Reading from the built-in EEPROM of your PIC

13 October, 2008 (06:00) | PIC, Tutorials | By: Joshua

We’ve already looked at the process of writing to your EEPROM, but it isn’t much use if you can’t retrieve the information.  In this post we’ll figure out how to get that information back so you can use it again.  It is much simpler than writing because there’s not the concern of corrupting data.

Again, this is based on the PIC16f690 but its basic principles should apply to most all PICs. Check in your data sheet to make sure you have the right register and bit names.

The registers and bits used to read from the EEPROM are as follows:

EEADR – EEprom ADdress: The location of the data you are attempting to retrieve.

EEPGD – EEprom ProGram Data: Selects whether you are accessing program or data memory.  0 is for data memory, 1 is for program memory.

EEDAT – EEprom DATa: This register is where the data retrieved from the EEPROM is placed.

RD – ReaD: This bit is set to start the process of pulling the data from the EEPROM and putting it into the EEDAT register.  This bit is set in software but can only be cleared in hardware.  It is reset when the transfer is complete, which takes only one clock cycle.

And an example function:

int read_eeprom(unsigned int address) {
EEADR = address;
EEPGD = 0;
RD = 1;
return EEDAT;
}

And that’s it. Piece of cake, right? If you have any issues with this or any further questions, just let me know!

Write a comment