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 AVRIO RegistersIO registers, including <strong>the</strong> Status Register SREG, can be accessed in two ways. TheIO addresses between 0x00 to 0x3F can be used with <strong>the</strong> IN <strong>and</strong> OUT instructions toread <strong>and</strong> write <strong>the</strong> IO registers, or <strong>the</strong> data memory addresses between 0x20 to 0x5Fcan be used with <strong>the</strong> normal data accessing instructions <strong>and</strong> addressing modes. Bothmethods are available in C: Data memory addresses. A direct address can be used directly through pointerindirection <strong>and</strong> type casting. For example, SREG is at data memory address 0x5F:unsigned char c = *(volatile unsigned char *)0x5F;// read SREG*(volatile unsigned char *)0x5F |= 0x80;// turn on <strong>the</strong> Global Interrupt bitNote that <strong>for</strong> non-XMega devices, data memory 0 to 31 refer to <strong>the</strong> CPU registers!Care must be taken not to change <strong>the</strong> CPU registers inadvertently.This is <strong>the</strong> preferred method, since <strong>the</strong> <strong>compiler</strong> automatically generates <strong>the</strong> lowlevelinstructions such as in, out, sbrs, <strong>and</strong> sbrc when accessing data memory in<strong>the</strong> IO register region. IO addresses. You may use inline assembly <strong>and</strong> preprocessor macros to accessIO addresses:register unsigned char uc;asm(“in %uc,$3F”); // read SREGasm(“out $3F,%uc”); // turn on <strong>the</strong> Global Interrupt bitThis is not recommended, as inline assembly may prevent <strong>the</strong> <strong>compiler</strong> fromper<strong>for</strong>ming certain optimizations.Note: To read a general-purpose IO pin, you need to access PINx instead of PORTx,<strong>for</strong> example, PINA instead of PORTA. Please refer to Atmel’s documentation <strong>for</strong>details.121

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

Saved successfully!

Ooh no, something went wrong!