Lec-18 EE-222
Lec-18 EE-222
SYSTEMS
EE-222
AVR Interrupts
Interrupt vs Polling
I/O SERVICES
• Polling • Interrupt
{ {
//do something; }
}
whenever PIND.2 is 0 then
do something
POLLING METHOD
NO
If TOV2
YES
Handle TOV2
INTERRUPT METHOD
Peripherals
Timers
IRQ0
CPU IRQ1 I/Os
Interrupt IRQ2
Controller IRQ3 USART
….
IRQn
SPI
THE ADVANTAGE OF
INTERRUPTS
• Each device can get service based on the priority assigned to it.
PROGRAM
ROM
Program
Bus Bus
CPU
SREG
EIMSK
PCICR
PCMSK0
PCMSK1 Other
OSC PCMSK2 Ports
Peripherals
Interrupt Unit
TIMSK0
TIMSK1
TIMSK2
I/O
PINS
Steps in Executing an Interrupt
REVIEW OF C ALL A SUBROUTINE
ROM addr.
0000
ROM addr. DELAY
0300 OUT DDRB,0FFH;
2. It jumps to a fixed location in memory based on the interrupt vector table. [see
couple of slides down]
3. The microcontroller gets the address of the ISR from the interrupt vector table
and jumps to it.
TOV0 0000
.... Reserved
1 0012 ISR of timer0 for
jumps to .... Interrupt
....
0028
main program
....
THE ADDRESSES OF ISRS
• The group of memory locations set aside to hold the addresses of ISRs is called
the interrupt vector table.
• Normally, the ISR for an interrupt is too long to fit into the memory space
allocated inside the interrupt vector table.
• For that reason, a JMP instruction is placed in the vector table to point to
the address of the ISR.
How to Enable and Disable an Interrupt?
ENABLE/DISABLE INTERRUPTS
IE register
External
Interrupt 0
Timer/
Counter 0
External
Interrupt 1
Timer/ I–
CPU
Counter 1 [Gloable
Inettrupt
Serial Enable]
Port
Timer/
Counter 2
GLOBAL INTERRUPT ENABLE