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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

ICCV8 <strong>for</strong> AVR – C Compiler <strong>for</strong> Atmel AVR#pragma data:data...int i;EEPROM_READ((int)&foo, i); // i now has 0x1234The second pragma is necessary to reset <strong>the</strong> data area name back to <strong>the</strong> defaultdata.Note that to work around <strong>the</strong> hardware bug in <strong>the</strong> older AVRs, location 0 is not used<strong>for</strong> <strong>the</strong> initialized EEPROM data <strong>for</strong> some of <strong>the</strong>se older devices (mostly <strong>the</strong> pre-MegaAT90S series).Note that when using this in an external declaration (e.g. accessing foo in ano<strong>the</strong>rfile), you do not use <strong>the</strong> pragma. For example, in ano<strong>the</strong>r file:extern int foo;int i;EEPROM_READ((int)&foo, i);Internal FunctionsThe following functions can be used directly if needed, but <strong>the</strong> macros describedabove should suffice <strong>for</strong> most if not all situations. unsigned char EEPROMread(int location)Reads a byte from <strong>the</strong> specified EEPROM location. int EEPROMwrite(int location, unsigned char byte)Writes byte to <strong>the</strong> specified EEPROM location. Returns 0 if successful. void EEPROMReadBytes(int location, void *ptr, int size)Reads size bytes starting from <strong>the</strong> EEPROM location into a buffer pointed toby ptr. void EEPROMWriteBytes(int location, void *ptr, int size)Writes size bytes to EEPROM starting with location with content from a bufferpointed to by ptr.“Real Time” EEPROM AccessThe preceding macros <strong>and</strong> functions wait until <strong>the</strong> any pending EEPROM write isfinished be<strong>for</strong>e <strong>the</strong>ir access. The files rteeprom.h <strong>and</strong> rteeprom.c in <strong>the</strong>c:\iccv8<strong>avr</strong>\examples.<strong>avr</strong> directory contain source code <strong>for</strong> routines that read<strong>and</strong> write to EEPROM that do not wait. This is particularly useful <strong>for</strong> a real-time137

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

Saved successfully!

Ooh no, something went wrong!