Using Interrupts in AVR GCC

When we use interavrupqts in assembly language, we need to make sure that the interrupt vector jump table, which needs to be set up starting at address 0x00, is properly set up. The names we need to use for each possible interrupt source are defined in the datasheet for the chip being used. From that document (page 65) we see this table:

VectorNo Address Name Definition
0 0x0000 RESET Power-on Reset
1 0x0002 INT0_vect External Interrupt Request 0
2 0x0004 INT1_vect External Interrupt Request 1
3 0x0004 PCINT0_vect Pin Change Interrupt Request 0
4 0x0008 PCINT1_vect Pin Change Interrupt Request 1
5 0x000A PCINT2_vect Pin Change Interrupt Request 2
6 0x000C WDT_vect Watchdog Time-out Interrupt
7 0x000E TIMER2_COMPA_vect Timer/Counter2 Compare Match A
8 0x0010 TIMER2_COMPB_vect Timer/Counter2 Compare Match A
9 0x0012 TIMER2_OVF_vect Timer/Counter2 Overflow
10 0x0014 TIMER1_CAPT_vect Timer/Counter1 Capture Event
11 0x0016 TIMER1_COMPA_vect Timer/Counter1 Compare Match A
12 0x0018 TIMER1_COMPB_vect Timer/Counter1 Compare Match B
13 0x001A TIMER1_OVF_vect Timer/Counter1 Overflow
14 0x001C TIMER1_COMPA_vect Timer/Counter0 Compare Match A
15 0x001E TIMER1_COMPB_vect Timer/Counter0 Compare Match A
16 0x0020 TIMER0_OVF_vect Timer/Counter0 Overflow
17 0x0022 SPI_STC_vect SPI Serial Transfer Complete
18 0x0024 USART_RX_vect USART Rx Complete
19 0x0026 USART_UDRE_vect USART Data Register Empty
20 0x0028 USART_TX_vect USART Tx Complete
21 0x002A ADC_vect ADC Conversion Complete
22 0x002C EE_READY_vect EEPROM Ready
23 0x002E ANALOG_COMP_vect Analog Comparator
24 0x0030 TWI_vect 2-wire Serial Interface
25 0x0032 SPM_READY_vect Store Program Memory Ready

If you dig into the AVR_GCC files, you will find a file named Interrupts.h where a handy ISR macro is defined. We can use this macro to set up the required entry in the vector table:

#define ISR(vector)

The actual macro is more complex than this, but this will work for our assembly language work. The vector names we need to use are define din the table above.

As an example, here is how we would set up the required entry in the vector table for using the counter compare interrupt for Timer1:

        org 0x0000
RESET   rjmp        start

        org 0x0016
        rjmp        Timer1_ISR

start:  ; main code goes here

        ; code for interrupt service routine goes here.