1 / 11

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

Interrupt Handler. 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 ins

lyre
Télécharger la présentation

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


    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

    8. Interrupt Vector Initialization Address Code Comments $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 $009 rjmp 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