EEPROM memory allocation

Language reference ›› Variables ››
Parent Previous Next

See also: The $SPACE directive, Constants in EEPROM.

A great PMP feature is its special ability to allow allocation of variables either in RAM or EEPROM.

Variables in EEPROM should be used with care since they are time consuming (read may take ~5-6 instructions per byte with speed optimization, write takes ~5 ms typical per byte) and the number of writes is limited by the PIC technology.

Reading bit variables in EEPROM is implemented as a byte read then masking; writing bit variables in EEPROM is implemented as a byte read, masking and write back. This is a bit time consuming.

There is some limitations in using EEPROM variables:

NEW! (V2.0): The $SPACE EEPROM directive may still be used to define a bunch of variables, but the EEPROM qualifier may be used to override the current $SPACE RAM to define explicitly one or several variables to be in EEPROM (see example below):

 {$SPACE EEPROM} // next in EEPROM
 {$SPACE RAM} // next in RAM
 MyString: STRING; { string in RAM }
 EE_BYTE_3, EE_BYTE_4: EEPROM BYTE; { Two EE simple variables; the EEPROM keyword overrides the $SPACE RAM }
 EE_BYTE_5: EEPROM BYTE = $AA; { An EE simple variable with an initial value; the EEPROM keyword overrides the $SPACE RAM }

Tip: To limit EEPROM writes (e.g.: to extend "life time" and limit execution time), a construct like hereafter should be preferred:

 IF RAM_PARAM <> EE_PARAM THEN EE_PARAM := RAM_PARAM; { Store to EEPROM only if changed }