PDA

View Full Version : LCDOUT command followed by variable data



flotulopex
- 11th March 2026, 09:55
Hi,

This must be recurrent subject but/and I can't recall how to handle this.

My project is about displaying time and adapting the output format to the number of digits to display adjusting mainly the number of spaces.

Since each LCDOUT command is 47 WORDs heavy, I'd like to avoid having to repeat this command all over my program.

This is a piece of my current code where one can see that I need to repeat the LCDOUT command often to fit the placement of characters.


' Display time in "0:00:00" format
IF Hours > 0 THEN ' " 0:00:00"
LCDOUT $FE,$2," ",DEC Hours,":",DEC2 Minutes,":",DEC2 Seconds
RETURN
ENDIF

IF Minutes > 9 THEN ' " 00:00"
IF LapDisplay THEN 'Lap is displayed
IF Lap > 9 THEN 'Lap is 2 characters wide
LCDOUT $FE,2,DEC2 Lap," ",DEC Minutes,":",DEC2 Seconds
ELSE 'Lap is 1 character wide
LCDOUT $FE,2,DEC1 Lap," ",DEC Minutes,":",DEC2 Seconds
ENDIF
ELSE 'no Lap display
LCDOUT $FE,2," ",DEC Minutes,":",DEC2 Seconds
ENDIF
RETURN
ENDIF

IF Minutes >= 0 THEN ' " 0:00"
IF LapDisplay THEN
IF Lap > 9 THEN
LCDOUT $FE,2,DEC2 Lap," ",DEC Minutes,":",DEC2 Seconds
ELSE
LCDOUT $FE,2,DEC1 Lap," ",DEC Minutes,":",DEC2 Seconds
ENDIF
ELSE
LCDOUT $FE,2," ",DEC Minutes,":",DEC2 Seconds
ENDIF
RETURN
ENDIF


How can I set a number of SPACEs by the mean of a variable?

Is there another way to achieve this?

richard
- 12th March 2026, 06:36
I assume you are trying to achieve something like this where the minutes/seconds remain at a fixed location regardless of the other formatted field widths in either lap mode or not
10044

its quite simple if you use a frame buffer for the lcd line and designate a frame address for each element to show, the fixed elements [that never change] can be set once off at code startup. you then just need to update each changeable element according to the rules/mode that currently apply when necessary. the display is updated from the buffer when necessary. its not only much faster it uses considerably less code space




LCDBUFF VAR BYTE[12]
lsecD0 var byte ext
lminD0 var byte ext
lhrsD0 var byte ext
lapdD0 var byte ext
lsecD1 var byte ext
lminD1 var byte ext
lhrsD1 var byte ext
lapdD1 var byte ext
LapDisplay VAR BYTE
Lap VAR BYTE
clear


asm
lsecD1 = _LCDBUFF + 8
lsecD0 = _LCDBUFF + 9
lminD1 = _LCDBUFF + 5
lminD0 = _LCDBUFF + 6
lhrsD0 = _LCDBUFF + 3
lhrsD1 = _LCDBUFF + 4
lapdD1 = _LCDBUFF
lapdD0 = _LCDBUFF + 1
endasm
arraywrite LCDBUFF,["LL h:mm:ss",0]
GOSUB ResetTime
GOSUB StartTimer
GOSUB update
pause 2000
hserout [ "Ready",13,10]
Minutes = 8
LapDisplay = 0
Seconds = 55
hours = 9




main:
IF MinutesChanged THEN
LapDisplay = !LapDisplay
MinutesChanged =0
ENDIF
IF SecondsChanged THEN
lap=lap+1
led=!led
GOSUB update
LCDout $FE,2, str LCDBUFF ;
SecondsChanged = 0
ENDIF
goto main


update:
lsecD1 = seconds dig 1 + "0" ;leading zero
lsecD0 = seconds dig 0 + "0"
lminD1 = Minutes dig 1 + "0" ;leading zero
lminD0 = Minutes dig 0 + "0"
IF LapDisplay THEN
if (lap dig 1 ) then ;two digits left justify
lapdD1 = lap dig 1 + "0"
lapdD0 = lap dig 0 + "0"
else ;one digits left justify
lapdD1 = lap dig 0 + "0"
lapdD0 = " "
endif
lhrsD1 = " "
lhrsD0 = " "
IF lminD1 == "0" THEN lminD1 = " " ;NO leading zero
ELSE
lhrsD1 = ":"
lhrsD0 = Hours dig 0 + "0"
lapdD1 = " "
lapdD0 = " "
ENDIF
return

flotulopex
- 13th March 2026, 15:29
Thanks Richard.

I think I get the idea.

Is it mandatory to use ASM?

I'd prefer not use it since I have no knowledge with this :o

richard
- 13th March 2026, 23:08
Is it mandatory to use ASM?

no , you can create your alias names for the array address' in the buffer in any way that you prefer or just use array notation and have no alias' at all