9.2.5 eeprom_write Function

A function that writes data to the EEPROM memory space.

Include

<xc.h>

Prototype

void eeprom_write(unsigned char address, unsigned char value);

Arguments

address
The EEPROM address to program
value
The value to program

Remarks

This function is available for all Mid-range devices that implement EEPROM. For PIC18 devices, calls to this routine will instead attempt to call the equivalent functions in the legacy PIC18 peripheral library, which you must download and install separately. It is recommended that for PIC18 devices you use MPLAB MCC to generate EEPROM access code, if possible.

This function tests and waits for any concurrent writes to EEPROM to conclude before performing the required operation. The function will initiate the write of value to EEPROM at address and this process will still be taking place when the function returns. The new data written to EEPROM will become valid at a later time. See your device data sheet for exact information about EEPROM on your target device.

Example

#include <xc.h>

int main(void)
{
  unsigned char data = 0x55;
  unsigned char addr = 0x20;

  eeprom_write(addr, data);
}