1 IKI10230 Pengantar Organisasi Komputer Kuliah no. A7: Bahasa Rakitan AVR Interrupt Handler 25 April 2003 Bobby Nazief Qonita Shahab bahan kuliah: Sumber: 1. AVR AT90S8515 Data Sheet. 2. Materi kuliah CS152, th. 1997, UCB.
2 Interrupt Handler
3 Enabling/Disabling Interrupt (1) °When an interrupt occurs, the Global Interrupt Enable I- bit is cleared (zero) and all interrupts are disabled. The user software can 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
4 Enabling/Disabling Interrupt (2) °The AT90S4414/8515 has two 8-bit Interrupt Mask control registers: GIMSK - General Interrupt Mask register to enable/disable external interrupts TIMSK - Timer/Counter Interrupt Mask register to enable/disable timer/counter interrupt
5 Remembering Interrupt °The AT90S4414/8515 has two 8-bit Interrupt Flag registers: GIFR - General Interrupt Flag register to remember external interrupts whenever it is being disabled TIFR - Timer/Counter Interrupt Flag register to remember timer/counter interrupt whenever it is being disabled
6 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
7 Interrupt Vector Vec NoPrg AdrSourceInterrupt 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 TIMER1CAPT Timer/Counter1 Capture Event 5 $004 TIMER1COMPATimer/Counter1 Compare Match A 6 $005 TIMER1COMPB Timer/Counter1 Compare Match B 7 $006 TIMER1OVF Timer/Counter1 Overflow 8 $007 TIMER0,OVF Timer/Counter0 Overflow 9$008SPI, STCSerial 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
8 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
9 Kerangka Program rjmp RESET rjmp EXT_INT0 RESET: ;init stack pointer ;init any ports used ;other init sei ;do things, main loop, etc EXT_INT0: ;do things reti
10 Contoh: Main Program.cseg.org INT0addr rjmpext_int0;External interrupt handler.org OVF0addr rjmptim0_ovf;Timer0 overflow handler main: Do some initializations rcalluart_init;Init UART sei;Enable interrupts idle: sbrsu_status,RDR;Wait for Character rjmpidle Do the work wait: sbrcu_status,TD;Wait until data is sent rjmpwait Wrap it up
11 Contoh: Interrupt Handler ext_int0: ldiu_status,1<<BUSY;Set busy-flag (clear all others) Do some work ldiu_tmp,1<<TOIE0;Set bit 1 in u_tmp outTIFR,u_tmp; to clear T/C0 overflow flag outTIMSK,u_tmp; and enable T/C0 overflow interrupt Do more work clru_bit_cnt;Clear bit counter outGIMSK,u_bit_cnt;Disable external interrupt reti tim0_ovf: sbrsu_status,TD;if transmit-bit set Do something ldiu_tmp,1<<INT0;(u_bit_cnt==9): outGIMSK,u_tmp;Enable external interrupt clru_tmp outTIMSK,u_tmp;Disable timer interrupt cbru_status,(1<<BUSY)|(1<<TD) ;Clear busy-flag and transmit-flag reti
12 Referensi °AVR Assembler User Guide ° °Contoh program: int-exmp.asm