Professional Documents
Culture Documents
EECON2 = 0x55;
EECON2=0xAA;
EECON1bits.WR =1;
_asm NOP endasm
INTCONbits.GIE = 1;
EECON1bits.WREN =0;
TBLPTR =(short long) 0x1200;
TABLAT = H
_asm TBLWTPOSTINC _endasm
TABLAT = E
_asm TBLWTPOSTINC _endasm
TABLAT = L
_asm TBLWTPOSTINC _endasm
TABLAT = L
_asm TBLWTPOSTINC _endasm
TABLAT = O
_asm TBLWTPOSTINC _endasm
//long write
TBLPTR =(short long) 0x1200;
EECON1bits.EEPGD = 1;
EECON1bits.CFGS = 0;
EECON1bits.WREN =1;
INTCONbits.GIE = 0;
EECON2 = 0x55;
EECON2 = 0xAA;
EECON1bits.WR =1;
_asm NOP _endasm
INTCONbits.GIE = 1;
EECON1bits.WREN = 0;
Example in C language
This program
(a)Writes the message YESto
EEPROM memory
(b)Reads the same data from EEPROM
and sends it to PORTB one byte at a
time
#include<p18F458.h>
void EE_WRT(void);
unsigned char EE_READ(void);
void Delay(unsigned int itime);
Void main()
{
unsigned char x;
TRISB =0;
//write to EEPROM
EEADR =0x0;
EEDATA =Y;
EE_WRT();
EEADR =0x1;
EEDATA =E;
EE_WRT();
EEADR =0x2;
EEDATA =S;
EE_WRT();
EECON1bits.WREN=0; //disable write
void EE_WRT()
{
EECON1bits.EEPGD=0;
EECON1bits.CFGS=0;
EECON1bits.WREN=1;
INTCONbits.GIE=0;
EECON2=0x55;
EECON2 = 0xAA;
EECON1bits.WR = 1;
INTCONbits.GIE =1;
while (!PIR2bits.EEIF);
//if EEIF still 0 write operation
not //complete and will loop here forever.
PIR2bits.EEIF=0; //once complete, EEIF = 1, it is
complete //and need to be cleared in software
}