Show me the Numbers - Parallel LCD
John Bond
Posts: 369
Hi Guys
·
I’m displaying the date on a parallel LCD from a BS2 (Yes, I know the 2p has the LCD commands but this is a quick project using an existing BS2). The Day, Month and 2 digits of the year are stored as EEPPOM bytes. I do calculations on these numbers so they can’t be stored as characters. The code I use to display these numbers on the LCD is particularly ugly. The code looks something like this:-
·
Day_Chars:
LCDIns ·= ·128+64+7··········· ‘To locate the position at the 8th position on the 2nd line of the LCD
Gosub SendInst
·
Char = (day/10) + 48·· ··········· ‘To get the ASCII of the 10s digit, "0" is the 48'th ASCII character
Gosub SendLCDChar
Char = (day//10) + 48· ··········· ‘To get the ones digit
Gosub SendChar
·
Month_Chars:
LCDIns ·= ·128+64+11······
Gosub SendInst
·
Char = (month/10) + 48
Gosub SendChar········
Char = (month//10) + 48·······
Gosub SendChar
·
Year_Chars:
……
·
Is there a better way? I've done a search on past queries without success which make me think I'm missing something basic.
·
Kind Regards for Kwa Dukuza
·
John Bond
·
I’m displaying the date on a parallel LCD from a BS2 (Yes, I know the 2p has the LCD commands but this is a quick project using an existing BS2). The Day, Month and 2 digits of the year are stored as EEPPOM bytes. I do calculations on these numbers so they can’t be stored as characters. The code I use to display these numbers on the LCD is particularly ugly. The code looks something like this:-
·
Day_Chars:
LCDIns ·= ·128+64+7··········· ‘To locate the position at the 8th position on the 2nd line of the LCD
Gosub SendInst
·
Char = (day/10) + 48·· ··········· ‘To get the ASCII of the 10s digit, "0" is the 48'th ASCII character
Gosub SendLCDChar
Char = (day//10) + 48· ··········· ‘To get the ones digit
Gosub SendChar
·
Month_Chars:
LCDIns ·= ·128+64+11······
Gosub SendInst
·
Char = (month/10) + 48
Gosub SendChar········
Char = (month//10) + 48·······
Gosub SendChar
·
Year_Chars:
……
·
Is there a better way? I've done a search on past queries without success which make me think I'm missing something basic.
·
Kind Regards for Kwa Dukuza
·
John Bond
Comments
Bean.
FOR idx = 1 TO 0
char = (month DIG idx) + "0"
GOSUB SendChar
NEXT
This really doesn't save you much typing -- but will help if you need to "print" longer numbers.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
OK! ... Thats a lot neater, and it'll also make more sense when I come back to the code in 6 months time.
As they say round here - "You're a mamba!"
(Mambas are the best of snakes so it implies that you are pretty terrific)
Kind regards from Kwa Dukuza
John bond
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
Thanks for this additional code. Something to play with this weekend.
That little bit of code you sent me that uses the DIG command works a treat. I was able to put it in a loop which is much clearer and saves 54 bytes and 2 byte variables.
Kind regards for Kwa Dukuza
John Bond