Shop OBEX P1 Docs P2 Docs Learn Events
Writing Variables to Serial LCDs — Parallax Forums

Writing Variables to Serial LCDs

VelocitVelocit Posts: 119
edited 2007-02-21 07:52 in General Discussion
This will hopefully be a pretty easy question for most of you to answer...

I have the SX Tech Board with SX28AC/DP chip and a Parallax 2x16 Serial LCD. I can display text just fine, but I cannot for the life of me figure out how to print a numeric value from a variable to the LCD. Does anyone have a code snippet or explanation as to how to do this? I appreciate your help very much.

I studied the RFID Reader and Serial LCD sample projects in the Help section, but I still can't quite figure it out. I've also looked at the sample programs for both SX/B and BS2 for the serial LCD, but displaying numeric variables doesn't seem to be as straightforward in SX/B as it is in PBASIC. Thanks!

Comments

  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2007-02-20 23:23
    Velocit
  • VelocitVelocit Posts: 119
    edited 2007-02-21 01:39
    Thanks so much for the link. I didn't realize converting a binary to BCD would be so complicated. I think I understand the code, I'm just not sure how to implement it properly... I just want to transmit the number using the SEROUT command.
  • JonnyMacJonnyMac Posts: 8,943
    edited 2007-02-21 02:13
    I think this function will work to replicate the DIG operator that is often used in PBASIC programs.

    ' Use: result = DIG value, position
    ' -- "value" is byte or word
    ' -- "position" is byte, 0 to 4
    
    DIG:
      IF __PARAMCNT = 2 THEN
        tmpW1 = __PARAM1
        tmpB1 = __PARAM2
      ELSE
        tmpW1 = __WPARAM12
        tmpB1 = __PARAM3
      ENDIF
    
      tmpB2 = 0
      IF tmpB1 < 5 THEN
        LOOKUP tmpB1, 1, 10, 100, 1000, 10000, tmpW2
        tmpW1 = tmpW1 / tmpW2        
        tmpW1 = tmpW1 // 10
        tmpB2 = tmpW1_LSB
      ENDIF
    
      RETURN tmpB2
    
    



    Declare it with:

    DIG        FUNC    1, 2, 3
    
    
  • william chanwilliam chan Posts: 1,326
    edited 2007-02-21 02:19
    Maybe you could try our iLCD product, another shameless serial LCD copycat based on the SX.
    It accepts a byte sized numeric variable and directly displays it as a HEX or a DECIMAL STRING.
    This saves code space on your main processor.

    For example, to display a variable temp, just output using SEROUT ESC, "N", temp
    and the value of temp will magically appear on the screen.

    See www.fd.com.my/products/ilcd/ilcd.php

    Good Luck.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my
  • VelocitVelocit Posts: 119
    edited 2007-02-21 04:26
    Jonny,

    I really appreciate the code snippet, but I still can't seem to get it to work. I copied the code verbatim and defined the variables and function as necessary. The output is still incomprehensible on the LCD screen. Is the position value just another working variable? Here's how I'm using the code as of now...

      f = 3 
      i = DIG f, d
      LCD_OUT i
    



    Where...
    f        VAR    Byte
    i        VAR    Byte
    d        VAR    Byte
    
  • JonnyMacJonnyMac Posts: 8,943
    edited 2007-02-21 05:26
    Sorry, you have to convert the digit value (0..9) to ASCII for the LCD; it's easy, just add 48 ("0") to the digit value and that should do the trick. I was just showing a function that duplicated a PBASIC operator; I should have provided a bit more detail for your application. Do this:

      myDigit = DIG theValue, digPos
      myDigit = myDigit + "0"
      LCD_OUT myDigit
    
    



    The second line converts the digit from a number to the correct ASCII code.
  • VelocitVelocit Posts: 119
    edited 2007-02-21 07:52
    Excellent! Thank you so much, I really appreciate your help.
Sign In or Register to comment.