Interfacing EEPROM with PIC Microcontroller

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.

24XX64 EEPROM Byte Write
24XX64 EEPROM Byte Write

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.


24XX64 EEPROM Page Write
24XX64 EEPROM Page Write

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.

24C64 EEPROM Current Address Read
24C64 EEPROM Current Address Read

 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.

24C64 EEPROM Random Read
24C64 EEPROM Random Read

 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.

24C64 EEPROM Sequential Read
24C64 EEPROM Sequential Read

Please Read Next Page to read about MikroC Programming.

Share this post

  • Hi Ligo Sir

    I am designing a speedometer cum odometer for my motor cycle.I need your help.My compiler is Mikro C.How can i store the odometer readings to external eeprom if the readings exceed 8 bit data?How can i store if the kilometer exceeds 255?Your earliest reply is expected.Give me the mikro c code also.Thanks in advance.I am using pic16f877a and 24c02 eeprom.Need to store km readings and read it back and display it on lcd(16×2).

  • if i will use 2 eeprom in the i2c bus.first address will be 1010000 and second device adress will be 1010001 ??

  • Hi Ligo, may I plz have the code for C18 compiler?? Actually i need to write a code for Library Management system by using PIC18F4550 microcontroller.

  • oh, i got it now!u mean we hardwire the address of each EEPROMs by setting or grounding their A0,A1, A2 pins differently in 8 different combinations(since 3 bits are used), thus generating a particular address to each EEPROM, right? thanks a great deal

  • You can connect pins A0, A1, A2 of the eeprom to different status (VDD or VSS) … and you can address a particular eeprom as explained in the Device Addressing Section…

  • if we are connecting more than 1 EEPROMs then, (here since we can join 8 EEPROMs), how does the EEPROMs know that the a particular 3 bit code varying from 000 to 111 is meant for them?is there a code to assign those 3 bit codes to respective EEPROMs??

  • See the section Device Addressing…
    You can see that there are 8bits for addressing…
    Higher 4 bits (1010) is preset in the device.. next 3 bits are the status of A2, A1, A0 of the device and the last bit specifies whether we want to write or read from the device…….
    By using A2,A1,A0 we can connect up to 8 EEPROM to an I2C Bus….


  • >