#include <pic.h>
//───────────────────────────────────
// Read data
//───────────────────────────────────
unsigned char E2promRead( unsigned char adr )
{
EEADR = adr;
RD = 1; // Set read bit
return( EEDATA ); // Return read data
}
//───────────────────────────────────
// Write data
//───────────────────────────────────
void E2promWrite( unsigned char adr, unsigned char data )
{
EEADR = adr;
EEDATA = data;
WREN = 1; // Set write enable bit
EECON2 = 0x55;
EECON2 = 0xaa;
WR = 1; // Set programming bit
while( EEIF == 0 ) // Wait till write operation complete
{
NOP();
}
EEIF = 0; // Clear EEPROM write complete bit
WREN = 0; // Clear write enable bit
}