Right Aligning characters on LCD

MearCat

Member
I have 2 numbers (temperatures) that I wish to display on a 16x2 LCD. Each of the temps can be 1-3 characters long (eg. 8degC up to 200degC) and I want to display each of the temps so that they are right aligned on the display. The last digit of the number will always be on the 6th character on each line, so the start of the number can either be 4th, 5th or 6th character on the line.

The temperature value are being stored in a byte. Is there a way to easily right align the number when is displayed on the LCD, or do I need to something fiddly like :
If the number is below 10 then goto 4th char before writing number...
If the number is between 10 and 99 then goto 5th char before writing number...
If the number is above 99, then goto 6th character before writing number...

Any ideas would be great.
 

hippy

Ex-Staff (retired)
You can't just go to the first character position where your first digit will be displayed because that leaves the previous ones unalterd. Example; if 100 was displayed, and you come to display 99, you'll end up showing 199.

You could replace the area on the LCD with spaces first then do as you siggest, but otherwise ( and more efficiently ) you'll need to re-write the entire number every time and convert leading zeros to spaces.

The code for doing that depends on whether you are using serial (AXE033) or parallel connected LCD. For the AXE033, this should work (untested ) ..

- b0 = 23 ' Value to display
-
- IF b0 >= 100 THEN ShowNumber
- SEROUT 7,N2400,(" ")
- IF b0 >= 10 THEN ShowNumber
- SEROUT 7,N2400,(" ")
- ShowNumber:
- SEROUT 7,N2400,(#b0)
 
Top