Shop OBEX P1 Docs P2 Docs Learn Events
Parallax LCD AppMod product #29121 and PBASIC - Display decimal value from a va — Parallax Forums

Parallax LCD AppMod product #29121 and PBASIC - Display decimal value from a va

John KauffmanJohn Kauffman Posts: 653
edited 2008-03-25 00:28 in BASIC Stamp
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.

Comments

  • westaust55westaust55 Posts: 14
    edited 2008-03-24 10:27
    I am new to the BASIC stamps world,
    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
  • PeterHPeterH Posts: 21
    edited 2008-03-24 10:33
    I don't have the LCD app mod sub in front of me, but you must write one character at time + convert it to ASCII.
    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
  • John KauffmanJohn Kauffman Posts: 653
    edited 2008-03-24 11:01
    Thanks for the suggestion.
    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.
  • PeterHPeterH Posts: 21
    edited 2008-03-24 11:49
    Correct you will have to parse the value. I have written a sub for that - but my wife say the guests will arrive for lunch in 12 minutes - so I will find the sub later today

    /Peter
  • PeterHPeterH Posts: 21
    edited 2008-03-24 11:52
    found it ( 7 minutes to go wink.gif)

    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
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-24 13:55
    The Stamps also have the DIG operator which gives you the value of the specified decimal digit (look in the manual for details). You could do something like:
    for idx = 4 to 0
      char = (DisplayVar DIG idx) + "0"
      gosub LCD_Write_Char
    next
    
  • westaust55westaust55 Posts: 14
    edited 2008-03-25 00:28
    John,
    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.
Sign In or Register to comment.