Menu

Table in EEPROM with #DEFINE NAME

Fulvio _
2023-02-02
2023-02-03
  • Fulvio _

    Fulvio _ - 2023-02-02

    Hello members,
    Working on Linux, but i might be no difference for other platform, I stumbled on this case.
    This is just a snippet.

    #chip 12F1840,32
    
    #DEFINE OK_OUT  512                 ' value where is permitted to light up
    #DEFINE MAXTIME  [WORD]20           ' value to count how many seconds to stay on
    #DEFINE ONTIME  1800                ' how many seconds to stay on by serial cmd
    #DEFINE NIGHTTIME  43200            ' period to disable the LDR input (12 hours)
    '8<-------8<-------8<-------8<-------8<-------8<-------8<-------8<-------
    Dim ADCthsld As Word                ' variable to store the current threshold
    Dim nsVal As Word                   ' current night value divider
    Dim ADCread As Word                 ' variable analog reading average
    EPread 6, nsVal                     ' reload the reduction value for night time
    EPread 0,ADCthsld                   ' Read the threshold from eeprom
    ADCread = OK_OUT                    ' default value, until new reading
    
    Table eepromdata Store Data
            OK_OUT                            ' low byte
            OK_OUTH                           ' high byte
            MAXTIME
            MAXTIMEH                          ' high byte
            NIGHTTIME
            NIGHTTIMEH                        ' high byte
            NIGHTSENSE
            NIGHTSENSEH                       ' high byte
    Table End
    

    Then the compiler gives me this error

    Aborting due to runtime error 14 ("abnormal termination" signal) in /tmp/GreatCowBASIC/sources/utils.bi::LINKEDLISTDELETE()

    Besides I should address my EPRead as Tableread, but I wasn't able to complete the compilation for the initial attempts.
    There could be an error of mine to expect to put a set of words in EEPROM to be set during the firmware writing .
    The purpose is to contain on the header all constant settings, rather than digging all the source if I will plan to make modifications.

     
  • Ccin E Crout

    Ccin E Crout - 2023-02-02

    Is that a valid name for a table?

    Try:
    Table eepromdataStoreData

    You will also need to access the High/Low bytes in the correct format:
    OK_OUT ' low byte
    OK_OUT_H ' high byte

     
  • Fulvio _

    Fulvio _ - 2023-02-02

    AFAIK the assembler would accept the following statement:

    #asmraw     low(OK_OUT)
    #asmraw      high(OK_OUT)
    

    But still doesn't go.
    Then I don't know how the compiler will load into variable, as little endian or big endian.

     

    Last edit: Fulvio _ 2023-02-02
    • Anobium

      Anobium - 2023-02-02

      Why are using #asmraw ?

      If you assigning a WORD variable to a BYTE variable then the compiler will only address the BYTE component of the WORD.

      If you assigning a WORD variable to a BYTE variable and you want to assign the HIGH BYTE then the compiler will only address the HIGH BYTE component of the WORD with suffix _H.

      wordvar = 0x12
      bytevar = wordvar -> result of bytevar = 0x02
      bytevar = wordvar_h -> result of bytevar = 0x01

       
  • Anobium

    Anobium - 2023-02-02

    I have not tried this before... but, always good to learn the compiler.

    I am using a word variable to read a word table (if you just read one value then the optimiser will not use a table.
    In the table, defined as a Word, just use the Word values.

    Evan

    #chip 12F1840,32
    
    #DEFINE OK_OUT  512                 ' value where is permitted to light up
    #DEFINE MAXTIME  [WORD]20           ' value to count how many seconds to stay on
    #DEFINE ONTIME  1800                ' how many seconds to stay on by serial cmd
    #DEFINE NIGHTTIME  43200            ' period to disable the LDR input (12 hours)
    '8<-------8<-------8<-------8<-------8<-------8<-------8<-------8<-------
    Dim ADCthsld As Word                ' variable to store the current threshold
    Dim nsVal As Word                   ' current night value divider
    Dim ADCread As Word                 ' variable analog reading average
    
    EPread 6, nsVal                     ' reload the reduction value for night time
    EPread 0,ADCthsld                   ' Read the threshold from eeprom
    
    ADCread = OK_OUT                    ' default value, until new reading
    
    Dim tableindex as Word
    Readtable eepromdata,tableindex , tabledata 
    For tableindex = 1 to tabledata
        Readtable eepromdata,tableindex , tabledata 
    Next
    
    Table eepromdata Store Data as Word
            OK_OUT                            ' low byte
            // OK_OUTH                           ' high byte
            MAXTIME
            // MAXTIMEH                          ' high byte
            NIGHTTIME
            // NIGHTTIMEH                        ' high byte
            //! NIGHTSENSE
            // NIGHTSENSEH                       ' high byte
    Table End
    

    ASM looks correct.

    TableEEPROMDATA equ 0
        de  3, 512, 20, 43200
    
     END
    
     
  • Fulvio _

    Fulvio _ - 2023-02-03

    This is the second day of life with GCbasic, the learning curve is pretty steep :-)
    I was looking at the idea to set the table as word, and also the read table, but try and fail got 90% of failures.
    So I will add this tip to my know-how baggage ;-)

    On the other hand, it was only the attempt to set the EEPROM with pre-defined values. So I have only to modify things in one place. As shown the data would be loaded on the variable with the even and fixed addressing.

    May there's the way to get the value of each displacement by the command sizeof(). It's looking like a Cish way.

     
    • Anobium

      Anobium - 2023-02-03

      Re sizeof(). For tables read the address 0.

      In the code below. I have read the number items in the table. (My code above did not do this... my err).

      Evan

      Dim tableindex as Word
      tableindex = 0
      Readtable eepromdata,tableindex , tabledata 
      For tableindex = 1 to tabledata
          Readtable eepromdata,tableindex , tabledata 
      Next
      
       
  • Fulvio _

    Fulvio _ - 2023-02-03

    SizeOf() on the array, I think I got it, but to have the way to know where it could be the next variable saved somewhere in the memory I probably would make something like:

    Sub EEreadSavedData()
    ' the routine intent is to save data in a structure fashion 
    ' where the memBank is what determine the number of block 
    ' to be written
    
      pntr = numblock * SavedDataSPACE + memBank
    ReadEEdata:
      EPRead pntr,SavedDataWr
      tmpl = SizeOf(SavedDataWr)
      pntr = pntr + tmpl
      EPRead pntr,SavedDataSize
      tmpl = SizeOf(SavedDataSize)
      pntr = pntr + tmpl
      EPRead pntr,SavedDataTotLen
      tmpl = SizeOf(SavedDataTotLen)
      pntr = pntr + tmpl
      EPRead pntr,SavedDataRep
    EndSub
    

    This is what a developer wish to have. The reason is that a certain point the data may need to be changed on the source to some different cast, then to preserve the same functionality the compiler should help out to recover the position on that Table and load the reshaped variable.

    I learned to write in C/C++ and that offers more things as I'm telling here, but I like the concept to have a broader number of MCU that can use the same language to compile, like GCbasic.

    My apologies for such ambitious design, I'm understanding that is a lot of things to add more features, therefore it's just my intention to share some idea, not to ask for more.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.