PIC18F4550 On-Chip EEPROM - PIC Controllers
PIC18F4550 On-Chip EEPROM - PIC Controllers
Introduction
Electrically Erasable Programmable Read-Only Memory (EEPROM) is a non-volatile data memory. Data EEPROM is used
mainly to store information (data) which is changing frequently and also used for long-term storage of data.
We can store the data while an application is running. So if there is a power failure (supply off), data will never get lost unlike
volatile RAM and we can recollect the data stored in EEPROM.
It is basically used for the application such as Automatic Electric Meter Reading where the reading needs to be store for
continuous calculation and also if a power failure occurs then needs to store current reading also.
PIC18F4550 has in-built 256 Bytes of data EEPROM. Its address ranges from 0h-FFh.
The default content of EEPROM data memory is 0xff.
1. EEADR: Register holds the 8-bit address of the EEPROM location which we want to access. It can address up to a maximum
of 256 Bytes.
2. EEDATA: Register holds the 8-bit data for read/write operation.
3. EECON1: It is the EEPROM Control register which needs to be configured for Read/Write operation.
4. EECON2: It is not a physical register. It is used in memory erase and write sequence.
EEPROM Registers
Now let’s see the EEPROM registers in detail.
EECON1 Register
1= write operation is terminated before completion due to any reset in normal operation or due to improper write attempt.
EECON2
Before writing data to the EEPROM, a sequence of characters needs to be sent to the EECON2 Register.
The sequence given below must be written to the EECON2 Register
1. Write 0x55h
2. Write 0xAAh
EEPROM Interrupt
Also, note that when Write operation is completed EEIF interrupt flag is set which indicates write operation is completed.
This flag is located in PIR2 Register<bit 4>.
It must be cleared in software.
Note: EEPROM has an endurance of at least 1,000,000 writes/read cycles, so as there is a finite write/read cycle, never read/write
EEPROM in a continuous infinite loop.
/* Write Operation*/
EECON2=0x55;
EECON2=0xaa;
Read Operation
/*Read operation*/
return(EEDATA);
Example
We are going to use internal Data EEPROM to which first we write data to EEPROM memory location and then read the
same data from that memory location. After reading, transmit them serially to the terminal to display.
Write data to a 1st i.e. 0x00h location and onwards.
Also, Read data from the same memory location.
/* Store and Read data from internal EEPROM of PIC18F4550.
* www.electronicwings.com
*/
#include <stdio.h>
#include <stdlib.h>
#include <p18f4550.h>
#include "eeprom_osc.h"
#include "USART_Header_File.h"
void main()
int i;
i=0;
char Data_read;
EEPROM_WriteString(0,"electronicWings");
while(Data_read!=0xff)
Data_read=EEPROM_Read(i);
i++;
while(1);
/*Write Operation*/
EECON2=0x55;
EECON2=0xaa;
while(*data!=0)
EEPROM_Write(address,*data);
address++;
*data++;
/*Read operation*/
return(EEDATA);