The document discusses interrupts in the 8051 microcontroller. It introduces the different types of interrupts including timer interrupts, external hardware interrupts, and serial communication interrupts. It describes how interrupts work, from triggering an interrupt service routine to exiting the routine. Special function registers like the interrupt enable register and interrupt priority register are discussed for configuring and handling interrupts. Examples of interrupt programming in assembly language are provided.
Scaling in conventional MOSFET for constant electric field and constant voltage
Unit 5_interrupt programming_Part 1
1. 1
Prepared By,
Ms. K. D. Patil, Assistant Professor
Department of Information Technology
(NBA accredited)
Sanjivani College of Engineering, Kopargaon-423603.
Maharashtra, India.
(An Autonomous Institute, Affiliated with SPPU, Pune.)
NAAC ‘A’ Grade Accredited, ISO 9001:2015 certified
2. Student will be able to
Introduce Interrupts of 8051 microcontroller
Learn Special Function Registers and their
configurations
Apply knowledge of 8051 assembly language to
write a code for 8051 Interrupt
Prepared By: Ms. K. D. Patil, Dept. of InformationTechnology, Sanjivani COE, Kopargaon 2
3. Part 1
What is Interrupt?
Different Ways 8051 Handles Interrupt
Interrupt Service Routine
Types of Interrupts
InterruptVectorTable
Part 2
Special Function Registers
▪ IE
▪ IP
Interrupt Structure
Example of Interrupt Programming
Prepared By: Ms. K. D. Patil, Dept. of InformationTechnology, Sanjivani COE,
Kopargaon 3
4. An interrupt is an external or internal event
that interrupts the microcontroller to inform
it that a device needs its service
A single microcontroller can serve several
devices by two ways
Interrupts
Polling
Prepared By: Ms. K. D. Patil, Dept. of Information Technology,Sanjivani COE, Kopargaon 4
5. Interrupts
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 serves the device
The program which is associated with the
interrupt is called the interrupt service routine
(ISR) or interrupt handler
Prepared By: Ms. K. D. Patil, Dept. of Information Technology,Sanjivani COE, Kopargaon 5
6. Advantages of Interrupts method
Microcontroller can serve many devices (at a
time one)
Each devices can get the attention of the
microcontroller based on the assigned priority
The microcontroller can also ignore (mask) a
device request for service
Prepared By: Ms. K. D. Patil, Dept. of Information Technology,Sanjivani COE, Kopargaon 6
7. Polling
Another method of Interrupt handling in 8051 is Polling
The microcontroller continuously monitors the status of a given device
When the conditions met, it performs the service
After that, microcontroller moves on to monitor the next device until
every one is serviced
Polling can monitor the status of several devices and serve each of
them as certain conditions are met
Disadvantages
The polling method is not efficient, since it wastes much of the
microcontroller’s time by polling devices that do not need service
It checks all the devices in Round Robin fashion and does not change
priority
example. JNB TF, target
Prepared By: Ms. K. D. Patil, Dept. of Information Technology,Sanjivani COE, Kopargaon 7
8. For every interrupt, there must be an Interrupt
Service Routine (ISR), or Interrupt Handler
ISR is a small program or subroutine that 8051
executes to handle the interrupt
When an interrupt is invoked, microcontroller runs
the ISR
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 ISRs is called interrupt vector
table
Prepared By: Ms. K. D. Patil, Dept. of InformationTechnology, Sanjivani COE,
Kopargaon 8
9. When microcontroller sense some Interrupt it
goes through the following steps to handle that
interrupt
Step 1: Microcontroller finishes the instruction it
is executing and saves the address of the next
instruction (PC) on the stack
Step 2: It saves the current status of all the
interrupts internally (not on the stack)
Step 3: It jumps to a fixed location in memory,
called the interrupt vector table (IVT), that holds
the address of the ISR
Prepared By: Ms. K. D. Patil, Dept. of InformationTechnology, Sanjivani COE,
Kopargaon 9
10. Step 4 : The microcontroller gets the address of the
ISR from the interrupt vector table and jumps to it
It starts to execute the ISR until it reaches the last
instruction of the subroutine which is RETI (return
from interrupt)
Step 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
Prepared By: Ms. K. D. Patil, Dept. of InformationTechnology, Sanjivani COE,
Kopargaon 10
11. There are a total of 6 interrupts available in
8051
1. Reset
2.Timer 0 Interrupt (TF0)
3.Timer 1 Interrupt (TF1)
4. External Hardware Interrupt 0 (INT0)
5. External Hardware Interrupt 1 (INT1)
6. Serial com Interrupt (RI andTI)
Prepared By: Ms. K. D. Patil, Dept. of InformationTechnology, Sanjivani COE,
Kopargaon 11
12. This is power up reset
When the reset pin is activated, 8051 jumps to
the address 0000H
Prepared By: Ms. K. D. Patil, Dept. of InformationTechnology, Sanjivani COE,
Kopargaon 12
13. Two interrupts are set aside for the timers:
one for timer 0 and
another for timer 1
Memory locations 000BH and 001BH in the
InterruptVectorTable belongs toTimer 0 and
Timer 1 respectively
In polling, we have to monitorTF (Timer Overflow
Flag) with the instruction
“JNBTF,Target”
We have to wait untilTF is raised, and
microcontroller cannot do anything else
Prepared By: Ms. K. D. Patil, Dept. of InformationTechnology, Sanjivani COE,
Kopargaon 13
14. 1 000B H
Prepared By: Ms. K. D. Patil, Dept. of InformationTechnology, Sanjivani COE,
Kopargaon 14
TF0
Jumps to
Timer 0 InterruptVector
1 001B H
TF1
Jumps to
Timer 1 InterruptVector
15. If theTimer Interrupt in IE (Interrupt Enable) is
enabled, whenever the timer rolls over,TF
raised and the microcontroller is interrupted
in whatever it is doing, and jumps to IVT to
service the ISR
In this way microcontroller can do other
things until it is notified that timer is rolled
over
Prepared By: Ms. K. D. Patil, Dept. of InformationTechnology, Sanjivani COE,
Kopargaon 15
16. The 8051 has two external hardware interrupts
Pin 12 (P3.2) and pin 13 (P3.3) of the 8051, designated
as INTO and INT1, are used as external hardware
interrupts.
These interrupts are referred as EX0 and EX1
respectively
Upon activation of these pins, the 8051 gets
interrupted in whatever it is doing and jumps to the
vector table to perform the interrupt service routine
Memory Locations 0003H and 0013H in the IVT are
assigned to INT0 and INT1 respectively
These interrupts are enabled or disabled using IE
register
Prepared By: Ms. K. D. Patil, Dept. of InformationTechnology, Sanjivani COE,
Kopargaon 16
17. Activation of INT0 and INT1 interrupts
There are two ways of activation of External
Hardware Interrupt
▪ LevelTriggered
▪ EdgeTriggered
Prepared By: Ms. K. D. Patil, Dept. of InformationTechnology, Sanjivani COE,
Kopargaon 17
18. Level Triggered interrupts
INTO and INT1 pins are normally high (just like all I/O port
pins)
Interrupt 1 type control bit (TCON.0) / Interrupt 1 type control
bit (TCON.2)ofTCON register goes high after 8051 sense such
type of interrupt
if a low-level signal is applied to them, it triggers the interrupt.
Then the microcontroller stops whatever it is doing and jumps
to the interrupt vector table to service that interrupt.
This is called a level-triggered or level-activated
interrupt and is the default mode upon reset of the 8051.
Prepared By: Ms. K. D. Patil, Dept. of InformationTechnology, Sanjivani COE,
Kopargaon 18
19. if the low-level interrupt signal is not removed before the ISR
is finished it is interpreted as another interrupt and the 8051
jumps to the vector table to execute the ISR again.
EdgeTriggered interrupts
Upon reset the 8051 makes INTO and INT1 low-level triggered
interrupts.
To make them edge-triggered interrupts, we must program
the IE0 (TCON.1) External Interrupt 0 Flag and IE1 (TCON.3)
External Interrupt 1 Flag bits of theTCON register.
Prepared By: Ms. K. D. Patil, Dept. of InformationTechnology, Sanjivani COE,
Kopargaon 19
20. Serial communication has a single interrupt that
belongs to both receive and transfer
The interruptVectorTable Location 0023H belongs to
this interrupt
Used to both send and receive data
If the interrupt bit in IE is enabled, when RI andTI is
raised, 8051 gets interrupted and jumps to memory
location 0023H to execute ISR
Prepared By: Ms. K. D. Patil, Dept. of InformationTechnology, Sanjivani COE,
Kopargaon 20
21. TI (Transfer Interrupt) is raised when the last
bit of the framed data, stop bit is transferred
indicating that the SBUF register is ready to
transfer next byte
RI (Receive Interrupt) is raised when the
received byte needs to be picked up before it
is lost by new incoming serial data
Prepared By: Ms. K. D. Patil, Dept. of InformationTechnology, Sanjivani COE,
Kopargaon 21
22. Prepared By: Ms. K. D. Patil, Dept. of InformationTechnology, Sanjivani COE,
Kopargaon 22
23. Interrupts ROM
Location
(HEX)
Pin Flag
Clearing
Reset 0000 9 Auto
External Hardware Interrupt 0
(INT0)
0003 P3.2 (12) Auto
Timer 0 Interrupt (TF0) 000B Auto
External Hardware Interrupt 1
(INT1)
0013 P3.3 (13) Auto
Timer 1 Interrupt (TF1) 001B Auto
Serial com Interrupt (RI and
TI)
0023 Programmer
Clears it
Prepared By: Ms. K. D. Patil, Dept. of InformationTechnology, Sanjivani COE,
Kopargaon 23
24. Interrupts Flag SFR Register
Bit
External Hardware Interrupt 0 IE0 TCON.1
Timer 0 Interrupt TF0 TCON.5
External Hardware Interrupt 1 IE1 TCON.3
Timer 1 Interrupt TF1 TCON.7
Serial com Interrupt TI SCON.1
Timer 2 Interrupt TF2 T2CON.7
(AT89C52)
Timer 2 Interrupt EXF2 T2CON.6
(AT89C52)
Prepared By: Ms. K. D. Patil, Dept. of InformationTechnology, Sanjivani COE,
Kopargaon 24
25. “The 8051 Microcontroller and Embedded
Systems usingAssembly and C” , Muhammad
Ali Mazidi, Janice Gillispie Mazidi, Rolin D.
McKinlay, Second Edition, Pearson
publication
http://what-when-how.com/8051-
microcontroller/programming-external-
hardware-interrupts/
Prepared By: Ms. K. D. Patil, Dept. of InformationTechnology, Sanjivani COE,
Kopargaon 25
26. Prepared By: Ms. K. D. Patil, Dept. of InformationTechnology, Sanjivani COE,
Kopargaon 26