EEPROM stands for electrically erasable read only memory. It is a non volatile memory means that it will store the last data if any power failure. Suppose we want to count the number of visitors in a shop. If a power failure occurs then all data will be erased. In that case we can store our counting i.e. important data in EEPROM. Maximum all Atmega family microcontrollers have internal EEPROM memory. They can have from 512 bytes to 4k bytes of EEPROM memory space and is linearly organized. The EEPROM i.e. Electrical Erasable Programmable Read Only Memory stores the values and we can read the values as soon as the power on. In order to read and write data from this memory there is a necessary special access function-
In 7 segment display part we write a program to display numbers in 7 segment display. In this section we modify the program to store the numbers of visitor’s in the EEPROM instant of storing in the flash memory. We also introduce a push button to clear the EEPROM, so that we may have the ability to start from beginning. After erasing the EEPROM please restart the device unless useless data will show. We previously learn how to display in seven segment display. Now we introduce new function to display digits using persistence of vision.
void print(int num)
{
for(i=0;num!=0;i++)
{
digits[i]=num%10;
digit[i]=seven_segment(digits[i]);
num=num/10;
}
/* main part display number*/
for(i=0;i<3;i++)
{
PORTD=0x07; // Dark condition
_delay_ms(5);
PORTB=digit[i];
PORTD&=~(1<<i); // i display on
_delay_ms(5);
PORTD=0x07; // Dark condition
_delay_ms(5);
}
}
Download the count.c and count.h file. The main program as follow-
#include<avr/io.h>
#include<util/delay.h>
#include<avr/eeprom.h>
#include"count.h"
uint8_t x,start;
uint16_t num=0,value,z;
int main(void)
{
DDRB=0xff; //7 segment port
PORTB=0b11111100; //default value 0 to all the 7 segment;
DDRD=0x07; //7 segment control port
PORTD|=(1<<PIND4); //push button to clear the eeprom
z=eeprom_read_word((uint16_t*) 100);
num=z;
while(1)
{
start=PIND&0b00010000;
if(start==0)
{
eeprom_update_word((uint16_t*) 100,0); //clear EEPROM
num=0; //clear cash
display_zero();
while(!(PIND&0b00001000));
_delay_ms(100); //wait for switch debouncing delay
}
x=PIND&0b00001000;
if(x==8)
{
num++;
print(num);
_delay_ms(150);
eeprom_update_word((uint16_t*) 100,num);
}
else print(num);
}
return 0;
}
As soon as we run the program an extra file is generated that is main.eep, where the program EEPROM value stored. We have to load the main.eep file in the burner software as shown in the figure-