Skip to main content

AVR EEPROM Tutorial


 EEPROM

EEPROM (Electrically Erasable Programmable Read-Only Memory) is a type of non-volatile memory which can be programmed, erased, and re-programmed electrically while it is on the circuit board. A majority of AVR microcontrollers come with some built-in EEPROM which is a great place to store data that should not be lost when the system is powered down. This tutorial explains the MikroC EEPROM library with example


MikroC EEPROM Library

EEPROM data memory is available with a number of AVR family. The mikroC PRO for AVR includes a library for comfortable work with MCU's internal EEPROM.
  Important : EEPROM Library functions implementation is MCU dependent, consult the appropriate MCU datasheet for details about available EEPROM size and address range.
Library Routines
EEPROM_Read
Prototype
unsigned short EEPROM_Read(unsigned int address);
Returns
Byte from the specified address.
Description
Reads data from specified address.
Parameters :
  • address: address of the EEPROM memory location to be read.
Requires
Nothing.
Example
unsigned int address = 2;
unsigned short temp;
...
temp = EEPROM_Read(address);
EEPROM_Write
Prototype
void EEPROM_Write(unsigned address, unsigned short dData);
Returns
Nothing.
Description
Writes wrdata to specified address.
Parameters :
  • address: address of the EEPROM memory location to be written.
  • wrdata: data to be written.
  Note : Specified memory location will be erased before writing starts.

Example
unsigned address = 0x732;
unsigned short dData = 0x55;
...
EEPROM_Write(address, dData);
Example
This example demonstrates using the EEPROM Library with ATMEGA16 MCU.
First, some data is written to EEPROM in byte and block mode; then the data is read from the same locations and displayed on PORTA, PORTB and PORTC.
char ii;                                   // loop variable

void main(){
   DDRA = 0xFF;                            // Set signal port as output
   DDRB = 0xFF;                            // Set signal port as output
   DDRC = 0xFF;                            // Set signal port as output
  
   PORTA = 0x00;                           // Clear signal ports
   PORTB = 0x00;
   PORTC = 0x00;
   Delay_ms(2000);

   EEPROM_Write(0x02,0xAA);                // Write some data at address 2
   EEPROM_Write(0x150,0x55);               // Write some data at address 0x150

   PORTA = EEPROM_Read(0x02);              // Read data from address 2 and display it on PORTA
   PORTB = EEPROM_Read(0x150);             // Read data from address 0x150 and display it on PORTB

   Delay_ms(1000);

   for(ii = 0; ii < 32; ii++)              // EEPROM write loop
     EEPROM_Write(0x100+ii, ii);           // Write data to address 0x100+ii

   for(ii = 0; ii < 32; ii++) {            // EEPROM read loop
     PORTC = EEPROM_Read(0x100+ii);        // Read data from address 0x100+ii
     Delay_ms(100);                        //   and display it on PORTC
   }
  
}



Circuit


Comments

Popular posts from this blog

PIC 16F877A Microcontroller Based Electronic Lock 16x2LCD 4x3 Keypad

 Circuit Diagram Security is a prime concern in our day-today life. Everyone wants to be as much secure as possible. An access control for doors forms a vital link in a security chain. The microcontroller based digital lock for Doors is an access control system that allows only authorized persons to access a restricted area. An electronic lock or digital lock is a device which has an electronic control assembly attached to it. They are provided with an access control system. This system allows the user to unlock the device with a password. The password is entered by making use of a keypad. The user can also set his password to ensure better protection. The major components include a Keypad, LCD and the controller PIC16F877A. This article describes the making of an electronic code lock using the 16F877A microcontroller. The system is fully controlled by the 8 bit microcontroller 16F877A which has a 8Kbytes of ROM for the program memory. The password is stored in the

Electronic Voting Machine Using 8051 Microcontroller (AT89C51)

  Circuit Electronic voting machine has now replaced the traditional mechanism of voting due to several advantages like security, automatic counting etc. This project presents a way to develop an electronic voting machine which displays the count of votes on a 16x2 LCD interface. A user can get his/her vote register through a set of switches (one for each candidate). After every cast of vote, the subsequent count can be seen on LCD. The circuit uses AT89C51 microcontroller and the code for the project has been written in C. This LCD based electronic voting machine is designed for four candidates. The input part consists of a set of six tactile switches. The switches and 16x2 LCD are interfaced to microcontroller AT89C51 for various operations and displays. The provision of casting votes for the candidates has been provided through four of these switches. These switches are made active high and connected to pins 2-5 (P1^1 – P1^4) of the controller. The remaining two

PC Based Digital Voltmeter Using PIC 16F877A

Voltmeter C# .Net PIC, Arduino, AVR This is a simple voltmeter which measures 0-5V at a precision of 4.8 mV. This is a simple design using inbuilt ADC of PIC 16F877A. PIC 16F877A have 8 channel 10bit ADC.   This is a computer interfaced project. Measured voltage is output in serial interface software in computer. There is a serial interface circuit (MAX232) is necessary for interfacing with computer, which is not included in the circuit. Please check       PIC Serial Communication Tutorial (UART)   for the circuit and more details. Using one of the most popular 8 bit PIC 16f877A, for instance, reading the datasheet , we'll find that the ADC modules (10 bit) are controlled by four different registers. The first two, ADCON0 and ADCON1 , are used to set and start the ADC module. When high level language is used, the programmer doesn't need to care a lot of the register connected to the results because they are normally stored in a variable by a rout