1 / 12

IKI10230 Pengantar Organisasi Komputer Kuliah no. A7: Bahasa Rakitan AVR Interrupt Handler

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 (nazief@cs.ui.ac.id) Qonita Shahab (niet@cs.ui.ac.id)

Download Presentation

IKI10230 Pengantar Organisasi Komputer Kuliah no. A7: Bahasa Rakitan AVR Interrupt Handler

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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 (nazief@cs.ui.ac.id)Qonita Shahab (niet@cs.ui.ac.id) bahan kuliah: http://www.cs.ui.ac.id/~iki10230/

  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 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

  4. 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

  5. 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

  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 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

  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 rjmp ext_int0 ;External interrupt handler .org OVF0addr rjmp tim0_ovf ;Timer0 overflow handler main: Do some initializations rcall uart_init ;Init UART sei ;Enable interrupts idle: sbrs u_status,RDR ;Wait for Character rjmp idle Do the work wait: sbrc u_status,TD ;Wait until data is sent rjmp wait Wrap it up

  11. Contoh: Interrupt Handler ext_int0: 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 reti tim0_ovf: 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 reti

  12. Referensi • AVR Assembler User Guide • http://www.avr-asm-tutorial.net • Contoh program: int-exmp.asm

More Related