Shop OBEX P1 Docs P2 Docs Learn Events
Display a value on a LCD — Parallax Forums

Display a value on a LCD

PeterHPeterH Posts: 21
edited 2007-09-25 09:22 in BASIC Stamp
Hi there,

I am setting up a small device to count how many people enter a room. For this I have connected:

Stamp 1 Project board
LCD Terminal AppMod
One Ping Sensor conencted to Pin 7,

I have got most of it working, so that the sensor counts every other person entering og leaving the room ( assuming that anybody who enters will also exits.

I Total the amount in a Byte variable , Counter, and then display the figure on the LCD, and here is my problem.

How do I convert the value 1234 to Ascii $31 $32 $33 $34

I wrote the following rutine but it only works for values <100

·char = LcdLine2 + 2························ ' show on 2nd line
· GOSUB LCD_Command···················· ' sub to·display the character on the LCD
· char = counter/1000· +$30
· GOSUB LCD_Write_Char·················· 'sub to·display the character on the LCD
· char = counter/100· + $30
· GOSUB LCD_Write_Char
· char = counter/10· + $30··············· ' This is the problem!!
· GOSUB LCD_Write_Char
· char = counter//10· + $30
· GOSUB LCD_Write_Char

The problem arises· with a value >100· e.g. the value 123

First character will be $31 but the second will be $c +$30 and the third will be ok $33

So I have to write another expression, but it must be SHORT since this is BS1 and memory is almost full,

any ideas?
TIA

Peter

Comments

  • Andy FoxAndy Fox Posts: 46
    edited 2007-09-24 17:36
    You need to add a modulus to the 10's digit calc like this:

    char = (counter/10) // 10 + $30

    You'll need to do something similar with the 100's digit as it'll have the same problem when you go above 1000. Of course, you can't go above 255 currently if your counter variable is a BYTE. It'll need to be a WORD (value 0-65535).
  • PeterHPeterH Posts: 21
    edited 2007-09-25 09:22
    Great Thanks!

    That did the trick. And yes you are right - the Variable is word length.

    I'll be back with more questions shortly

    Thanks Again
Sign In or Register to comment.