5.1.4 Writing an ISR

It is relatively easy to write an ISR in C using avr-gcc and the libc package.

If you plan to write your own ISR, be sure to include the following lines at the top of your program files:

#include <avr/io.h>
#include <avr/signal.h>

The first line allows the compiler and header files automatically determine which MCU is being used, then automatically include the proper macro definitions. For a list of applicable interrupts for a particular MCU, do the following:

Once you have found the name of the interrupt you want to handle, define a shell ISR as follows:

SIGNAL(SIG_OVERFLOW1)
{
}

This example is a shell to handle overflow interrupts from timer 1. Note that the macro SIGNAL automatically specifies the necessary compiler options so that the ISR uses the special return instruction at the end.

Copyright © 2006-02-15 by Tak Auyeung