#include <htc.h>#include <string.h>
#ifndef EEPROM_H
#define EEPROM_H
unsigned char x,len,i,u;
void EEPROM_Write()
{
EECON1bits.EEPGD = 0; //Points to EEPROM
EECON1bits.CFGS = 0; //Points to Flash and EEPROM
EECON1bits.WREN = 1; //EEPROM Write Enable bit
INTCONbits.GIE = 0; //Disable all Interrupts
EECON2 = 0x55;
EECON2 = 0xAA;
EECON1bits.WR = 1; //WR Control bit initiates Write Operation
INTCONbits.GIE = 1;
// while(!PIR2bits.EEIF);
Nop();
Nop();
Nop();
// PIR2bits.EEIF = 0;
EECON1bits.WREN = 0;
}
void EEPROM_Write_String(unsigned char msg[],unsigned char address)
{
len = strlen(msg);
for(i=0;i<len;i++)
{
EEADR = address + i;
EEDATA = msg[i];
EEPROM_Write();
}
}
unsigned char EEPROM_Read(unsigned int add)
{
EEADR=add;
EECON1bits.EEPGD = 0; //Point to EEPROM
EECON1bits.CFGS = 0; //Points to Flash and EEPROM
EECON1bits.RD = 1; //EEPROM Read Enable Bit
u=EEDATA;
return(u);
}
#endif /* EEPROM_H */