1 / 12

IKI10230 Pengantar Organisasi Komputer Kuliah no. A7: Bahasa Rakitan AVR Interrupt Handler - PowerPoint PPT Presentation

  • Uploaded on

IKI10230 Pengantar Organisasi Komputer Kuliah no. A7: Bahasa Rakitan AVR Interrupt Handler. Sumber : 1. AVR AT90S8515 Data Sheet. 2. Materi kuliah CS152, th. 1997, UCB. 25 April 2003 Bobby Nazief ([email protected]) Qonita Shahab ([email protected])

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about ' IKI10230 Pengantar Organisasi Komputer Kuliah no. A7: Bahasa Rakitan AVR Interrupt Handler' - emery-kaufman

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

IKI10230Pengantar Organisasi KomputerKuliah no. A7: Bahasa Rakitan AVRInterrupt Handler

Sumber:1. AVR AT90S8515 Data Sheet.2. Materi kuliah CS152, th. 1997, UCB.

25 April 2003

Bobby Nazief ([email protected])Qonita Shahab ([email protected])

bahan kuliah: http://www.cs.ui.ac.id/~iki10230/

Enabling disabling interrupt 1
Enabling/Disabling Interrupt (1)

  • When an interrupt occurs, the Global Interrupt Enable I-bit is cleared (zero) and all interrupts are disabled.The user softwarecan set (one) the I-bit to enable nested interrupts (risky!). The I-bit is set (one) when a Return from Interrupt instruction – RETI- is executed.

  • Instructions: SEI, CLI

Enabling disabling interrupt 2
Enabling/Disabling Interrupt (2)

  • The AT90S4414/8515 has two 8-bit Interrupt Mask control registers:

    • GIMSK - General Interrupt Mask registerto enable/disable external interrupts

    • TIMSK -Timer/Counter Interrupt Mask registerto enable/disable timer/counter interrupt

Remembering interrupt
Remembering Interrupt

  • The AT90S4414/8515 has two 8-bit Interrupt Flag registers:

    • GIFR - General Interrupt Flag registerto remember external interrupts whenever it is being disabled

    • TIFR -Timer/Counter Interrupt Flag registerto remember timer/counter interrupt whenever it is being disabled

When interrupt is set sei
When Interrupt is Set - SEI

  • If the interrupting condition occurs, e.g. a change on the port bit, the processor pushes the actual program counter to the stack

  • After that, processing jumps to the predefined location, the interrupt vector, and executes the instructions there.

    • Usually this is a JUMP instruction to the interrupt service routine somewhere in the code.

    • The interrupt vector is a processor-specific location and depending from the hardware component and the condition that leads to the interrupt

  • The service routine must re-enable this flag after it is done with its job. The service routine can end with the command: RETI

Interrupt vector
Interrupt Vector

Vec No Prg Adr Source Interrupt Definition

1 $000 RESET Hardware Pin, Power-on Reset and

Watchdog Reset

2 $001 INT0 External Interrupt Request 0

3 $002 INT1 External Interrupt Request 1

4 $003 TIMER1 CAPT Timer/Counter1 Capture Event

5 $004 TIMER1 COMPA Timer/Counter1 Compare Match A

6 $005 TIMER1 COMPB Timer/Counter1 Compare Match B

7 $006 TIMER1 OVF Timer/Counter1 Overflow

8 $007 TIMER0, OVF Timer/Counter0 Overflow

9 $008 SPI, STC Serial Transfer Complete

10 $009 UART, RX UART, RX Complete

11 $00A UART, UDRE UART Data Register Empty

12 $00B UART, TX UART, TX Complete

13 $00C ANA_COMP Analog Comparator

Prioritas Tertinggi

Interrupt vector initialization
Interrupt Vector Initialization

Address CodeComments

$000 rjmp RESET ; Reset Handler

$001 rjmp EXT_INT0 ; IRQ0 Handler

$002 rjmp EXT_INT1 ; IRQ1 Handler

$003 rjmp TIM1_CAPT ; Timer1 Capture Handler

$004 rjmp TIM1_COMPA ; Timer1 CompareA Handler

$005 rjmp TIM1_COMPB; Timer1 CompareB Handler

$006 rjmp TIM1_OVF; Timer1 Overflow Handler

$007 rjmp TIM0_OVF; Timer0 Overflow Handler

$008 rjmp SPI_STC; SPI Transfer Complete Handler

$009rjmp UART_RXC ; UART RX Complete Handler

$00a rjmp UART_DRE ; UDR Empty Handler

$00b rjmp UART_TXC ; UART TX Complete Handler

$00c rjmp ANA_COMP ; Analog Comparator Handler

Kerangka program
Kerangka Program

rjmp RESET

rjmp EXT_INT0


;init stack pointer

;init any ports used

;other init


;do things, main loop, etc


;do things


Contoh main program
Contoh: Main Program


.org INT0addr

rjmp ext_int0 ;External interrupt handler

.org OVF0addr

rjmp tim0_ovf ;Timer0 overflow handler


Do some initializations

rcall uart_init ;Init UART

sei ;Enable interrupts


sbrs u_status,RDR ;Wait for Character

rjmp idle

Do the work


sbrc u_status,TD ;Wait until data is sent

rjmp wait

Wrap it up

Contoh interrupt handler
Contoh: Interrupt Handler


ldi u_status,1<<BUSY ;Set busy-flag (clear all others)

Do some work

ldi u_tmp,1<<TOIE0 ;Set bit 1 in u_tmp

out TIFR,u_tmp ; to clear T/C0 overflow flag

out TIMSK,u_tmp ; and enable T/C0 overflow interrupt

Do more work

clr u_bit_cnt ;Clear bit counter

out GIMSK,u_bit_cnt ;Disable external interrupt



sbrs u_status,TD ;if transmit-bit set

Do something

ldi u_tmp,1<<INT0 ;(u_bit_cnt==9):

out GIMSK,u_tmp ;Enable external interrupt

clr u_tmp

out TIMSK,u_tmp ;Disable timer interrupt

cbr u_status,(1<<BUSY)|(1<<TD) ;Clear busy-flag and transmit-flag



  • AVR Assembler User Guide

  • http://www.avr-asm-tutorial.net

  • Contoh program: int-exmp.asm