{ ^_^ } sinustrom Solving life, one problem at a time!

ATmega8/128 assembly interrupt jump tables

2006-12-16
Author: Zoltan Puskas
Categories: electronics
Tags:

This semester a lot of laboratory exercises and homework has been related to programming microcontrollers, especially the ATmega128 on the MitMot modular development kit, designed by the Department of Measurement and Information Systems at my university, and the ATmega8, which I used in my own digital circuit designs. Since we have to write code in ASM too, not just C, I decided to write the interrupt jump tables for future use, so I don’t have to always open the datasheet and copy it from there.

MitMot modular development kit (image courtesy of BME) BME-MIT MitMot modular development kit [Copyright BME, 2005]

ATmega128 Interrupt table

Full interrupt table based on the ATmega128 datasheet.

;*************************************************
; Reset File for ATmega128
; Interrupt jump table
;*************************************************
        jmp reset               ; reset
        jmp int0                ; external interrupts INT0-INT7
        jmp int1
        jmp int2
        jmp int3
        jmp int4
        jmp int5
        jmp int6
        jmp int7
        jmp timer2_comp         ; timer2 compare match
        jmp timer2_ovf          ; timer2 overflow
        jmp timer1_capt         ; timer1 capture event
        jmp timer1_compa        ; timer1 compare match A
        jmp timer1_compb        ; timer1 compare match B
        jmp timer1_ovf          ; timer1 overflow
        jmp timer0_comp         ; timer0 compare match
        jmp timer0_ovf          ; timer0 overflow
        jmp spi_stc             ; SPI Serial Transfer Complete
        jmp usart0_rx           ; USART0 RX complete
        jmp usart0_udre         ; USART0 Data Register Empty
        jmp usart0_tx           ; USART0 TX complete
        jmp adc_cc              ; ADC Conversion Comlete
        jmp ee_rdy              ; EEPROM ready
        jmp analog_comp         ; Analog comparator
        jmp timer1_compc        ; timer/counter1 compare match c
        jmp timer3_capt         ; timer3 capture event
        jmp timer3_compa        ; timer3 compare match A
        jmp timer3_compb        ; timer3 compare match B
        jmp timer3_compc        ; timer3 compare match C
        jmp timer3_ovf          ; timer3 overflow
        jmp usart1_rx           ; USART1 RX complete
        jmp usart1_udre         ; USART1 Data Register Empty
        jmp usart1_tx           ; USART1 TX complete
        jmp twi                 ; Two Wire Interface
        jmp spm_rdy             ; SPM ready

ATmega8 Interrupt table

Full interrupt table based on the ATmega8 datasheet.

;*************************************************
; Reset File for ATmega8
; Interrupt jump table
;*************************************************
        rjmp reset       ; Reset Handler
        rjmp error       ; IRQ0 Handler
        rjmp error       ; IRQ1 Handler
        rjmp error       ; Timer2 Compare Handler
        rjmp error       ; Timer2 Overflow Handler
        rjmp error       ; Timer1 Capture Handler
        rjmp int_timer1A ; Timer1 CompareA Handler
        rjmp int_timer1B ; Timer1 CompareB Handler
        rjmp error       ; Timer1 Overflow Handler
        rjmp int_timer0  ; Timer0 Overflow Handler
        rjmp error       ; SPI Transfer Complete Handler
        rjmp error       ; USART RX Complete Handler
        rjmp error       ; UDR Empty Handler
        rjmp error       ; USART TX Complete Handler
        rjmp error       ; ADC Conversion Complete Handler
        rjmp error       ; EEPROM Ready Handler
        rjmp error       ; Analog Comparator Handler
        rjmp error       ; Two-wire Serial Interface
        rjmp error       ; Store Program Memory Ready

Note that the ATmega8 microcontroller does not have a jmp instruction.

Usage

Copy the jump table to a file and then include it in the beginning of your code section. The files above simply define tags for the assembler to use, so make sure to write your interrupt handlers. I will usually write the handlers as separate files too, just to make my code more manageable. I used AVR Studio 4.12 to compile my projects.

Example usage:

.include "m8def.inc"

; More initialization, defines, etc.

.CSEG
        .ORG 0x0000

.include "int_jmp_table.asm"    ; Interrupt jump table (must be first!)
.include "reset.asm"            ; uC initialization code (reset: label)
.include "int.asm"              ; Interrupt handler code (rest of the labels)

main:
    ; one off initial code
main_loop:
    ; main busy loop
    wdr
    rjmp main_loop

Content