Atmel CAVR-4 Manual De Usuario

Descargar
Página de 323
CAVR-4
Part 1. Using the compiler
Functions
29
Special function types 
This section describes the special function types interrupt and monitor. The AVR IAR 
C/C++ Compiler allows an application to take full advantage of these AVR features, 
without forcing you to implement anything in assembler language.
INTERRUPT FUNCTIONS 
In embedded systems, the use of interrupts is a method of detecting external events 
immediately; for example, detecting that a button has been pressed.
In general, when an interrupt occurs in the code, the microcontroller simply stops 
executing the code it runs, and starts executing an interrupt routine instead. It is 
imperative that the environment of the interrupted function is restored; this includes the 
values of processor registers and the processor status register. This makes it possible to 
continue the execution of the original code when the code that handled the interrupt has 
been executed.
The AVR microcontroller supports many interrupt sources. For each interrupt source, an 
interrupt routine can be written. Each interrupt routine is associated with a vector 
number, alternatively multiple vector numbers, which is specified in the AVR 
microcontroller documentation from the chip manufacturer. The header file 
ioderivative.h
, where 
derivative
 corresponds to the selected derivative, contains 
predefined names for the existing exception vectors.
To define an interrupt function, the 
_ _interrupt
 keyword and the 
#pragma
 
vector
 
directive can be used. For example:
#pragma vector=0x14
_ _interrupt void my_interrupt_routine(void)
{
  /* Do something */
}
Note: An interrupt function must have the return type 
void
, and it cannot specify any 
parameters.
If a vector is specified in the definition of an interrupt function, the processor interrupt 
vector table is populated. It is also possible to define an interrupt function without a 
vector. This is useful if an application is capable of populating or changing the interrupt 
vector table at runtime. See the chip manufacturer’s AVR microcontroller 
documentation for more information about the interrupt vector table.