EEPROM Library
EEPROM data memory is available with a number of AVR family. The mikroPascal 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 |
function EEPROM_Read(address: word) : byte; |
|---|---|
| Returns |
Byte from the specified address. |
| Description |
Reads data from specified Parameters :
|
| Requires |
Nothing. |
| Example |
var eeAddr : word; temp : byte; ... eeAddr := 2 temp := EEPROM_Read(eeAddr); |
EEPROM_Write
| Prototype |
procedure EEPROM_Write(address: word; wrdata: byte); |
|---|---|
| Returns |
Nothing. |
| Description |
Writes Parameters :
Note :
Specified memory location will be erased before writing starts.
|
| Requires |
Nothing. |
| Example |
var eeWrite : byte;
wrAddr : word;
...
address := 0x02;
wrdata := 0xAA;
EEPROM_Write(wrAddr, eeWrite);
|
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.
program Eeprom;
var counter : byte; // loop variable
begin
DDRA := 0xFF;
DDRB := 0xFF;
DDRC := 0xFF;
for counter := 0 to 31 do // Fill data buffer
EEPROM_Write(0x100 + counter, counter); // Write data to address 0x100+counter
EEPROM_Write(0x02,0xAA); // Write some data at address 2
EEPROM_Write(0x150,0x55); // Write some data at address 0x150
Delay_ms(1000); // Blink PORTA and PORTB diodes
PORTA := 0xFF; // to indicate reading start
PORTB := 0xFF;
Delay_ms(1000);
PORTA := 0x00;
PORTB := 0x00;
Delay_ms(1000);
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 counter := 0 to 31 do // Read 32 bytes block from address 0x100
begin
PORTC := EEPROM_Read(0x100+counter); // and display data on PORTC
Delay_ms(100);
end;
end.
Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
What do you think about this topic ? Send us feedback!




