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 AVRGlobal RegistersSometimes it is more efficient if your program has access to global registers. Forexample, in your interrupt h<strong>and</strong>lers, you may want to increment a global variable thatano<strong>the</strong>r part of <strong>the</strong> program may need to access. Using regular C global variables inthis manner may require more overhead than you want in interrupt h<strong>and</strong>lers due to <strong>the</strong>overhead of saving <strong>and</strong> restoring registers <strong>and</strong> <strong>the</strong> overhead of accessing memorywhere <strong>the</strong> global variables reside.You can ask <strong>the</strong> <strong>compiler</strong> not to use <strong>the</strong> registers R20, R21, R22, <strong>and</strong> R23 bychecking <strong>the</strong> Compiler->Options->Target->”Do Not Use R20..R23” option. You shouldnot check this option in general since <strong>the</strong> <strong>compiler</strong> may generate larger programbecause it has less registers to use. You cannot reserve o<strong>the</strong>r registers besides thisset.In rare cases when your program contains complex statements using long <strong>and</strong>floating-point expressions, <strong>the</strong> <strong>compiler</strong> may complain that it cannot compile suchexpressions with this option selected. When that happens, you will need to simplifythose expressions.You can access <strong>the</strong>se registers in your C program by using <strong>the</strong> pragma:#pragma global_register : :...<strong>for</strong> example:#pragma global_register timer_16:20 timer_8:22 timer2_8:23extern unsigned int timer_16;char timer_8, timer2_8;..#pragma interrupt_h<strong>and</strong>ler timer0:8 timer1:7void timer0(){timer_8++;}Note that you must still declare <strong>the</strong> datatypes of <strong>the</strong> global register variables. Theymust be of char, short, or int types, <strong>and</strong> you are responsible to ensure that <strong>the</strong>register numbering is correct. A 2-byte global register will use <strong>the</strong> register number youspecified <strong>and</strong> <strong>the</strong> next register number to hold its content. For example, timer_16above is an unsigned int, <strong>and</strong> it will occupy register R20 <strong>and</strong> R21.Since <strong>the</strong>se registers are in <strong>the</strong> upper 16 set of <strong>the</strong> AVR registers, very efficient codewill be generated <strong>for</strong> <strong>the</strong>m when assigning constants, etc.123

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

Saved successfully!

Ooh no, something went wrong!