The compiler includes a special type modifier keyword to define variables located in the EEPROM (@eeprom). Using the @eeprom type modifier, you can define standard global variables that will be located in the EEPROM area. e.g.
@eeprom unsigned char evar; // Variable located in EEPROM
@eeprom unsigned char *eptr; // Pointer is located in RAM, but points to EEPROM.
unsigned char * @eeprom eptr3; // Pointer is located in EEPROM, but points to RAM.
@eeprom unsigned char *@eeprom eptr2; // Pointer is located in EEPROM and points to EEPROM
Variables declared with the @eeprom modifier are allocated to the .eeprom section so they can be linked together easily. The @eeprom modifier also marks the data object so the compiler can perform the appropriate EEPROM erase/write sequence when an @eeprom modified variable is assigned or otherwise modified. When the compiler detects a write to an EEPROM location, it calls a machine library function that performs the actual erase and write of the EEPROM. The eeprom configuration and write routines are included in the library source file eeprom.s located in the machine library (libm).
Note that writing an eeprom location sometimes takes more than the watchdog allows, and the library functions do not service the watchdog: you can either disable the watchodog or modify the library to service it while waiting.
For Example using the HC12/HCS12 Compiler
The library file eeprom.s is located in \install_dir\cx12\cx12\src12\libm for the HC12 and \install_dir\cx12\src12\libe for the HCS12 family. The HC12 eeprom write routines include some symbols at the top that may need to be modified depending on your actual hardware. Processor reset values are used by default. If the register base address is changed the EBASE value must be changed accordingly. If the bus speed is different than the default you must modify TWAIT proportionally to maintain the proper delay.
EEPROG: equ $F3 ; control register
EBASE: equ $1000 ; eeprom starting address
TWAIT: equ 20000 ; wait value for 10ms @8MhzThe
ECNFG: equ $0113
EPROT: equ $0114
ESTAT: equ $0115
ECMD: equ $0116