Shop OBEX P1 Docs P2 Docs Learn Events
Writing Dec. Numers to Parallel LCD — Parallax Forums

Writing Dec. Numers to Parallel LCD

MikeSMikeS Posts: 131
edited 2005-01-29 15:58 in BASIC Stamp
I recently came by a 1x16 Parallel LCD and got it working with the help of a sample program from AL Williams -Microcontroller Projects with Basic Stamps (great book). In the program he has a subroutine that will write a byte in decimal to the LCD. I have not been able to fully understand what is happening in this subroutine. Specifically the line...char=inum DIG j +"0". The +"0" has got me buffaloed. I know that it must be obvious to the most casual observer but I don't see it. I have attached my complete program that I have modified from Al's. Any help would be appriciated.

Thanks,
Mike S.

' Write a word in decimal
wr_worddec:
· j=5
· GOTO wr_dec
' Write a byte in decimal
wr_bytedec:
· j=2
wr_dec:
· char=inum DIG j +"0"
' Supress zeros
· IF j<>0 AND char="0" AND nozero=1 THEN digz
· GOSUB wr_LCD
· nozero=0· ' turn off suppression so we don't turn 102 into 12
digz:
· IF j=0 THEN nowr
· j=j-1
· GOTO wr_dec
nowr:
· PAUSE 500
· RETURN

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-29 15:16
    The BASIC Stamp is very flexible in how items are represented in code, and ultimately everything is stored as a byte. For a character LCD you must send the ASCII code for a digit to display it. The ASCII code for zero is 48 -- which can be represented by "0" in a PBASIC listing. What the program is doing then, is taking the digit value and adding it to the ASCII code for zero so that it can be displayed.

    0 + 48 = 48 --> "0"
    1 + 48 = 49 --> "1"
    2 + 48 = 50 --> "2"
    ...

    I think you get the picture. Again, the key is that you must send the ASCII code for a digit to the display, not the digit value. In PBASIC the easiest way to convert a digit to its ASCII value is:

    asciiVal = digVal + "0"

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • MikeSMikeS Posts: 131
    edited 2005-01-29 15:58
    Jon,
    Bingo! That fact was filed somewhere in my brain but just would not come out.

    Thank you again.

    Mike S.
Sign In or Register to comment.