Shop OBEX P1 Docs P2 Docs Learn Events
I need to write 65 to my LCD, but get A instead.... — Parallax Forums

I need to write 65 to my LCD, but get A instead....

robotrobot Posts: 13
edited 2007-11-14 22:13 in BASIC Stamp
Hey folks, Heres whats going on....
I built the reaction timer from the parallax homework kit. Instead of using my computer and the debug command to display the "Reaction time" I am using a parrallel LCD.

I have a variable that the reaction time is stored in. I call the variable "Timecounter". This is how I coded it..

WRITE 0, "Your reaction time is", timecounter


The lcd then displays "Your time is"···ASCII caracter········ for instance if timecounter equals 65 you get
"Your time is A"··········· How do I get 65?

Comments

  • JC68JC68 Posts: 19
    edited 2007-11-09 23:21
    try using the DEC command

    WRITE 0, "Your reaction time is", DEC timecounter

    JC68
    ·
  • robotrobot Posts: 13
    edited 2007-11-10 18:46
    Hey, thanks for the reply! I thought the same thing, and I tried that, However, I got a syntax error when trying to run the program. I would think that converting a variables numeric value to its equivalent text would be a common thing, but it seems to be stumping me... I'm still very new to all this programming stuff though.....
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-11-10 19:13
    WRITE puts the bytes (and words) following it into EEPROM. It does not support the DEC prefix, and I'm not sure what the purpose of it is in your program, as it relates to a parallel LCD. Later in your program you must have an LCDOUT statement. This would be the place to to use DEC, viz:

    LCDOUT pin, command, [noparse][[/noparse]"Your reaction time is ", DEC timecounter]
    
    
    



    -Phil
  • robotrobot Posts: 13
    edited 2007-11-11 03:19
    I have a regular basic stamp 2, It does not support the lcdout command, here is my code...


    Init:
    DIRL = %11111110 'p1-p7 outputs
    LOW e 'put
    LOW rw ' control lines
    LOW rs ' in initial state
    PAUSE 500 'wait til vcc stable
    GOSUB InitLCD 'initialize LCD

    beginning:
    cmd = ClearDisplay
    GOSUB sendcmd
    WRITE 0, "·· Press and hold····· light turn red,·· pushbutton to make " , %00000000
    GOSUB instructions
    WRITE 0, " When light turns··· fast as you can!··· green, let go as········ " , %00000000
    PAUSE 1250
    cmd = ClearDisplay
    GOSUB sendcmd
    GOSUB instructions
    GOSUB Game
    Game:
    DO
    ···· IF (IN9 = 1)· THEN
    ···· LOW 14
    ···· HIGH 15
    ···· RANDOM value
    ···· PAUSE 1000 + value
    ···· HIGH 14
    ···· LOW 15
    ···· timecounter = 0
    ···· DO
    ···· PAUSE 1
    ···· timecounter = timecounter + 1
    ···· LOOP UNTIL IN9 = 0
    ···· LOW 14
    ···· timecounter = timecounter * 2
    ···· IF (timecounter = 2) THEN
    ···· WRITE 0, "You must wait until light turns green" , %00000000
    ···· cmd = ClearDisplay
    ···· GOSUB sendcmd
    ···· GOSUB instructions
    ···· PAUSE 2000
    ···· GOTO beginning
    ···· ELSE
    ···· WRITE 0, "Your time was ",· timecounter·· , %00000000
    ···· cmd = ClearDisplay
    ···· GOSUB sendcmd
    ···· GOSUB instructions
    ···· PAUSE 2000
    ···· GOTO beginning

    ··· ENDIF
    ··· ENDIF
    LOOP
    instructions:
    index = 0
    Display:
    READ index,ch 'read data from eeprom
    IF ch = %00000000 THEN RETURN
    GOSUB sendchr 'send to lcd
    index = index + 1 'increment eeprom addr
    GOTO Display



    '
    ' Initialize LCD according to specifications for the HD44780
    '
    InitLCD:
    FOR x=1 TO 3 'spec said to do three times
    OUTB = WakeUp>>4 'send wakeup call
    PULSOUT e,pulstime 'send command
    PAUSE 5
    NEXT
    OUTB = FourBitMode>>4 'go to 4 but mode
    PULSOUT e,pulstime 'send it
    PAUSE 1
    '
    ' Initialization command sequence...
    '
    cmd = FourBitMode
    GOSUB sendcmd
    cmd = TwoLine5x8Font
    GOSUB sendcmd
    cmd = DisplayOff
    GOSUB sendcmd
    cmd = DisplayOnBLCrsr
    GOSUB sendcmd
    cmd = IncCrsr
    GOSUB sendcmd
    cmd = ClearDisplay
    GOSUB sendcmd
    cmd = HomeDisplay
    GOSUB sendcmd
    RETURN
    '
    ' send character to ddram on lcd
    '
    sendchr:
    GOSUB busychk 'wait til lcd not busy
    OUTB = ch.HIGHNIB 'upper part first
    HIGH rs 'rs high
    PULSOUT e,pulstime 'send it
    LOW rs 'reset rs
    GOSUB busychk 'wait again
    OUTB = ch.LOWNIB 'lower nibble
    HIGH rs 'rs high
    PULSOUT e,pulstime 'send it
    LOW rs 'reset rs
    RETURN

    '
    ' Send command in the var "cmd" to the lcd
    '
    sendcmd:
    GOSUB busychk 'wait til lcd not busy
    OUTB = cmd.HIGHNIB 'upper cmd first
    PULSOUT e,pulstime 'send it
    GOSUB busychk 'wait again
    OUTB = cmd.LOWNIB 'lower nibble
    PULSOUT e,pulstime 'send it
    RETURN
    '
    ' waits til the lcd is no longer busy and then returns
    ' uses the var "temp"
    '
    busychk:
    DIRL = %00001110 'make lcd databus input
    HIGH rw 'were reading
    busyloop:
    HIGH e 'enable
    temp = INB 'get data from lcd
    LOW e 'toggle back enable
    PULSOUT e,pulstime 'because were in 4bit mode (two reads of 4 bits)
    TEMP = temp & $80 'mask all but busy flag (db7 from lcd)
    IF temp <> 0 THEN busyloop 'loop until not busy
    LOW rw 'back to write
    DIRL = %11111110 'reset databus back to output
    RETURN
  • robotrobot Posts: 13
    edited 2007-11-11 03:27
    If I am using my computer monitor, and the debug comand, then DEC works fine for converting a numeric value into its equivalent text form. However I'm not using my monitor or the debug command. I'm not sure if I should...

    (1) Convert the numeric value to text, and then write to eeprom or....
    (2) Read numeric value from eeprom then convert to equivalent text before sending to LCD....

    I'm not even sure if I'm using the correct terminology, or if what I'm saying makes sense to you guys......

    Any help is certianly appreciated!
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-11-11 06:32
    In that case, there's no way to make use of the built-in DECimal conversion. I would recommend a subroutine called SendDec which computes ch for each digit and calls your SendChr routine.

    One thing I would also recommend in your program is not to use the WRITE command at all. You can put all of your text info in DATA statements, each beginning at a known location. Then, instead of setting index to zero at the beginning of Instructions, set it in the calling program to the beginning address of the string you want to display. By using DATA statements, the only time the EEPROM is written is when you upload your program. This will save wear and tear on the EEPROM from having to WRITE to it so many times.

    -Phil
  • robotrobot Posts: 13
    edited 2007-11-13 05:33
    Thankyou for your help.... I did as you suggested and replaced the write commands with data commands. I had to fiddle with it to get it to work. I thought a ASCII character took up two bytes, and that a single address was one byte. By this logic the address I used should overlap....But anyway, thats a problem for another day.....

    For now, I'm still trying to figure out:

    (1) how to create a subroutine that will take the numeric value of a variable( x = 11) and save it as "text" that my send characted subroutine can use. ·

    I understand how I could use the lookup command to do this for a few numbers, but how would one approach a routine that would convert any number?



    Anyway thanks again, and here is my modified program.........



    DATA @0, "·· Press and hold····· light turn red,·· pushbutton to make " , %00000000
    DATA @75, " When light turns··· fast as you can!··· green, let go as········ " , %00000000
    DATA @150, "You must wait until light turns green" , %00000000
    DATA @200, "Your time was ", %00000000
    Init:
    DIRL = %11111110 'p1-p7 outputs
    LOW e 'put
    LOW rw ' control lines
    LOW rs ' in initial state
    PAUSE 500 'wait til vcc stable
    GOSUB InitLCD 'initialize LCD


    beginning:
    cmd = ClearDisplay
    GOSUB sendcmd
    index = 0
    GOSUB instructions
    PAUSE 1250
    cmd = ClearDisplay
    GOSUB sendcmd
    index = 75
    GOSUB instructions
    GOSUB Game

    Game:

    DO
    ···· IF (IN9 = 1)· THEN
    ···· LOW 14
    ···· HIGH 15
    ···· RANDOM value
    ···· PAUSE 1000 + value

    ···· HIGH 14
    ···· LOW 15

    ···· timecounter = 0

    ···· DO
    ···· PAUSE 1
    ···· timecounter = timecounter + 1
    ···· LOOP UNTIL IN9 = 0
    ···· LOW 14
    ···· timecounter = timecounter * 2
    ···· IF (timecounter = 2) THEN
    ···· cmd = ClearDisplay
    ···· GOSUB sendcmd
    ···· index = 150
    ···· GOSUB instructions
    ···· PAUSE 2000
    ···· GOTO beginning
    ···· ELSE
    ···· cmd = ClearDisplay
    ···· GOSUB sendcmd
    ···· index = 200
    ···· GOSUB instructions
    ···· PAUSE 2000
    ···· GOTO beginning
    ··· 'DEBUG " Your time was ", DEC timecounter,
    ··· '" ms.", CR, CR,
    ··· '"To play again, hold the ", CR,
    ··· '"button down again.", CR, CR

    ··· ENDIF
    ··· ENDIF
    LOOP

    instructions:
    Display:
    READ index,ch 'read data from eeprom
    IF ch = %00000000 THEN RETURN
    GOSUB sendchr 'send to lcd
    index = index + 1 'increment eeprom addr
    GOTO Display
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-11-13 16:52
    You don't need to write the decimal value to EEPROM before you send it. Just send the preamble string first, using instructions, then call a separate routine to send the decimal value on the fly. To aid in writing this routine, take a look at PBASIC's DIG (digit) operator.

    -Phil
  • robotrobot Posts: 13
    edited 2007-11-14 21:57
    Thankyou so much for the help Mr Pilgrim.... I finally finished my first project, and you were a tremendous help! The DIG·operator, combined with the·LOOKUP command made it possible to convert my numeric value into its equivalent text form! Thankyou again! Here is a picture of my project board I built running its first application!

    Signed: Daniel...........www.AllAboutTheWood.com.............This is my website of things I've made!
    972 x 1296 - 136K
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-11-14 22:13
    That's a nice-looking unit! I'm glad you got it working.

    -Phil
Sign In or Register to comment.