Microchip , for whatever reason , have stopped including the PIC18 peripheral library with XC8(1.45) , so when I came to want access to the EEprom on a PIC18F14K22 … tough , not supported … “use MCC was the message...” so three options... 1/ use MCC. 2 /go back to old XC that had the peripheral library. 3 /write your own EEprom stuff. 1 / Can't spend the time learning MCC at the moment, 2 / go back to an old XC8 seems a daft move. 3 . DIY … this is my result … May save someone a couple of hours ...or not !
Code:
unsigned char readEEPROM(unsigned char ee_addr)
{
EEADR = ee_addr; //Address to be read
EECON1bits.EEPGD = 0;//Selecting EEPROM Data Memory
EECON1bits.RD = 1; //Initialise read cycle
return EEDATA; //Returning data
}
void writeEEPROM(unsigned char ee_addr, unsigned char nv_data)
{
unsigned char INTCON_SAVE;//To save INTCON register value
EEADR = ee_addr; //Address to write
EEDATA = nv_data; //Data to write
EECON1bits.EEPGD = 0; //Selecting EEPROM Data Memory
EECON1bits.WREN = 1; //Enable writing of EEPROM
INTCON_SAVE=INTCON;//Backup INCON interrupt register
INTCON=0; //Disables the interrupts
EECON2=0x55; //Required sequence for write to internal EEPROM
EECON2=0xAA; //Required sequence for write to internal EEPROM
EECON1bits.WR = 1; //Initialise write cycle
INTCON = INTCON_SAVE;//Enables Interrupt from saved
EECON1bits.WREN = 0; //To disable write
while(PIR2bits.EEIF == 0)//Check for completion of write
{
Nop(); //do nothing
}
PIR2bits.EEIF = 0; //Clearing EEIF bit
}