Effective ways for storing multiple string variables within PBP code?


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2013
    Posts
    1,078

    Default Effective ways for storing multiple string variables within PBP code?

    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:

    Code:
    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:

    Code:
    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?

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,388


    Did you find this post helpful? Yes | No

    Default Re: Effective ways for storing multiple string variables within PBP code?

    you failed to mention chip type, for a 16f1825 i would employ this method
    Code:
    ;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
    Warning I'm not a teacher

  3. #3
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Effective ways for storing multiple string variables within PBP code?

    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?

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,388


    Did you find this post helpful? Yes | No

    Default Re: Effective ways for storing multiple string variables within PBP code?

    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
    Last edited by richard; - 31st December 2021 at 10:46.
    Warning I'm not a teacher

  5. #5
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Effective ways for storing multiple string variables within PBP code?

    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?

  6. #6
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: Effective ways for storing multiple string variables within PBP code?

    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.

  7. #7
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Effective ways for storing multiple string variables within PBP code?

    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.

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    2,388


    Did you find this post helpful? Yes | No

    Default Re: Effective ways for storing multiple string variables within PBP code?

    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

    Name:  Screenshot 2021-12-31 210708.jpg
Views: 225
Size:  220.8 KB

    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
    Warning I'm not a teacher

Similar Threads

  1. How about String Variables?
    By mytekcontrols in forum PBP Wish List
    Replies: 40
    Last Post: - 20th January 2015, 12:53
  2. Replies: 2
    Last Post: - 12th November 2014, 07:57
  3. Replies: 4
    Last Post: - 18th September 2014, 07:59
  4. PBP and storing variables
    By Charlie in forum FAQ - Frequently Asked Questions
    Replies: 1
    Last Post: - 28th January 2012, 11:10
  5. Ways to make code easily reviewable and extendable
    By Ted's in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 23rd August 2008, 00:10

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts