Shop OBEX P1 Docs P2 Docs Learn Events
Show me the Numbers - Parallel LCD — Parallax Forums

Show me the Numbers - Parallel LCD

John BondJohn Bond Posts: 369
edited 2005-01-14 12:44 in BASIC Stamp
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

Comments

  • BeanBean Posts: 8,129
    edited 2005-01-13 12:21
    Check out the "DIGIT" function.
    Bean.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-13 13:38
    With a parallel LCD you really have to do things one character at a time -- just as you are. With DIG you could do this:

    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
  • John BondJohn Bond Posts: 369
    edited 2005-01-13 14:15
    Hi Jon

    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 WilliamsJon Williams Posts: 6,491
    edited 2005-01-13 14:48
    You may want to have a look at the program I've attached. It's for our LCD AppMod and shows how one can write code that works on the BS2 (without LCD instructions) and the BS2p.· Even if the conditional compilation stuff doesn't float your boat, I would suggest that using defined constants for LCD commands will make writing (and later reading) your program easier.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • John BondJohn Bond Posts: 369
    edited 2005-01-14 12:44
    Hi Jon

    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
Sign In or Register to comment.