Microprocessors & Interfacing: Interrupts (II)
Microprocessors & Interfacing: Interrupts (II)
• Interrupts in AVR
Microprocessors & Interfacing – External interrupts
– Internal interrupts
• Timers/Counters
Interrupts (II)
EICRB EIFR
• External Interrupt Control Register B • Interrupt flag register
– For INT4-7 – A bit is set when an event-triggered interrupt is
– Defines the type of signals that activates the enabled and the related event on the related INT
External Interrupt pin happens.
• on rising or falling edge or level sensed. • Event-triggered interrupt: signal edge activated.
Example 2 Example 2
; continued ; continued
.dseg
SecondCounter:
RESET: ldi temp, high(RAMEND) ; Initialize stack pointer
.byte 2 ; Two-byte counter for counting seconds.
TempCounter: out SPH, temp
.byte 2 ; Temporary counter. Used to determine ldi temp, low(RAMEND)
; if one second has passed out SPL, temp
.cseg
.org 0x0000
jmp RESET ser temp ; set Port C as output
jmp DEFAULT ; No handling for IRQ0. out DDRC, temp
jmp DEFAULT ; No handling for IRQ1.
… rjmp main
jmp Timer0OVF ; Jump to the interrupt handler for Timer0 overflow.
… ; continued
jmp DEFAULT ; default service for all other interrupts.
DEFAULT: reti ; no service
; continued
Example 2 Example 2
; continued
; continued
st z, r25 ; Store the value of the second counter. main:
st -z, r24 ldi leds, 0xff
rjmp EndIF out PORTC, leds
NotSecond: ldi leds, PATTERN
st y, r25 ; Store the value of the temporary counter. Clear TempCounter ; Initialize the temporary counter to 0
st -y, r24 Clear SecondCounter ; Initialize the second counter to 0
EndIF: ldi temp, 0b00000010
pop r24 ; Epilogue starts; out TCCR0, temp ; Prescaling value=8
pop r25 ; Restore all conflict registers from the stack. ldi temp, 1<<TOIE0 ; =278 microseconds
pop r28 out TIMSK, temp ; T/C0 interrupt enable
pop r29 sei ; Enable global interrupt
pop temp loop: rjmp loop ; loop forever
out SREG, temp
reti ; Return from the interrupt.
; continued
S2, 2008 COMP9032 Week7 31 S2, 2008 COMP9032 Week7 32
Reading Material Homework
• Chapter 8: Interrupts and Real-Time Events. 1. What do you need to do to set up an Timer0
Microcontrollers and Microcomputers by Output Compare Match Interrupt?
Fredrick M. Cady.
• Mega64 Data Sheet.
– External Interrupts.
– Timer0
Homework
2. Based on the Example 1 in this week lecture
slides, implement a software interrupt such
that when there is an overflow in the counter
that counts the number of LED toggles, all
LEDs are turned on.