HELP EEPROM

There are two types of memory on a PIC - the RAM (Random Access Memory), and the ROM (Read-Only Memory). The RAM is temporary memory (i.e. it can change), whereas the ROM is permanent.

On all PICs, the program is stored in the ROM (in a section called the program memory). Some PICs (e.g. the P16C84) have an EEPROM (electrically erasable programmable ROM), which is a part of the ROM that you can use for storage purposes.

With the file registers in the RAM, there is no certainty that when you reset, or power-up the PIC, the values inside them will be the same as when you switched the PIC off. An EEPROM is therefore a useful place to store data, which you can be sure will remain unchanged, even when you switch the power off to the PIC. Whereas the program memory ROM is stored in 12-bit, or 14-bit packets depending on the amount of bits instructions take up on a given PIC, the EEPROM stores data in a similar way to file registers - 8 bits for every EEPROM address.

The EEPROM will have a number of file registers in the RAM associated with it, such as EEADR (which holds the address in the EEPROM being read or written to), EEDATA (which holds the data read from the EEPROM, or about to be written to the EEPROM), and EECON1, EECON2 etc., which control various settings of the EEPROM.

Reading from the EEPROM is fairly straightforward, because it poses no threat to the security of the data (in other words read the data doesn't change the data). This normally involves chosing what address of the EEPROM you wish to read, and then setting a bit in EECON1 to initiate the read, and then the data read will be found in the EEDATA file register. The easiest way to do this is to use the PIC PRESS read EEPROM macro:

Writing to the EEPROM is more complicated, because it involves a change to the data stored in the EEPROM. To protect against an accidental write operation, the PIC requires a secret handshake in order to successfully write to the EEPROM. For example, on the P16C84, the following four lines must immediately preceed the write operation:

movlw 0x55 ; secret handshake
movwf EECON2 ;
movlw 0xAA ;
movwf EECON2 ;
      
bsf EECON1, ? ; initiates EEPROM write

The EEPROM write operation takes a short amount of time, so you may wish to use the EEPROM write complete interrupt which is triggered when the EEPROM write operation finishes. There is a PIC PRESS EEPROM write macro which you may wish to use.

You may wish to get more help on this topic.

Back to Index

Related topics
ROM
Copyright ©2006 Perfect Square Ltd.