Formatting for LCD

evans_us

Member
Hi
I have been testing code to run on an LCD (AXE033; 16 x2)

I have several "user values" that can increment (0-999) when a button is pressed and the program asks for each of the 4 values which are stored in variables (words). I would like to display all these values on the LCD screen and know what each one refers to. Currently, on the upper line I put all the "Titles" for the values that should appear beneath them on the second line. It is easy to centre these with appropriate blank spaces (" "). I would like to align the text for the values on the second line and centre each under its corresponding title. The problem is that if a value has less than 3 digits it is not set in the right position under its "Title" and can cause all the other values to be offset as well.
The question is: how do I code to add spaces to my text based on whether I have a 2digit number (need one space; " ") or 1 digit (2spaces; " ").
Thank goodness for the simulator!! I wouldn't have got this far without it.
Thanks for any help.
 

westaust55

Moderator
Hi
I have been testing code to run on an LCD (AXE033; 16 x2)

I have several "user values" that can increment (0-999)
:
:
I would like to align the text for the values on the second line and centre each under its corresponding title. The problem is that if a value has less than 3 digits it is not set in the right position under its "Title" and can cause all the other values to be offset as well.

The question is: how do I code to add spaces to my text based on whether I have a 2digit number (need one space; " ") or 1 digit (2spaces; " ").

Thank goodness for the simulator!! I wouldn't have got this far without it.
Thanks for any help.
Evan,
Note that while you have been a member for around a year, but very few posts so welcome to the PICAXE forum to start with.

If you have already tried something, can I suggest that you upload your code so far, so we can better see where you may be going wrong and give guidance that is best suited to the problem rather than just dump a piece of code upon you.

In the meantime if you think in terms of flow charting and pseudo-code you need to think out the flow something like this:

Max number of digits = 3
IF number = 3 digits THEN no spaces needed but . . . .
IF number is < 3 digits THEN need to print a space
IF number is < 2 digits THEN need to print another space
NOW print the number between 0 and 999
 

BeanieBots

Moderator
There are several methods you can use but they all follow the pricipal outlined by westaust.
More often than not, when sending data to the AXE033, it uses a line such as:-
serout pin,baud,(254,position.....
You can use the method to alter the value of 'position'.

For an example, have a look at my charger/discharger program.
http://www.picaxeforum.co.uk/showthread.php?t=10986

The mAhr figure is 1 to 5 digits and sent to the AXE033 right justified.

Originally it was an independant subroutine but I had to move it to be part of the "Control_Loop" routine to save space.

The "Display Volts" routine shows how to split a four digit number into seperate numbers and blank the leading zero.
 

evans_us

Member
Thanks for the help

Thanks for the rapid input guys. 99% of all my previous questions have always been answered in previous posts but my searches for this answer must have used the wrong terms!
Thanks BeanieBots for the code - the answer is in the use of the 'PTR' approach for selecting where to start the cursor in the display.

The only problem with this though is I now need a lot more lines of code and I am already at 3/4 capacity on the 28X1.:eek:
Oh well!! I am sure that there is plenty of room for optimisation!
Thanks
 

boriz

Senior Member
I have never used a serial LCD, but here&#8217;s a couple of ideas off the top of my head:

BINTOASCII does much of the work for you. Put this into the simulator:
Code:
w3=99
bintoascii w3,b0,b1,b2,b3,b4
do:loop
B0 to B2 will contain 48 (ASCII for zero).

Or&#8230;

Try this in the simulator:
Code:
w1=99
w2=w1
for b0=1 to 5
	w2=w2/10
	if w2=0 then exit
next b0
do:loop
On exit, b0 contains the number of decimal digits in w1. This can be used as an offset for your position command. IE:
Code:
position=position-b0
print digits
Or it can be used to pad with an appropriate number of spaces. IE:
Code:
b0=4-b0
for b1=1 to b0
    print space
next b1
print digits
 
Last edited:

InvaderZim

Senior Member
Instead of calculating the number of spaces to use, a more brain-dead way to handle it is to reserve the number of digits you need (eg, 4 for a number from 0-9999). When you refresh the value, do something like:
Code:
'blank a 4-space area of the display, then send the updated value
serout 7,T4800, (254,128,"    ",254,128,#w0)
It ends up being left-justified, and it isn't elegant. But it doesn't take much space or thought to implement.
 
Top