When running in MPLAB® X Debug mode, EEPROM data can be edited in a PIC Memory view window of EEPROM Data. But some older devices don't offer debug capability and sometimes you just want to make a quick correction in a specific EEPROM location and reprogram the device. There is a simple way to modify it at program time by using the Project Properties window.
First, you have to fill the EEPROM Data memory at build time, and this ends up in the HEX file that gets programmed into your device. To do this you can use the _EEPROM_DATA macro in the MPLAB XC8 Compiler.
You must insert 8 bytes at a time starting from EEPROM address 0x00. Use this statement after #include <xc.h> at the top of your C code file.
EEPROM Code Section Example
//addr:0x00 … 0x07
__EEPROM_DATA(0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77);
//addr:0x08 … 0x0F
__EEPROM_DATA(0x12,0x23,0x45,0x67,0x89,0xab,0xcd,0xef);
Each line must specify exactly 8 bytes. The compiler places data in the order you have them in your C code. This data will be programmed into the EEPROM where you allow it to be programmed.
Changing a Specific Byte
If you only want to change a specific location, you can restrict the range of EEPROM addresses that are updated in the dev tool section of the program properties prior to reprogramming the device. For instance, let’s say you only wanted to change EEPROM address 0x05 which has the data 0x55 defined for it in the EEPROM code section example.
5
Click Apply and OK to close the window.
Build the project file and program the device.
Location 0x05 will be updated but the rest of EEPROM data will remain unchanged.