PDA

View Full Version : String problem



Newzed
06-04-2005, 07:49 PM
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

Jon Williams
06-04-2005, 09:14 PM
EDIT: After rethinking, you can put the whole thing into this routine:


Print_Temp:
· FOR idx = 0 TO 6
··· LOOKUP idx, ["Temp = "], char
··· GOSUB LCD_Write_Char
· NEXT
· ' print numeric temperature -- no leading zeros
· LOOKDOWN temp, <=[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

Newzed
06-04-2005, 09:28 PM
Jon, handling the value is my problem.

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
06-04-2005, 09:35 PM
See my edited post above -- and the demo code that is attached.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

Newzed
06-05-2005, 01:11 AM
Jon, I put my ADC program in slot 1, then tacked on your neat little routine.· I set flags to jump to slot 1 immediately after the LCD displays time and date, and it works fantastic.· I was running out of space so I aliased temp as AD0 and idx as com.· I'll probably go back and just change the variable names - that would be simpler.· I deleted the two lines that said:

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
06-05-2005, 02:11 AM
The demo program was setup just to show that it would correctly "print" values from 0.0 to 6553.5 correctly. I'm glad it worked for you.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

Newzed
06-05-2005, 03:16 AM
I connected my TLC2543 AppMod into the Super Carrier board and now I'm reading actual room temperature.· I'm going to have to adjust the ADC output with a· */· so it will read the accurate temp.· Thanks again, Jon.

Sid