How to initialize EEPROM data

There is currently no specific #pragma to force EEPROM data value during chip programming. If you plan to initialize the EEPROM, the following will do the job: use the __asm__() instruction to insert one (or more) «DE» directive in the emitted code. See the gpasm documentation for details about this directive.

Another option is to explicitly put the data at the correct address, as showed by this example.

void your_function()
{
    /* Do the job this function is written for */
   return ;
   /* 
   the following sequence is just a hack to insert 
   data at eeprom addr in hex file
   It does not correspond to executable code 
   (and cannot be reached by execution flow)
   */
   __asm__("ee___sav equ $") ;
   __asm__("\torg 0xF00000") ;
   __asm__("\tfill 0,1024") ; // 1K byte eeprom memory for 18F2525
   __asm__("\torg ee___sav") ;

}

Here, I initialize all EEPROM space of a 18F2525 device with 0x00 (the default value for an «erased» chip is all 0xFF). Remember that the function must be used to be included in the final executable file.



Alain Gibaud 2015-07-09