Modifying a Single EEPROM Data Byte

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.

1

Open the Project Properties window.

image001.png

2

Select your programming tool window and select 'Memories to Program' menu.

image002.png

3

Choose the 'Manually select memories and ranges'.

image003.png

4

Check the 'Preserve EEPROM Memory' box and then select the range of memory to leave untouched. Notice that location 0x05 is not listed.

image004.png

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.

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.