Many of the different PICmicro processors contain an area of EEPROM memory. EEPROM stands for Electrically Erasable Programmable Read Only Memory, which translates to "memory which holds its value when the power is turned off". EEPROM is not like the PICmicro register memory, in that you can't just put values into it, instead you have to instruct the PICmicro to write or read a particular location.

EEPROM is useful as a way of replacing hardware like switches or lines which would otherwise have to be used to configure a device. Because it is important that such information is not corrupted by rogue programs the designers of the PICmicro have devised a sequence of actions you need to perform in order to store values in EEPROM. This sequence is given in detail in Practical 7, the digital lock, where you will also find code to read and write to this memory.

### Writing to EEPROM

To write to the EEPROM you must follow this sequence:

1. set the address of the destination in EEADR bank 0

2. put the data in EEDATA bank 0

3. turn off all the interrupts (clear GIE in INTCON) bank 0

4. set the write enable bit (WREN) in EECON1 bank 1

5. put the value 0x55 in EECON2 bank 1

6. put the value 0xAA in EECON2 bank 1

7. set the write bit (WR) in EECON1 bank 1

8. wait for the EEIF bit in EECON1 to set bank 1

9. clear the EEIF bit in EECON1 bank 1

10. clear the WREN bit in EECON1 bank 1

11. turn interrupts back on (set GIE in INTCON) bank 1

This rather long winded process will write a single byte to EEPROM. Note that EECON1 and EECON2 are in bank 1 and so your code must set the bit in the status register for this to work correctly.

### Reading from EEPROM

To read from the EEPROM is much easier. You just need to follow this sequence:

1. set the address of the source in EEADR bank 0

2. set RD bit in EECON1 bank 1

3. read the data from EEDATA bank0.

I have put these actions into the functions which I have written. See the code in ex71.c for this.