PDA

View Full Version : Joining variables and displaying on an LCD



Navaidstech
- 28th April 2009, 12:22
I'm having trouble trying to convert numbers into strings, joining them together and displaying on an LCD display.

Essentially what's going on is that I receive a data stream via RF and from that stream I'm trying to extract bits and pieces of information and then formatting them to display on an LCD.
Long story short, I'm extracting three numbers representing the tens, units, and decimals - for example numbers 2, 5 and 7 and assigning them to variables (such as TempTens, TempUnits and TempDecimals)
I'm trying to display this info on an LCD display to be shown as "25.7"

Sure, I could issue a command
LCDOUT $fe, $c0, #TempTens, #TempUnits,".",#TempDecimals
but I'm wondering if there is a way of merging the three variables into a string and then displaying the whole thing so that my LCDOUT command doesn't get cluttered.

Any help would be appreciated.

ScaleRobotics
- 28th April 2009, 14:31
I could issue a command
LCDOUT $fe, $c0, #TempTens, #TempUnits,".",#TempDecimals
but I'm wondering if there is a way of merging the three variables into a string and then displaying the whole thing so that my LCDOUT command doesn't get cluttered.


You could make it a string variable, but it would add an extra step, and would add clutter to another line. So it would really be more clutter. I realize neatness counts, but in this case your current code is very readable. And hey, you're the only person that's going to be bothered by it. No one else will know its there.

Navaidstech
- 28th April 2009, 16:40
I see your point, and it DOES make sense. :)

My only problem is that this variable will be distributed in numerous locations on the LCD screen. Had it only been one location, I wouldn't be too concerned about clutter and such.
So essentially, as you have mentioned, I need to create a string variable. I tried a few things last night (it was getting late and I tried doing it while wearing a Visual Basic hat) but couldn't get it to work.

ScaleRobotics
- 28th April 2009, 18:19
Ok, that makes sense. Here is the easy way. It is still not making it a string though. Let me ponder the string route.......



LCDOUT (lcd command to move cursor to desired position goes here)
gosub printtemp


printtemp:
LCDOUT $fe, $c0, #TempTens, #TempUnits,".",#TempDecimals
return

ScaleRobotics
- 28th April 2009, 20:46
Sorry, the above code should be:



LCDOUT $fe, ($c0 + 4) 'moves cursor to 4th character position on bottom line
gosub printtemp


printtemp:
LCDOUT #TempTens, #TempUnits,".",#TempDecimals 'remove line/cursor info
return

Navaidstech
- 28th April 2009, 22:59
You know... you might have something going here. I'll explore this option as well.

Now that I think of it, the original way might work as well. I'm just worried about the size of the program (trying to fit everything on a F628) but now that I think about it, just because a variable looks long and messy on the Microcode screen, doesn't mean it will take that much space on a chip, right?

:)

ScaleRobotics
- 29th April 2009, 00:31
That's right, looks can be deceiving.

I did a couple tests with Darrel's "How much code could a code hog ...." thread at
http://www.picbasic.co.uk/forum/showthread.php?t=2418
This was done with a 18F chip:

it turns out that both lines use the same amount of space:


Lcdout $fe, ($c0 +4),"98.7"

LCDOUT $fe, ($c0 +4), #TempTens, #TempUnits,".",#TempDecimals


And, if you use the gosub (in post #5) 3 times, rather than use the above line (three times), you will use about 2/3 the code space. And that's not considering forming the data into a string.

Navaidstech
- 29th April 2009, 04:12
Good stuff. Thank you for running the tests for me.
Looks like I'll have to go with the original plan as you have suggested.
No worries... I simply thought there would be a different way of doing it but I'll just have to get creative here and make efficient use of code space.

Thank you very much for all your help.