D:\Prg\C2CW\TEST\minF877\eeprom.c

Read/write eeprom routines for PIC16F877


// write & read EEPROM routines (for 16F877)

// Author : Joan Ilari - e-mail: c2c@ilari.org

void write_eeprom ( char addr, char data )
{        //---- Write eeprom -----

 while ( _EECON1 & _WR);                // check completion of last write
 _EEADR = addr;                        // set address register
 _EEDATA = data;                        // set data register
 clear_bit ( _EECON1, EEPGD );
 set_bit( _EECON1, WREN );
 _EECON2 = 0x55;
 _EECON2 = 0xAA;
 set_bit( _EECON1, WR );                // write command
 clear_bit( _EECON1, WREN );        // inhibit further writing
}

char read_eeprom ( char addr )
{        //---- Read eeprom -----

 _EEADR = addr;                        // set address register
 clear_bit ( _EECON1, EEPGD );
 set_bit( _EECON1, RD );                // read command
 return (_EEDATA);
}




Copyright© 2002 Pavel Baranov