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.
Requires

Nothing.

Example
unsigned address = 0x732;
unsigned short dData = 0x55;
...
EEPROM_Write(address, dData);

Library 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.

Copy Code To ClipboardCopy Code To Clipboard
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
   }
   
}
Copyright (c) 2002-2017 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code