Shop OBEX P1 Docs P2 Docs Learn Events
Displaying calculated numbers on Parallax parallel LCD — Parallax Forums

Displaying calculated numbers on Parallax parallel LCD

studebaker1925studebaker1925 Posts: 2
edited 2012-03-04 12:09 in BASIC Stamp
I am using the Parallax Experiment kit which comes with a parallel (not serial) LCD and the BS2. I am measuring resistance of a pot using the supplied 555 oscillator chip with the result stored as a Word variable (let's call it ResistanceValue). I view the result using DEBUG as a decimal (DEC) with 4 digits using DEBUG CRSRXY, 13, 2, DEC ResistanceValue, CLREOL. I would like to display this four digit value on the parallel LCD. I have no problem loading characters from a string (from the EEProm) such as "This is the resistance=" but have yet to work out how to add the number generated from the resistance.

:blank: Steve

Comments

  • Mike GMike G Posts: 2,702
    edited 2012-03-04 04:59
    Welcome studebaker1925...

    This is not the most elegant method for converting an integer to a character byte array (string) but it works and should give you some ideas.
    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}
    
    ' VARs
    number    VAR   Word
    char      VAR   Byte(4)
    
    'Init
    number = 1234
    
    
    Main:
      ' Get the individual numbers
      char(3) = number // 10
      number = number - char(3)
    
      char(2) = number // 100
      number = number - char(1)
      char(2) = char(2) / 10
    
      char(1) = number // 1000
      number = number - char(2)
      char(1) = char(1) / 100
    
      char(0) = number / 1000
    
      GOSUB PrintHex
    
      'Conver the numbers to ASCII
      char(0) = char(0) + $30
      char(1) = char(1) + $30
      char(2) = char(2) + $30
      char(3) = char(3) + $30
    
      GOSUB PrintHex
      GOSUB Print
    END
    
    PrintHex:
      DEBUG HEX ?char(0), HEX ?char(1), HEX ?char(2), HEX ?char(3)
      RETURN
    
    Print:
      DEBUG STR char \4
      RETURN
    
  • studebaker1925studebaker1925 Posts: 2
    edited 2012-03-04 06:26
    Thanks. I had thoughts on the same lines and came up with this (not the complete code):

    MsgNums DATA "0123456789" ' store number characters in array

    ...Extract_Digits_from_number:

    R1=Number//1000
    R2=R1//100
    R3=R2//10
    R4=R3
    R3=R2/10
    R2=R1/100
    R1=Number/1000


    ...then

    READ (MsgNums + R1), char ' read a character from MsgNums
    GOSUB LCD_Out ' write character at next cursor location
    READ (MsgNums + R2), char ' read a character from MsgNums
    GOSUB LCD_Out ' write character at next cursor location
    READ (MsgNums + R3), char ' read a character from MsgNums
    GOSUB LCD_Out ' write character at next cursor location
    READ (MsgNums + R4), char ' read a character from MsgNums
    GOSUB LCD_Out ' write character at next cursor location
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2012-03-04 12:09
    Also take a look at the Stamps DIG operator.
    X=12345

    X DIG 4 returns the 10^4 decimal digit (1 in this case)
    X DIG 0 returns the 10^0 decimal digit (5 in this case)

    add 48 to that and you have the numeric ascii code to send to the LCD
    X DIG 4 + 48

    You can loop through the digits and suppress leading zeros or turn them into spaces if you want.
Sign In or Register to comment.