PDA

View Full Version : LCDOUT command followed by variable data



flotulopex
- 11th March 2026, 08: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, 05: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, 14: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, 22: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

flotulopex
- 15th March 2026, 15:03
Thanks a lot Richard!

It works like a charm and I can spare a lot of memory space not having to desperately repeat code consuming commands.

I should have first, but I totally forgot to give a look to the PBP manual:

10046


May I ask what the semicolon at the end of the LCDOUT command does? I tried with and without and can't see the difference.


LCDBUFF VAR BYTE[8]

LCDBUFF[0] = "0"
LCDBUFF[1] = "1"
LCDBUFF[2] = "2"
LCDBUFF[3] = "3"
LCDBUFF[4] = "4"
LCDBUFF[5] = "5"
LCDBUFF[6] = "6"
LCDBUFF[7] = "7"

MAIN:

LCDOUT $FE,2, STR LCDBUFF ;

GOTO MAIN
END

richard
- 15th March 2026, 22:52
May I ask what the semicolon at the end of the LCDOUT command does?


comments begin with an apostrophe or a semicolon, so its a blank comment

flotulopex
- 18th March 2026, 07:51
Sorry for my dumb question!

I'm mixing things up between PBP and another programming language where the semicolon supresses the CR/LF (Liberty Basic).

Sorry... :o

richard
- 18th March 2026, 08:29
I would be too worried about it, afaics it's totally undocumented for pbp and if you don't do much asm work you may rarely come across its usage

CuriousOne
- 20th March 2026, 20:26
I'm using this for such cases:



topline: 'top line updater sub
ofs=pos*16 'modify position offset
for x=0 to 15
i2cread sda, scl, adr, x+ofs, [y] 'write from eeprom
tline[x]=y 'write into array
next
lcdout $FE, $02 ' top row
for y=0 to 15
lcdout tline[y]
next
return


This is for top row and have similar for botton row.