Lorem ipsum dolor sit amet, consectetur adipiscing elit. Test link

Search Suggest

PIC16F877A internal EEPROM code

This post provides the internal EEPROM reading and writing code for PIC16F877A microcontroller. As we know, PIC16F877A microcontroller has 256 bytes of built in EEPROM data space with an address range of 0x00 to 0xFF. 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 blink an LED with PIC16F877A microcontroller. If you don't then please read this page first, before proceeding with this article.

The result of simulating the code in Proteus is shown below.

PIC16F877A internal EEPROM code
Figure 1. Internal EEPROM testing circuit for PIC16F877A

In the above circuit, LED attached on RB0 indicates whether a byte was successfully written in the internal EEPROM or not. In the above figure, LED is ON which indicates that EEPROM was successfully programmed.

In the main function, firstly RB0 pin is made an output. After that, eeprom_write(address, value) function writes the desired data value on the given address in the internal EEPROM. For example, in the above code a value of 0xFF is being written on the 0x00 address of EEPROM. Also, eeprom_read(address) function reads the value of byte present at the given address. In the above code, the data value from the 0x00 address of internal EEPROM is being compared to 0xFF, if it is a match then LED is turned on, if it is not a match then LED is turned off.

These two functions eeprom_write(address, value) and eeprom_read(address) are built in functions provided by the HI-TECH C compiler. You don't need to write your own functions to access internal EEPROM. Just use these functions and you are done. It is that simple.

You can leave your comments and suggestions in the comment section below.

EEPROM code for PIC16F877A 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.

Blogger, English Education Student, Photographer

Post a Comment