I need to write 65 to my LCD, but get A instead....
robot
Posts: 13
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?
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
WRITE 0, "Your reaction time is", DEC timecounter
JC68
·
-Phil
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
(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!
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
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
Signed: Daniel...........www.AllAboutTheWood.com.............This is my website of things I've made!
-Phil