#define __16f877A
#include"pic/pic16f877a.h"
void WriteByteToEE(unsigned char d, const unsigned char ad);
void main(void)
{
 WriteByteToEE( 0x45,0x01);
 while(1)
 {
  }
}

void WriteByteToEE(unsigned char d, const unsigned char ad)
{
        //EEADRH=0x21;
    EEADR  = ad;                          // Address to write to
    EEDATA = d;                           // Data to write
 
    WREN   = 1;                             // Enable writes to the EEProm
    GIE    = 0;                             // Disable interrupts during write
 
    EECON2 = 0x55;                          // Write "password" to EECON2
    EECON2 = 0xAA;
    WR     = 1;                             // Initiate a write cycle
 
    while(WR==1)                 //while loop
        {
         }         
                                           
    WREN   = 0;             // Wait for write to complete                        
    EEIF   = 0;             // Disable writes to EEProm
        GIE=1;

}

This is a c code which write the data to eeprom .But it doesn't work.
When this code is written in asm it works well.