PIC18 EEPROM fails to write
here is an example function to write to the eeprom.

void write_16f84_eeprom(unsigned char adr, unsigned char d)
{
   EEADR = adr;  // the address within the EEPROM
   EEDATA = d;   // the data to be written to that address

   WREN = 1;     // write enable
   EECON2 = 0x55; // protection sequence
   EECON2 = 0xaa;

   WR = 1;      // begin programming sequence

   // wait, in loop, for write operation to complete
   // I.E, WR control bit is 0
   //     and EEIF interrupt flag bit is 1

   WREN = 0;  // disable write enable

   // after completion of the write operation
   EEIF = 0 
}