Writing Dec. Numers to Parallel LCD
MikeS
Posts: 131
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
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
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
Bingo! That fact was filed somewhere in my brain but just would not come out.
Thank you again.
Mike S.