3.1 __eeprom Keyword
The IAR __eeprom
keyword places objects declared with the attribute in EEPROM
and additionally ensures that EEPROM-access routines are used to access such objects
either directly or indirectly via any pointer qualified with this same keyword.
Suggested Replacement
There are two changes that must both be made to IAR code to have it behave in a similar way when using MPLAB XC8.
To place an object in EEPROM, include the <avr/eeprom.h>
header
and use the EEMEM
attribute (or its expanded form,
__attribute__((section(".eeprom")))
with the object's
definition. This attribute, however, does not affect how the object is accessed.
To read the object, use the eeprom_read_byte()
,
eeprom_read_word()
, eeprom_read_dword()
, or
eeprom_read_block()
functions as appropriate, and the
corresponding eeprom_write_xxxx()
functions to write to the
object in EEPROM.
Caveats
None.
Examples
__eeprom int mode = 12;
volatile int x;
int main() {
x = mode;
}
to
MPLAB XC8 codes similar
to:#include <avr/eeprom.h>
int mode EEMEM = 12;
volatile int x;
int main() {
x = eeprom_read_word(&mode);
}
Further Information
See the Variables in EEPROM section in the MPLAB XC8 C Compiler User's Guide for AVR MCUs for more information on these attributes.