EEPROM
Steps to ------Read
1. Specify the memory location in EEADR (EEADR=4;)
2. Clear the EEPGD bit (EEPGD=0 ;)
3. Read the value from EEDATA register (unsigned short int a =EEDATA ;)
Steps to ------Write
1. Specify the memory location in EEADR (EEADR=4;)
2. Write the value to EEDATA register (EEDATA=7;)
3. Set WREN (WREN=1;)
4. Clear the EEPGD bit (EEPGD=0 ;)
5. Write 55h to EECON2 (EECON2=0x55;)
6. Write AAh to EECON2 (EECON2=0xAA;)
7. Set the WR bit (WR=1;)
#define _XTAL_FREQ 16000000
__CONFIG(0x3f7a);
unsigned short int eeread();
eewrite(unsigned short int ,unsigned short int );
main()
{
eewrite(4,'1');
unsigned short int a=eeread(); //data from eeprom
TRISB=0;
PORTB=a;
while(1) ;
}
unsigned short int eeread()
{
EEADR=4;
EEPGD=0;
unsigned short int z =EEDATA;
return z;
}
eewrite(unsigned short int x,unsigned short int y)
{
EEADR=x;
EEDATA=y;
WREN=1;
EEPGD=0 ;
EECON2=0x55;
EECON2=0xAA;
WR=1;
}