Interfacing EEPROM with PIC Microcontroller
Contents
Writing Data to EEPROM
We can write data to 24C64 in two ways.
Byte Write
In this mode one byte is written at a time. After giving the START signal, the master send control byte, the control code (four bits), the chip select (three bits), and the R/W bit (which is a logic low) via I2C bus. This indicates the addressed device that, higher order address of memory location to be written will be follow after it has generated acknowledge signal. Thus next byte transmitted by master device will be higher order address and it will be stored in the address pointer of the 24XX64. The Least Significant Address byte will be followed after it has generated acknowledge signal. Then the master device will send data to written the address location. When the 24XX64 acknowledges, the master issues stop signal.

Note: Some delay should be given between sequential write processes otherwise write cycle may not occur.
Page Write
Page write is similar Byte write, instead of generating STOP signal master transmits up to 31 additional bytes. These are temporarily stored in the on-chip page buffer and will be written in to memory after the master has given STOP signal. If the master sends more than 32 bytes, previously written data will be over written.

Note: Some delay should be given between sequential write processes otherwise write cycle may not occur.
Reading Data From EEPROM
Data can be read from 24XX64 EEPROM in 3 ways.
Current Address Read
The 24XX64 EEPROM contains an internal counter which maintains address of last memory location accessed, incremented by one internally. Thus upon receiving control byte with read/write control bit set to 1, 24XX64 issues acknowledge signal and transmits the 8-bit data word in the next memory location.

Random Read
Random read operation allows master to access any memory location in random manner. To perform this type of operation, we want to set the address in internal address counter to the required value. This is achieved by sending address to 24XX64 EEPROM as the part of write operation. After the acknowledge of this process, the master issues a START signal and control byte for read operation. Thus the required random memory location can be easily accessed.

Sequential Read
Sequential Reading is initiated in a similar way as Random Read, except that after the 24XX64 EEPROM transmits first data byte master issues acknowledge signal instead of STOP signal in Random Read operation. This will direct 24XX64 EEPROM to send next data byte.

Please Read Next Page to read about MikroC Programming.