Any elegant way of text string handling?
Hello.
I'm making a LCD clock which uses 1602 LCD. I want to display day of the week according to RTC reading.
However, since there are no string variables, I have to make an array, in which I put ASCII codes of letters to be written, and read them accordingly:
Code:
DNAME[1]=77:DNAME[2]=111: DNAME[3]=110 'Mon
DNAME[4]=84:DNAME[5]=117: DNAME[6]=101 'Tue
DNAME[7]=87:DNAME[8]=101: DNAME[9]=100 'Wed
DNAME[10]=84:DNAME[11]=104: DNAME[12]=117 'Thu
DNAME[13]=70:DNAME[14]=114: DNAME[15]=105 'Fri
DNAME[16]=83:DNAME[17]=97: DNAME[18]=116 'Sat
DNAME[19]=83:DNAME[20]=117: DNAME[21]=110 'Sun
TAVAKI:
FOR CNT=1 to 21 STEP 3
lcdout $fe, $01, DNAME[CNT], DNAME[CNT+1],DNAME[CNT+2]
PAUSE 1000
NEXT CNT
GOTO TAVAKI
Here it works, because I've trimmed all weekday names to same length. But say if I want to have different length texts, I have to add another array, which will hold the length of the words. This is very weird, is there any means to avoid this?
Re: Any elegant way of text string handling?
Quote:
But say if I want to have different length texts, I have to add another array, which will hold the length of the words. This is very weird, is there any means to avoid this?
there are many ways that have be discussed on this forum over the years
try a forum search "embedded string" or "null terminated"
Re: Any elegant way of text string handling?
Well I've checked and there are some posts, with ASM code and referring to non-existing pbpcommunity domain.
So as I can see, the easiest method is to use an external EEPROM or chip's built in one (if there are not much strings to be used) and build system like this - say first 32 bytes (16 words) of eeprom contain entry addresses of separate strings, and to read the stirng we launch a routine, which will start reading eeprom at X address till it reaches value, stored in next string entry address area. Code (for reading single string) should look like this
Code:
READ 0, startval ' read entry address of 1st string
READ 2, nextval 'read entry address of next string
nextval=nextval-startval 'determine string length
LCDOUT $fe,$2 'set LCD start position to needed area (1st line in this case)
FOR A=1 to nextval 'start the loop
READ A,TXT 'read into variable
LCDOUT $fe,TXT, $14 "Output char and move cursor to next position
next
Not the best, but I guess better than with dealing with ASM.
Re: Any elegant way of text string handling?
Why not use a termination character, say 0 terminated string.
So you only have to check if you reached the 0 value in the data area that your message is stored.
This is what Richard suggested. No calculations required.
Ioannis
Re: Any elegant way of text string handling?
Nice idea, but I have to have all entries for next string marked, so this makes no big difference.....
Re: Any elegant way of text string handling?
It sure does...
Think about it.
Ioannis