PDA

View Full Version : Effective ways for storing multiple string variables within PBP code?



CuriousOne
- 31st December 2021, 06:42
Hello.
I'm advancing my nixie clock project, and now it has LCD screen, which is used for setup config.
I want to add multi-language setup choices, and I have texts ready, but I come up with the following problem:

The setup routine has 14 steps total, and each step has own 16 character text displayed on LCD screen.

Each step has it's own part, which looks like this:



if menuitem=2 then
arraywrite topline, ["Set the year: "]
dlim=22:ulim=99
gosub gettime
gosub yeardecode
cvladi=T3*10+T4
gosub yrshow 'update screen
endif


For single language this is OK, but if I want to add more languages, say 8 different languages
this means, I'll have to make it look like this:



if menuitem=2 then


if language=1 then
arraywrite topline, ["Set the year: "]
endif

if language=2 then
arraywrite topline, ["Derniers baisers: "]
endif

if language=3 then
arraywrite topline, ["Sauerkraut: "]


dlim=22:ulim=99
gosub gettime
gosub yeardecode
cvladi=T3*10+T4
gosub yrshow 'update screen
endif


And so on. This is doable, but does not looks practical.
So I need a way to somehow reference to internal memory
So when I need to read say text for french language, I just point to address,
from where data for French can be read.

This is quite simple with EEPROM - just set offsets and you're done, but
the chips I'm using have only 256 bytes of eeprom, and setup text will require
14x16 bytes for each language, which means, I can only have one language available
I want to avoid usage of external EEPROM chips, since I have about 3K of data code
space free, so I think, these strings in different languages can be somehow
packed there?

richard
- 31st December 2021, 07:41
you failed to mention chip type, for a 16f1825 i would employ this method

;16f1825
#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _CP_OFF & _WDTE_OFF & _PWRTE_ON & _MCLRE_ON & _CLKOUTEN_OFF
__config _CONFIG2, _PLLEN_ON & _LVP_OFF
#ENDCONFIG


DEFINE OSC 32
OSCCON=$70
ANSELA=0
ANSELC=0
TRISA = %001110
trisc = %11100010 ' set PORTC I/O
Strings CON EXT
i VAR BYTE
Char VAR BYTE
ctemp VAR WORD
rand VAR WORD
StringNumber VAR BYTE
StartAddress VAR WORD
isa VAR WORD
lata.0=1
DEFINE DEBUG_REG PORTA
DEFINE DEBUG_BIT 0 ;
DEFINE DEBUG_BAUD 9600
DEFINE DEBUG_MODE 0
pause 2000
Debug "Start",13 ,10
Goto OverStrings
ASM
Strings; even length string terminates with a NULL, string cannot embed a null nor the eof chr chosen
da "Set Year", 0 ; 0
da "Set Month" ; 1
da "Set Date", 0 ; 2
da "Set day of week" ; 3
da "Set Hour", 0 ; 4
da "Set Minute", 0 ; 5

;lang 2
da "Jahr einstellen", 0 ;6+ 0
da "Set Month" ;6+ 1
da "Set Date", 0 ; 2
da "Set day of week" ; 3
da "Set Hour", 0 ; 4
da "Set Minute", 0 ; 5
lang 3
da "Definir l'annee", ; 12+ 0
da "Set Month" ; 12+ 1
da "Set Date", 0 ; 2
da "Set day of week" ; 3
da "Set Hour", 0 ; 4
da "Set Minute", 0 ; 5

dw 3 ;eof must not be in any string
ENDASM
OverStrings:


Start:
Debug "Program start",13,10
Debug "Address of first string: $", HEX4 Strings, 13 ,10


Action:
for rand=0 to 5
StringNumber = rand + 0 ;0=en ,6 ge ,12 fr ' Select which language and string to print
GOSUB findIndex
GOSUB PrintString ' And, you guessed it, go print it.
next
PAUSE 1000
goto Action
END


findIndex:
isa = Strings
while StringNumber
ReadCode isa, CTEMP
isa=isa+1
if CTEMP ==3 then
isa=0
return
endif
CTEMP=CTEMP&$7f
if (CTEMP==0) then
StringNumber=StringNumber-1
if StringNumber == 0 then return
endif
wend
return


PrintString:
if isa then
Debug 13,10,dec rand," "
For i = 0 to 19 ' Maximum string length is 20 characters
ReadCode (isa + i), CTEMP ' Get a char from string in question.
Char = (CTEMP>>7)
IF (Char = 0) THEN EXIT ' Break out if char is NULL
Debug Char ' Otherwise print it
Char = CTEMP&$7f
IF (Char = 0) THEN EXIT ' Break out if char is NULL
Debug Char ' Otherwise print it
NEXT
endif
RETURN

CuriousOne
- 31st December 2021, 10:31
PIC16F887, 16F917, 16F1939, basically any with built in oscillator, 44 pin tqfp case and at least 8k memory.

Why does this matters? above code uses some chip specific magic?

richard
- 31st December 2021, 10:39
chip has to able to read its code space, pic18 needs different treatment


there is a couple of typo's
;lang 2
da "Jahr einstellen", 0 ;6+ 0
da "Set Month" ;6+ 1
da "Set Date", 0 ; 2
da "Set day of week" ; 3
da "Set Hour", 0 ; 4
da "Set Minute", 0 ; 5
;lang 3 ;semi colon missing
da "Definir l'annee" ; 12+ 0 ;extra comma
da "Set Month" ; 12+ 1
da "Set Date", 0 ; 2
da "Set day of week" ; 3
da "Set Hour", 0 ; 4
da "Set Minute", 0 ; 5

CuriousOne
- 31st December 2021, 11:01
No I'm not using 18F series.
Regarding that "own code reading"
how it is named in datasheet, so I can have a look for appropriate models?

mpgmike
- 31st December 2021, 22:22
You said that if the EEPROM were larger, you could easily store the strings there, then find them with a look-up index. Newer PICs have the ability to write directly to Flash (HEF is one example, but not the limit). The mechanics of it are essentially the same as writing to EEPROM. PBP has no convenient command code for it (that I'm aware of), as it didn't exist when PBP was created. However, look at some of the PIC16F1xxxx chips (or PIC18FxxK40/42). You can treat Flash memory like EEPROM memory. Be aware that with Flash you must first erase an entire page before writing to it. If you intend to change the content periodically, you'll need temporary variables to store the entire page, alter what you wish to change, erase the page, then re-write back to the same addresses with the revised data.

CuriousOne
- 1st January 2022, 05:55
So I'm not asking for any direct-hardware-access methods. I just asked, whenever it is possible, using built-in abilities of PBP, structure all this in more simple to use way? Basically, I can hook a external EEPROM chip to my device, but I was not able to make to work any EEPROM with PBP, I2C or SPI.

richard
- 1st January 2022, 09:02
Regarding that "own code reading"
how it is named in datasheet

look for "read flash" or "read program flash", there is no consistency i have ever found in how microchip assemble datasheet info


So I'm not asking for any direct-hardware-access methods. I just asked, whenever it is possible, using built-in abilities of PBP

and it is , i "fancied up" my code a bit and can change language with one var

9131

mikes suggestion would be useful to allow a common set of string messages to read into hef in chosen language from a
pg-flash coded larger multi-lingual data set.

its all doable