String problem
Newzed
Posts: 2,503
I have a small problem.
I have a Super Carrier hardwired as a driver for a parallel LCD.· It receives serial data from a circuit on·my PDB which conveys date and time.· The PDB data is received into an array, which is loop read by the LCD program.
Everything works just fine.
Now I want to incorporate temperature.· I have an TLC2543 built up as an AppMod.· However, the PDB has no AppMod connector but the Super Carrier board does.· So...I can plug it into the Super Carrier and derive a temperature.· Now I have a variable - AD0 - that contains the temp.
Let's say the ADC reports 798.· Problem - how do I get 798 into a string that says "dec AD0/10, ".". dec1 AD0" so that the Put_LCD_String routine can read it one byte at a time and send each byte to LCD_Write_Char.
My array is defined as msg·· VAR· byte(20).
I tried msg\20 = ..AD0 stuff and
STR msg\20 = ...AD0 stuff but that didn't work.
I can write "Temp is: ", 0 to DATA and get that much OK, then I could append AD0 if I can get it into a string.
Any suggestions?
Sid
I have a Super Carrier hardwired as a driver for a parallel LCD.· It receives serial data from a circuit on·my PDB which conveys date and time.· The PDB data is received into an array, which is loop read by the LCD program.
Everything works just fine.
Now I want to incorporate temperature.· I have an TLC2543 built up as an AppMod.· However, the PDB has no AppMod connector but the Super Carrier board does.· So...I can plug it into the Super Carrier and derive a temperature.· Now I have a variable - AD0 - that contains the temp.
Let's say the ADC reports 798.· Problem - how do I get 798 into a string that says "dec AD0/10, ".". dec1 AD0" so that the Put_LCD_String routine can read it one byte at a time and send each byte to LCD_Write_Char.
My array is defined as msg·· VAR· byte(20).
I tried msg\20 = ..AD0 stuff and
STR msg\20 = ...AD0 stuff but that didn't work.
I can write "Temp is: ", 0 to DATA and get that much OK, then I could append AD0 if I can get it into a string.
Any suggestions?
Sid
Comments
Print_Temp:
· FOR idx = 0 TO 6
··· LOOKUP idx, [noparse][[/noparse]"Temp = "], char
··· GOSUB LCD_Write_Char
· NEXT
· ' print numeric temperature -- no leading zeros
· LOOKDOWN temp, <=[noparse][[/noparse]9, 99, 999, 9999, $FFFF], idx
· idx = idx MIN 1······························ ' print at least two digits
· FOR idx = idx TO 0··························· ' print value
··· char = temp DIG idx + 48
··· GOSUB LCD_Write_Char
··· IF (idx = 1) THEN·························· ' add DP before
····· char = "."
····· GOSUB LCD_Write_Char
··· ENDIF
· NEXT
· RETURN
LCD_Write_Char:
· DEBUG char
· RETURN
It's a little bit of code, but should work and handle problems like a zero value properly.· I actually ran this in a little test program (attached) and it works as designed.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Post Edited (Jon Williams (Parallax)) : 6/4/2005 4:28:28 PM GMT
If AD0 = 798, how do I get this into a string so Put_String can handle it.
How about:
msg(0) = AD0 dig 0···· 'digit 8
msg(1) = "."
msg(3) = AD0 dig 1···· ' digit 9
msg(4) = AD0 dig 2···· ' digit 7
Then a special PutString -
PutString:
for ix = 0 to 4
char = msg(ix)
GOSUB LCD_Write_Char
next
return
Would that work?
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
temp = 3
GOSUB Pront_Temp
They generated an extra·"Temp = " on the LCD.· I couldn't figure out what you had in mind do I just deleted them.· Would like to add another temp - AD1 but I have no variable space left.· Maybe after the LCD displays AD0, I could rerun the whole thing and just reuse AD0.· That should work - I've done that before.
Thanks a bunch, Jon.· I've just about got this parallel LCD project wrappeth uppeth.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Sid