5.4.5.1 EEPROM Variables

When compiling for Baseline and Mid-range parts, the __eeprom qualifier allows you to create named C objects that reside in the EEPROM space (see 5.3.9.2 EEPROM Type Qualifier).

Objects qualified __eeprom are cleared or initialized, as required, just like ordinary RAM-based objects; however, the initialization process is not carried out by the runtime startup code. Initial values are placed into the HEX file and are burnt into the EEPROM when you program the device. Thus, if you modify the EEPROM during program execution and then reset the device, these objects will not contain the initial values specified in your code at startup up.

The following example defines two arrays in EEPROM.

__eeprom char regNumber[10] = "A93213";
__eeprom int lastValues[3];

For both these objects, their initial values will appear in the HEX file. Zeros will be used as the initial values for lastValues.

The generated code to access __eeprom-qualified objects will be much longer and slower than code to access RAM-based objects. Consider copying values from EEPROM to regular RAM-based objects and using these in complicated expressions to avoid can’t generator code error messages.