EEPROM Library
EEPROM data memory is available with a number of AVR family. The mikroBasic PRO for AVR includes a library for comfortable work with MCU's internal EEPROM.

Library Routines
EEPROM_Read
Prototype |
sub function EEPROM_Read(dim address as word) as byte |
---|---|
Returns |
Byte from the specified address. |
Description |
Reads data from specified Parameters :
|
Requires |
Nothing. |
Example |
dim eeAddr as word temp as byte ... eeAddr = 2 temp = EEPROM_Read(eeAddr) |
EEPROM_Write
Prototype |
sub procedure EEPROM_Write(dim address as word, dim wrdata as byte) |
---|---|
Returns |
Nothing. |
Description |
Writes Parameters :
![]() |
Requires |
Nothing. |
Example |
dim eeWrite as byte wrAddr as word ... eeWrite = 0x02 wrAddr = 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 dim counter as byte ' loop variable main: DDRA = 0xFF DDRB = 0xFF DDRC = 0xFF for counter = 0 to 31 ' Fill data buffer EEPROM_Write(0x100 + counter, counter) ' Write data to address 0x100+counter next 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 PORT0 PORTB = EEPROM_Read(0x150) ' Read data from address 0x150 and display it on PORT1 Delay_ms(1000) for counter = 0 to 31 ' Read 32 bytes block from address 0x100 PORTC = EEPROM_Read(0x100+counter) ' and display data on PORT2 Delay_ms(100) next counter 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!