2. INTERRUPTS
Interrupts vs. Polling
An interrupt is an external or internal event that interrupts the microcontroller to inform
a microcontroller that a device needs its service
A single microcontroller can serve several devices by two ways
1) Interrupts
• 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
3. Interrupt Method Polling Method
Microcontroller time is used efficiently Microcontroller time is not used
efficiently Ex: JNB TFx, target
Priority can be assigned to the devices Priority cannot be assigned. The devices
are served in round robin fashion
Microcontroller can enable/disable the
interrupts
It is not possible in polling method
Interrupts vs. Polling
4. Six Interrupts in 8051
Six interrupts are allocated as follows
• Reset –power-up reset
• Two interrupts are set aside for the timers: one for timer 0 and one
for timer 1
• Two interrupts are set aside for hardware external interrupts
P3.2 and P3.3 are for the external hardware interrupts INT0 (or
EX1), and INT1 (or EX2)
• Serial communication has a single interrupt that belongs to both
receive and transfer(RI and TI)
5. Interrupt Service Routine
For every interrupt, there must be an interrupt service
routine (ISR), or interrupt handler
• When an interrupt is invoked, the microcontroller runs the
interrupt service routine
• For every interrupt, there is a fixed location in memory that
holds the address of its ISR
• The group of memory locations set aside to hold the
addresses of ISR’s is called interrupt vector table
7. Steps in Executing an Interrupt
Upon activation of an interrupt, the microcontroller goes through the following steps
1.It finishes the instruction it is executing and saves the address of the next instruction (PC) on
the stack
2.It also saves the current status of all the interrupts internally (i.e: not on the stack)
3.It jumps to a fixed location in memory, called the interrupt vector table, that holds the address
of the ISR
4. 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)
5.Upon executing the RETI instruction, the microcontroller returns to the place where it was
interrupted
• First, it gets the program counter (PC) address from the stack by popping the top two bytes of
the stack into the PC
• Then it starts to execute from that address