Mengakses AVR EEPROM di AVR GCC + AVR Studio 4

Berikut adalah contoh akses EEPROM dengan EEMEM attribute.

#include <avr/io.h>
#include <avr/eeprom.h>
#define BLKSIZE 16
#define DATA 0x10
uint8_t EEMEM eechar;
uint16_t EEMEM eeword=0x1234;
uint8_t EEMEM eestring[] = "Write to EEPROM";
int main(void)
{
uint16_t sramword;
//where block has to be read
uint8_t readblock[BLKSIZE];
//write byte to location eechar
eeprom_write_byte(&eechar, DATA);
sramword=eeprom_read_word(&eeword);
//read block from EEPROM
eeprom_read_block ((void *)readblock, (const void *)eestring, BLKSIZE);
while(1)
{
    //do nothing
}
}

Dengan cara di atas alokasi address EEPROM akan diatur secara otomatis oleh software. Setiap variable EEPROM akan disimpan dalam file .eep. Maka dari itu .eep tersebut harus kita upload juga ke mikrokontroler.

Pada bagian flash masukan .hex sedangkan bagian EEPROM masukan .eep.

________________________________________________

DAFTAR PUSTAKA

http://www.embedds.com/accessing-avr-eeprom-memory-in-avrgcc/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s