This post provides theΒ code for interfacing 24LC64 EEPROM with PIC16F877 microcontroller. This 24LC64 EEPROM has i2c based interface.
This code is written in C language using MPLAB with HI-TECH C compiler. You can download this code from the βDownloadsβΒ section at the bottom of this page.
It is assumed that you know how to interface LCD with PIC16F877 microcontroller in 4bit mode. If you donβt then please readΒ this pageΒ first, before proceeding with this article. It is also assumed that you know how to use i2c module in PIC16F877, if you donβt then please readΒ this pageΒ first. You should also read how to write/read a byte in/from 24LC64 EEPROM from itβs datasheet.
The result of simulating the code inΒ ProteusΒ is shown below.
In the above circuit[1], RC4 pin is being used as SDA pin and RC3 pin is the SCK pin. Both of these pins are pulled up using 10K resistors as required for i2c protocol. 24LC64 EEPROM is the slave device, while PIC16F877 is configured to be the master. LCD is also attached with PIC16F877, just to show the values received from the EEPROM, otherwise it is not required in this circuit.Β ProteusΒ provides an βI2C Debugger Toolβ which is attached on the SDA and SCK pins in the above circuit, this debugger shows all the activity on i2c bus[2]. It is attached in the circuit just for debugging purposes.
In the code, string βSaeedβ is stored in theΒ 24LC64Β EEPROM and then retrieved back and displayed on the LCD. As shown in Figure 1, βSaeedβ is correctly displayed on the LCD, this shows that it was stored and retrieved from 24LC64Β EEPROMΒ successfully.
Code
The code for the main function is shown below.
Downloads
24LC64 EEPROM interfacing with PIC16F877 code was compiled inΒ MPLAB v8.85 with HI-TECH C v9.83 compiler and simulation was made in Proteus v7.10.Β To download code andΒ ProteusΒ simulationΒ click here.
For more detail: Interfacing of PIC16F877 with (i2c based) 24LC64 EEPROM (Code + Proteus simulation)