Parallax LCD AppMod product #29121 and PBASIC - Display decimal value from a va
John Kauffman
Posts: 653
Parallax LCD AppMod product #29121 and PBASIC - Display decimal value from a variable
·
In the demo code for the LCd AppMod I see ways to:
From EEPROM (DATA) - Display a constant (LCD command)
From EEPROM (DATA) - Display a string
From a Variable - Display the ASCII character representing the number in the var
·
But I do not see a way to:
From a Variable – display a decimal value.
·
For example, I have put the value of 65 into a variable. I want "65" displayed on the screen. But the following code shows "A" since that is ASCII 65
·
' *** needs fix *** Sample Code - Write one number from variable
· VarTest = 65·········· ·············· ' put decimal value into variable
· char = VarTest········ ············· ' value to be output
· GOSUB LCD_Write_Char·· ' display decimal value
· PAUSE 500
·
How can I display a decimal value from a variable?
Thanks.
·
In the demo code for the LCd AppMod I see ways to:
From EEPROM (DATA) - Display a constant (LCD command)
From EEPROM (DATA) - Display a string
From a Variable - Display the ASCII character representing the number in the var
·
But I do not see a way to:
From a Variable – display a decimal value.
·
For example, I have put the value of 65 into a variable. I want "65" displayed on the screen. But the following code shows "A" since that is ASCII 65
·
' *** needs fix *** Sample Code - Write one number from variable
· VarTest = 65·········· ·············· ' put decimal value into variable
· char = VarTest········ ············· ' value to be output
· GOSUB LCD_Write_Char·· ' display decimal value
· PAUSE 500
·
How can I display a decimal value from a variable?
Thanks.
Comments
and firstly a presumption that you have a serial LCD module.
Believe that if you use the Serout command then add the character # in front of the variable
# makes serout treat value as ascii. If b0 = 127 then #b0 ==> "1","2","7"
so try program lines like like:
b0 = 127
SEROUT pin, baudrate, #b0
i.e
Char= 6 + $30
GOSUB LCD_Write_Char
Char= 5 + $30
GOSUB LCD_Write_Char
HTH
/Peter
Post Edited (PeterH) : 3/24/2008 10:50:25 AM GMT
I don't think that wil work if I don't know what the variable's value will be at run time.
For example, the value might be a byte that came from a RC circuit temp sensor.
Perhaps I could parse out the units, tens and hundreds, but I think there should be a more efficient way.
/Peter
REM put your VAR in displayVar
WRITE_To_Lcd:
GOSUB LCD_Command
'char = DisplayVar/10000 +$30
Dividevar = 10000
FOR idx =1 TO 4
char = DisplayVar/dividevar//10 +$30
GOSUB LCD_Write_Char
Dividevar = Dividevar /10
NEXT
char = DisplayVar//10 + $30
GOSUB LCD_Write_Char
RETURN
you do not say which BS model you have.
Do you have a BS2-p , pe or px?
If so, ·then the LCDCMD, LCDIN and LCDOUT commands work with a parallel LCD module using the upper nybble and may help you.
b0 = 65
LCDOUT 0,0, [noparse][[/noparse]DEC b0] ··‘ will send “6” then “5”.
See the BASIC Stamp manual at page 265.· See table 5.50 about fixed format say if you want 4 digits (ie with leading zeros)
Otherwise you are restricted to the methods put forward by Mike Green and others.