const uint8_t data[10] __at(0xF00000)={0,1,2,3,4,5,6,7,8,9};
uint8_t data2[10]={0,0,0,0,0,0,0,0,0,0},temp;
void writeEEPROM(uint8_t,uint8_t);
uint8_t readEEPROM(uint8_t);
void main(void) {
for(uint8_t i=0;i<sizeof(data);i++){
data2[i]=readEEPROM(i);
}
for(uint8_t i=0;i<sizeof(data);i++){
writeEEPROM(i,i+'A');
}
for(uint8_t i=0;i<sizeof(data);i++){
data2[i]=readEEPROM(i);
}
temp=readEEPROM(0);
while(1);
}
uint8_t readEEPROM(uint8_t add){
EEADR=add;
EECON1bits.EEPGD=0;
EECON1bits.CFGS=0;
EECON1bits.RD=1;
return(EEDATA);
}
void writeEEPROM(uint8_t add,uint8_t dat){
//interrupts must be disabled.
while(WR); //allow any existing write to complete
EEADR=add;
EEDATA=dat;
EEPGD=0;
CFGS=0;
WREN=1;
EECON2=0x55;
EECON2=0xAA;
WR=1;
WREN=0;
}