Interrupt Service Routine Declaration and Definition

The C language Standard does not specify a standard for declaring and defining Interrupt Service Routines (ISR). Different compilers have different ways of defining registers, some of which use non-standard language constructs.

AVR GCC uses the ISR macro to define an ISR. This macro requires the header file: <avr/interrupt.h>. In AVR GCC an ISR is defined as follows:

#include <avr/interrupt.h>
ISR(PCINT1_vect)
{
    //code
}

In IAR:

#pragma vector=PCINT1_vect //C90
__interrupt void handler_PCINT1_vect()
{
    // code
}

or

_Pragma("vector=PCINT1_vect") //C99
__interrupt void handler_PCINT1_vect()
{
    // code
}

There is also a way to create a method to define an ISR that is common between the two compilers (AVR GCC and IAR). Create a header file that has these definitions:

#if defined(__GNUC__)
    #include <avr/interrupt.h>
#elif defined(__ICCAVR__)
    #define __ISR(x) _Pragma(#x)
    #define ISR(vect) __ISR(vector=vect) __interrupt void handler_##vect(void)
#endif

This is read by the precompiler and correct code will be used depending on which compiler is being used. An ISR definition would then be common between IAR and GCC and defined as follows:

ISR(PCINT1_vect)
{
    //code
}