11.07.2015 Views

Imagecraft c compiler and development environment for the atmel avr

Imagecraft c compiler and development environment for the atmel avr

Imagecraft c compiler and development environment for the atmel avr

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ICCV8 <strong>for</strong> AVR – C Compiler <strong>for</strong> Atmel AVRAccessing EEPROMThe EEPROM can be accessed at runtime using library functions. Use #include be<strong>for</strong>e calling <strong>the</strong>se functions.IMPORTANT: These functions do not work <strong>for</strong> <strong>the</strong> XMega. XMega support will beprovided in a later release. EEPROM_READ(int location, object)This macro calls <strong>the</strong> EEPROMReadBytes function (see below) to read in <strong>the</strong> dataobject from <strong>the</strong> EEPROM location(s). The int “object” can be any program variable,including structures <strong>and</strong> arrays. For example,int i;EEPROM_READ(0x1, i); // read 2 bytes into i EEPROM_WRITE(int location, object)This macro calls <strong>the</strong> EEPROMWriteBytes function (see <strong>the</strong> next section) to write<strong>the</strong> data object to <strong>the</strong> EEPROM location(s). The int “object” can be any programvariable, including structures <strong>and</strong> arrays. For example,int i;EEPROM_WRITE(0x1, i); // write 2 bytes to 0x1There are actually 3 sets of macros <strong>and</strong> functions: Most classic <strong>and</strong> mega AVRs AVRs with 256 bytes of EEPROM MegaAVRs with extended IOThe IDE predefines certain macros (e.g., ATMega168), so that <strong>the</strong> right macros <strong>and</strong>functions are used when you #include <strong>the</strong> eeprom.h header file. Thus, you mayuse <strong>the</strong> names given here <strong>for</strong> <strong>the</strong>se macros <strong>and</strong> functions.Initializing EEPROMEEPROM can be initialized in your program source file by allocation of a globalvariable to a special area called eeprom. In C source, this can be done usingpragmas. See Program Areas <strong>for</strong> a discussion of <strong>the</strong> different program areas. Theresulting file is .eep. For example,#pragma data:eepromint foo = 0x1234;char table[] = { 0, 1, 2, 3, 4, 5 };136

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!