Internal EEPROM read write operation of microcontroller use Mikcro C compiler
Internal EEPROM in PIC16F877A
PIC16F877A Microcontroller has three type memory.
Memory Map of EEPROMPIC16F877A Microcontroller has three type memory.
- Flash program memory ( 8kB)
- Data Merory(368 Byte)
- EEPROM Memory (256 Byte)
In this tutorial I am describe how to write and read operation of EEPROM Memory. The data EEPROM and Flash Program Memory are readable and writable during mormal operation over the entire Vdd range.EEPROM abbreviation is Electrically Erasable Programmable Read Only Memory. It is a Non-Volatile and Flash Memory. EEPROM design for high speed and high density at the expense of large erase blocks and number of write cycles.
EEPROM Library of Mikro C Pro For PIC
MikroC PRO for PIC includes library for comfortable work with EEPROM.
Library Routine
EEPROM Memory Write Opertation
Frist time I am write data, address at 080h to 09Fh and data 0x00 to 0x1F.
code: for(ii=0;ii<32;ii++){ // loop for write EEPROM Memory
EEPROM_Write(0x80,ii) ; // 0x80 is EEPROM Address & ii is data variable
}
Second time write data at address 002h and store data 0xAA.
Code: EEPROM_Write(0x02,0xAA);
Third time write data at address 050h and store data 0x55.
Code: EEPROM_Write(0x50,0x55);
EEEPROM Memory Read Operation
First time I read data on PORTB from Memory address 002h and location 2.
Code: EEPROM_Read(0x02);
![]() |
Data (0xAA) |
Second time I read data on PORTC from Memory address 050h and location 80.
Code: EEPROM_Read(0x50);
![]() |
Data ( 0x55) |
third time I read data on PORTD from Memory address (080h - 09Fh) and location (128 - 159).
Code: for(ii=0;ii<32;ii++){ // Read 32 bytes block from address0x80
PORTD = EEPROM_Read(0x80+ii); // and display data on PORTDdelay_ms(250);
}
Mikro C Code :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char ii; // loop variable | |
void main() { | |
TRISB = 0X00; // PORTB is output | |
TRISC = 0X00; // PORTC is output | |
TRISD = 0X00; // PORTD is output | |
PORTB = 0X00; // Clear PORTB | |
PORTC = 0X00; // Clear PORTC | |
PORTD = 0x00; // Clear PORTD | |
for(ii=0;ii<32;ii++) // Fill data buffer | |
EEPROM_Write(0x80+ii,ii); // Write data to address 0x80+ii | |
EEPROM_Write(0x02,0xAA); // Write data | |
EEPROM_Write(0x50,0x55); // Write me data at address 0x50 | |
delay_ms(1000); | |
PORTB = 0XFF; // Blinking PORTB | |
PORTC = 0XFF; // Blinking PORTC | |
delay_ms(1000); | |
PORTB = 0X00; | |
PORTC = 0X00; | |
delay_ms(1000); | |
PORTB = EEPROM_Read(0x02); // read data from address 0x02 and display it on PORTB | |
PORTC = EEPROM_Read(0x50); // read data from address 0x50 and display it on PORTB | |
delay_ms(1000); | |
for(ii=0;ii<32;ii++){ // Read 32 bytes block from address0x80 | |
PORTD = EEPROM_Read(0x80+ii); // and display data on PORTD | |
delay_ms(250); | |
} | |
} |
Program code file and proteus file downlaod For click download button.
![]() |
download |
No comments