Summary of Interfacing of PIC16F84A with (i2c based) 24LC64 EEPROM (Code + Proteus simulation)
This article details the software-based I2C interface between a PIC16F84A microcontroller and a 24LC64 EEPROM using C code in MPLAB. Since the PIC lacks built-in I2C, a software module is implemented. The project demonstrates writing strings like 'Saeed' to the EEPROM and reading them back to an LCD for verification via Proteus simulation.
Parts used in the Interfacing of PIC16F84A with 24LC64 EEPROM:
- PIC16F84A microcontroller
- 24LC64 EEPROM
- LCD (Liquid Crystal Display)
- RA4 pin (SDA)
- RB0 pin (SCK)
- 10K resistors
- MPLAB IDE
- HI-TECH C compiler
- Proteus simulation software
This post provides the code for interfacing 24LC64 EEPROM with PIC16F84A microcontroller. This 24LC64 EEPROM has i2c based interface and PIC16F84A doesn’t have any built in i2c modules, so software i2c module is created in the code. 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 PIC16F84A 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 create software i2c module in PIC16F84A, 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], RA4 pin is being used as SDA pin and RB0 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 PIC16F84A is configured to be the master. LCD is also attached with PIC16F84A, 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.
In the main function, firstly LCD is initialized using InitLCD() function. Then i2c pins are initialized using InitI2C() function. Then Write_Byte_To_24LC64_EEPROM(0x0001, ‘d’); function writes 0x64 (i-e ‘d’) value on 0x0001 address in the EEPROM. After that, Read_Byte_From_24LC64_EEPROM(0x0001); function reads a single byte from 0x0001 address and saves this value in RxByte variable.
Write_Page_To_24LC64_EEPROM(0x0020, TxArray, 4); function writes 4 bytes present in the TxArray starting from address 0x0020. And Read_Bytes_From_24LC64_EEPROM(0x0020, RxArray, 4); function reads 4 bytes from the starting address of 0x0020 and saves these bytes in RxArray. In the end all of these 5 received bytes are displayed on the LCD. You can verify from Figure 1, that all of these bytes were correctly received and displayed on the LCD. Using these simple read and write functions you can easily interface 24LC64 EEPROM with PIC16F84A.
Downloads
24LC64 EEPROM interfacing with PIC16F84A 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 PIC16F84A with (i2c based) 24LC64 EEPROM (Code + Proteus simulation)
- How does the PIC16F84A communicate with the 24LC64 EEPROM?
The PIC16F84A uses a software I2C module because it lacks built-in I2C hardware. - Which pins are used for the I2C communication?
RA4 is used as the SDA pin and RB0 is used as the SCK pin. - What components are required for the I2C protocol pull-up resistors?
Both SDA and SCK pins must be pulled up using 10K resistors. - Can this code be compiled without prior knowledge of LCD interfacing?
No, it is assumed the user knows how to interface an LCD with the PIC16F84A in 4bit mode. - How can one verify the data storage and retrieval process?
Data written to the EEPROM is read back and displayed on the LCD to confirm success. - What tools were used to compile and simulate the project?
The code was compiled in MPLAB v8.85 with HI-TECH C v9.83, and simulated in Proteus v7.10. - Does the LCD serve a critical function in the circuit operation?
No, the LCD is only attached to display values; it is not required for the core circuit functionality. - What specific functions are used to write multiple bytes to the EEPROM?
The Write_Page_To_24LC64_EEPROM function writes multiple bytes starting from a specified address.

