Sie sind auf Seite 1von 3

What is interrupt ?

An interrupt is an external or internal event that interrupts the microcontroller to inform it


that a device needs its service.

Why we need interrupt?


A single microcontroller can serve several devices by two ways

1. Interrupt-Whenever any device needs its service, the device notifies the
microcontroller by sending it an interrupt signal. Upon receiving an interrupt
signal, the microcontroller interrupts whatever it is doing and serves the device.
The program which is associated with the interrupt is called the interrupt service
routine (ISR) or interrupt handler
2. Polling- The microcontroller continuously monitors the status of a given device.
When the conditions met, it performs the service. After that, it moves on to
monitor the next device until every one is serviced

Advantage of interrupt
The polling method is not efficient, since it wastes much of the microcontroller’s time by
polling devices that do not need service. The advantage of interrupts is that the
microcontroller can serve many devices, Each devices can get the attention of the
microcontroller based on the assigned priority . For the polling method, it is not possible
to assign priority since it checks all devices in a round-robin fashion.

How does interrupt works?

 Whenever any device needs service of microcontroller, the device notifies


the microcontroller by sending it an interrupt signal.
 Upon receiving an interrupt signal, the microcontroller interrupts whatever it is
doing and saves the address of the next instruction (PC) on the stack pointer
(SP).
 It jumps to a fixed location in memory, called the interrupt vector table, that holds
the address of the ISR(interrupt service routine). Each interrupt has its own
ISR. The microcontroller gets the address of the ISR from the interrupt vector
table and jumps to it
 It starts to execute the interrupt service subroutine until it reaches the last
instruction of the subroutine which is RETI (return from interrupt).RETI not used
in C coding.
 Upon executing the RETI instruction, the microcontroller returns to the place
where it was interrupted and First, it gets the program counter (PC) address from
the stack pointer by popping the top two bytes of the stack into the PC
 Then it starts to execute from that address and continue what it executing before.
 This whole process is shown graphically in above pics.

Interrupt vector table


Interrupt vector table shows priority of different interrupts. Upon Reset, all interrupts are
disabled (masked), meaning that none will be responded to by the microcontroller if they
are activated. There are 21 total interrupts in ATmega32 microcontroller.

Vector Program Interrupt name(used in


source Interrupt detail
no address programming)
1 0000 RESET Power on RESET Not programmable
2 0002 INT0 External interrupt 0 INT0_vect
3 0004 INT1 External interrupt 1 INT1_vect
4 0006 INT2 External interrupt 2 INT2_vect
Timer/counter2
5 0008 TIMER2 COMP TIMER2_COMP_vect
compare match
Timer/counter2
6 000A TIMER2 OVF TIMER2_OVF_vect
overflow
Timer/counter1
7 000C TIMER1 CAPT TIMER1_CAPT_vect
capture event
Timer/counter1
8 000E TIMER1 COMPA TIMER1_COMPA_vect
compare match A
Timer/counter1
9 0010 TIMER1 COMPB TIMER1_COMPB_vect
compare match B
Timer/counter1
10 0012 TIMER1 OVF TIMER1_OVF_vect
overflow
Timer/counter0
11 0014 TIMER0 COMP TIMER0_COMP_vect
compare match
Timer/counter0
12 0016 TIMER0 OVF TIMER0_OVF_vect
overflow
Serial transfer
13 0018 SPI, STC SPI_STCvect
complete
14 001A USART, RXC USART, Rx complete USART0_RX_vect
USART, data register
15 001C USART, UDRE USART0_UDRE_vect
empty
16 001E USART, TXC USART, Tx complete USART0_TX_vect
ADC conversion
17 0020 ADC ADC_vect
complete
18 0022 EE_RDY EEPROM ready EE_RDY_vect
19 0024 ANA_COMP Analog comparator ANALOG_COMP_vect
Two wire serial
20 0026 TWI TWI_vect
interface
Stored program
21 0028 SPM_RDY SPM_RDY_vect
memory ready

Das könnte Ihnen auch gefallen