Easy start with AVR EEPROM using WinAVR

AVR microcontrollers are loaded with some amount of EEPROM (Electronically Erasable Read-Only memory ) memory. This is handy feature allowing developers to store program parameters like service information, constants, menu strings etc. Atmel states that AVR EEPROM memory can be rewritten over 1000000 times. Reading is unlimited. In this article I am going to show how to store data to EEPROM by defining a variables. For this we need to include eeprom.h header from avr directory (#include “avr/eeprom.h” ). Then we can just write simple variable declaration using simple attribute EEMEM: #include “inttypes.h” #include “avr/io.h” #include “avr/iom8.h” #include “avr/eeprom.h” //store initial byte to eeprom uint8_t EEMEM eeprombyte=0x10; //store initial word to eeprom uint16_t EEMEM eepromword=0x5555; //store string to eeprom uint8_t EEMEM eepromstring[5]={“Test\0”}; int main(void) { //RAM byte variable uint8_t RAMbyte; //RAM word variable uint16_t RAMword; //RAM array of bytes uint8_t RAMstring[5]; //read byte from EEPROm and store to RAM RAMbyte = eeprom_read_byte(&eeprombyte); //read word from EEPROM and store to RAM RAMword = eeprom_read_word(&eepromword); //copy string fro mEEPROM to RAM eeprom_read_block ((void *)&RAMstring, (const void *)&eepromstring,5); return (0); }   EEMEM keyword indicates to compiler that variables are stored in EEPROM and it creates separate .eep file which has to be…

Continue reading