SlideShare a Scribd company logo
Interrupts of 8051 Microcontroller
Dr. Nilesh Bhaskarrao Bahadure
https://www.sites.google.com/site/nileshbbahadure/home
July 25, 2021
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 1 / 54
Overview I
1 What is Interrupt
Introduction to 8051 Microcontroller Interrupts
2 Interrupts of 8051 Microcontroller
3 Interrupt Vs Polling
4 IE register
5 IP register
6 What happens when an interrupt occurs?
7 What happens when an interrupt Ends?
8 Programming Timer Interrupt
9 Serial Interrupt
10 External Hardware Interrupt
Level Triggered Interrupt
Edge Triggered Interrupt
TCON Register
11 Examples
Example - 1: Example on IE
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 2 / 54
Overview II
Example - 2: Example on IP
Example - 3: Example on IP
Example - 4: Generation of Square Wave Using Timer 0 Mode 2
Example - 5: Generation of Square Wave Using Timer 0 Mode 1
Example - 6: Generation of Square Wave of 50 Hz Using Timer 0
Example - 7: Transmission of bits serially using Interrupt
Example - 8: Reception of bits serially using Interrupt
Example - 9: LED ON using External Hardware Interrupt
Example - 10: LED ON using External Hardware Interrupt and Pulse
generator
Example - 11: Transfer - Receive & Square Wave using Interrupt
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 3 / 54
What is Interrupt
Interrupt is the routine program to break or stop the current execution and
branch to another program. Interrupt of microcontroller 8051 consists two
hardware interrupts as well as generated interrupts using timers and serial
communication.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 4 / 54
Introduction to 8051 Microcontroller Interrupts
Interrupts are signals that cause the Microcontroller to suspend what is doing
and transfer to a special program called an interrupt handler. The interrupt
handler is responsible for determining the cause of interrupt, servicing the
interrupt and returning the control to the point from where the interrupt
was caused.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 5 / 54
Introduction to 8051 Microcontroller Interrupts...
When Microcontroller executes any program then it is called Main pro-
gram. In between the main program, Microcontroller is interrupted then
Microcontroller will branch from main program to subprogram this subpro-
gram is called Interrupt service routine (ISR). After executing this ISR then
RETI/RET instruction comes then Microcontroller returns back from ISR
to the main program from where Microcontroller has left.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 6 / 54
Interrupts of 8051 Microcontroller
Question
What events can trigger interrupts, and where do they go?
We can configure the 8051 so that any of the following events will cause
an interrupt:
1 Timer 0 Overflow.
2 Timer 1 Overflow.
3 Reception/Transmission of Serial Character.
4 External Event 0.
5 External Event 1.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 7 / 54
Interrupts of 8051 Microcontroller...
The six interrupts in the 8051 are allocated as follows:
1 RESET: When the reset pin is activated, the Microcontroller 8051
jumps to the address location 0000h. This is also referred as power
on reset.
2 Timers: Two interrupts are set aside for the timers: Timer 0 and
Timer 1. Memory location addresses 000Bh and 001Bh in the
interrupt vector table belongs to timer 0 and timer 1, respectively.
3 Hardware external interrupts: Two interrupts are set aside for
hardware external interrupts. Pin number 12 (P3.2) and 13 (P3.3)
are for the external hardware interrupts also referred as EX 1 and EX
2. Memory location addresses 0003h and 0013h in the interrupt
vector table are assigned to INT0 and INT1 external hardware
interrupts respectively.
4 Serial communication: serial communication has a single interrupt
that belongs to both transmit and receive. The interrupt vector table
location 0023h belongs to the serial communication interrupt.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 8 / 54
Interrupts of 8051 Microcontroller...
Table : Interrupts with their handler addresses
Interrupt Flag Interrupt handler address/Vector location
External 0 IE0 0003h
Timer 0 TF0 000Bh
External 1 IE1 0013h
Timer 1 TF1 001Bh
Serial RI/TI 0023h
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 9 / 54
Interrupt Vs Polling
A single Microcontroller can serve several devices. There are two ways to
do that: Interrupts and polling.
Interrupts:
In the interrupt method, whenever any device needs its service, the device
notifies the Microcontroller by sending an interrupt signal, upon receiving
an interrupt signal, the Microcontroller interrupts whatever it is doing and
serve the device. The program associated with the interrupt is called the
interrupt service routine (ISR) or interrupt handler.
Polling:
In polling, the Microcontroller continuously monitors the status of a several
devices, when the status condition is met, it perform the service, after that,
it moves on to monitor the next device until each one is serviced. Although
polling can monitors the status of several devices and serve each of them as
certain conditions are met, it is not an efficient use of Microcontroller.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 10 / 54
Interrupt Vs Polling...
Figure : Polling method to access several devices
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 11 / 54
Interrupt Vs Polling...
The advantage of the interrupts is that the Microcontroller can serve many
devices, not all at the same time; each device can get the attention of the
Microcontroller, based on the priority assigned to it. The polling method
cannot assign priority since it checks all the devices in a round robin fashion
as shown in the figure 1. Also in the interrupt method, the Microcontroller
can also ignore or mask or reset a device request for service. This is not
possible in polling.
The most important reason that the interrupt method is preferable over
the polling is that the polling method waste the time of Microcontroller in
order to search the devices one by one, so in order to avoid tying down the
Microcontroller, interrupts are used.
For example, the instruction LABEL: JNB TFx, LABEL, waited until the
timer rollover and while we were waiting we could not do anything else
i.e. a waste of this Microcontroller’s time that could have been used to
perform some other useful tasks. In this case, the Microcontroller can go
about doing other tasks, and when the timer flag bit is raised, the timer will
interrupt the Microcontroller in whatever it is doing.
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 12 / 54
IE register
D7 D6 D5 D4 D3 D2 D1 D0
EA – – ES ET1 EX1 ET0 EX0
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 13 / 54
IE register...
Table : Explanation of function of IE register
Bit Name Bit address Function
7 EA AFh Global Interrupt Enable / Disable
6 – AEh Undefined (don’t care)
5 – ADh Undefined (don’t care)
4 ES ACh Enable serial communication interrupt
3 ET1 ABh Enable timer 1 interrupt
2 EX1 AAh Enable external 1 hardware interrupt
1 ET0 A9h Enable timer 0 interrupt
0 EX0 A8h Enable external 0 hardware interrupt
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 14 / 54
IE register...
The schematic representations of the interrupt are as follows:
Figure : Interrupt structure of 8051 Microcontroller
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 15 / 54
IP register
D7 D6 D5 D4 D3 D2 D1 D0
– – PT2 PS PT1 PX1 PT0 PX0
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 16 / 54
IP Register...
Table : Explanation of function of IP register
Bit Name Bit address Function
7 – BFh Undefined (don’t care)
6 – BEh Undefined (don’t care)
5 PT2 BDh Timer 2 interrupt priority (8052 only)
4 PS BCh Serial communication interrupt priority
3 PT1 BBh External 1 hardware interrupt priority
2 PX1 BAh Timer 1 interrupt priority
1 PT0 B9h External 0 hardware interrupt priority
0 PX0 B8h Timer 0 interrupt priority
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 17 / 54
What happens when an interrupt occurs?
When an interrupt is triggered, the following actions are taken
automatically by the Microcontroller:
1 The current Program Counter is saved on the stack, low-byte first.
2 Interrupts of the same and lower priority are blocked.
3 In the case of Timer and External interrupts, the corresponding
interrupt flag is set.
4 Program execution transfers to the corresponding interrupt handler
vector address.
5 The Interrupt Handler Routine executes.
Take special note of the third step: If the interrupt being handled is a
Timer or External interrupt, the Microcontroller automatically clears the
interrupt flag before passing control to your interrupt handler routine.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 18 / 54
What happens when an interrupt Ends?
An interrupt ends when your program executes the RETI instruction.
When the RETI instruction is executed the following actions are taken by
the Microcontroller::
1 Two bytes are popped off the stack into the Program Counter to
restore normal program execution.
2 Interrupt status is restored to its pre-interrupt status.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 19 / 54
Programming Timer Interrupt
Figure : Timer 0 and Timer 1 interrupt invoked by TF0 and TF1
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 20 / 54
Programming Timer Interrupt...
We know that timer flag is raised when the timer rolls over i.e. overflows
and the overflow condition are checked by monitoring TF bit using the in-
struction “JNB TFx, Label”. In polling method, we have to wait until the
timer flag bit TF is raised. The problem with this method is that the Micro-
controller is tied down while waiting for TF flag bit to be raised and cannot
do anything else. Using interrupts this problem getting solve and avoids
tied down the Microcontroller. If the timer interrupt in IE (Interrupt
enable) register is enabled, whenever the timer rolls over, timer flag TF
bit is raised automatically and Microcontroller is interrupted in whatever
it is doing, and jump to the interrupt vector table to service the interrupt
service routine (ISR) of the timer. In this way the Microcontroller can do
other things until it is notified that the timer has rolled over. Whenever the
timer flag bit is raised and if the corresponding bit of the timer interrupt flag
bit is set in the IE register, Microcontroller automatically switch or jump
to the vector location of timers.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 21 / 54
Serial Interrupt of Microcontroller 8051
The working of Serial Interrupts is slightly different than the rest of the
interrupts. This is due to the fact that there are two interrupt flags: RI
and TI and only one interrupt flag bit is associated for both. If either flag
is set, a serial interrupt is triggered. As you will recall from the previous
section on the serial port, the RI bit is set when a byte is received by the
serial port and the TI bit is set when a byte has been sent. This means that
when your serial interrupt is executed, it may have been triggered because
the RI flag was set or because the TI flag was set or because both flags were
set. Thus, your routine must check the status of these flags to determine
what action is appropriate. Also, since the 8051 does not automatically
clear the RI and TI flags you must clear these bits in your interrupt handler.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 22 / 54
Serial Interrupt of Microcontroller 8051...
INT SERIAL: JNB RI, CHECK TI ; If the RI flag is not set, we jump to check TI
MOV A, SBUF ; If we got to this line, it’s because the RI bit was set
CLR RI ; Clear the RI bit after we’ve processed it
CHECK TI: JNB TI, EXIT INT ; If the TI flag is not set, we jump to the exit point
CLR TI ; Clear the TI bit before we send another character
MOV SBUF, #’A’ ; Send another character to the serial port
EXIT INT: RETI
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 23 / 54
Programming External Hardware Interrupt
There are only two external hardware interrupts in the 8051 Microcontroller:
INT0 and INT1. They are located on pin P3.2 and P3.3 of port 3
respectively. The interrupt vector table locations 0003h and 0013h are set
aside for INT0 and INT1 respectively. They are enabled and disabled using
IE register. There are two types of activation for the external hardware
interrupts, they are
1. Level triggered
2. Edge triggered
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 24 / 54
Programming External Hardware Interrupt...
Figure : Level & Edge triggered for INT0 and INT1
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 25 / 54
Level Triggered Interrupt
In the level triggered mode, INT0 and INT1 pins are normally high and if
a low level signal (as they are low level active pins) is applied to them, it
triggers the interrupt. Upon receiving the interrupt signal, Microcontroller
stops whatever it is doing and jumps to the interrupt vector table to service
the interrupt. This is called level triggered or level activated interrupt and is
the default mode of activation upon reset of the 8051. The low level signal
at the 8051 pin must be removed before the execution of the last instruction
of interrupt service routine i.e. RETI, otherwise, another interrupt will be
generated.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 26 / 54
Edge Triggered Interrupt
Upon reset the 8051 makes INT0 and INT1 low level triggered interrupts.
To make them edge triggered interrupts, we must program the bits of the
TCON register. The TCON register consists of IT0 and IT1 flag bits that
determine level or edge triggered mode of the hardware interrupts. IT0 and
IT1 are bits D0 and D2 of the TCON register respectively. Since TCON
is a bit addressable register, these bits are also referred as TCON.0 and
TCON.2. Upon reset TCON.0 and TCON.2 are both 0s i.e. external hard-
ware interrupts of INT0 and INT1 pins are low level triggered. By making
TCON.0 and TCON.2 bits high with instruction such as SETB TCON.0 and
SETB TCON.2 the external hardware interrupts INT0 and INT1 becomes
edge triggered interrupts. For example by applying High to Low pulse on
INT1 pin, then INT1 hardware interrupt becomes edge triggered hardware
interrupts.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 27 / 54
TCON SFR
D7 D6 D5 D4 D3 D2 D1 D0
TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 28 / 54
TCON SFR...
Bits Name Function
3 IE1 External hardware interrupts 1 edge flag. Set by CPU when the ex-
ternal interrupt edge (High to Low transition) is detected. Cleared
by CPU when the interrupt is processed
2 IT1 Interrupt 1 type control bit. Set/Cleared by software to specify
falling edge (Edge triggered)/Level triggered external interrupts.
1 IE0 External hardware interrupts 0 edge flag. Set by CPU when the ex-
ternal interrupt edge (High to Low transition) is detected. Cleared
by CPU when the interrupt is processed
0 IT0 Interrupt 0 type control bit. Set/Cleared by software to specify
falling edge (Edge triggered) / Level triggered external interrupts.
(IT0 = 0, then low level triggered mode is set
IT0 = 1, then edge triggered mode is set)
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 29 / 54
Example - 1
Show the instruction to
(a) Enable serial interrupt, timer 0 interrupt and hardware external
interrupt 0.
(b) Disable timer 0 interrupt
(c) Show how to disable all the interrupts with a single instruction.
Solution
EA – ET2 ES ET1 EX1 ET0 EX0
1 0 0 1 0 0 0 1 93h
IE = 93h
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 30 / 54
Assembly Language Program
(a)
MOV IE, #93H
Since IE register is a bit addressable register, we can use the following
instructions to access individual bits of register
SETB IE.7 ; EA = 1, global enable
SETB IE.4 ; enable serial interrupt
SETB IE.1 ; enable timer 0 interrupt
SETB IE.0 ; enable external hardware interrupt 0
(b)
CLR IE.1 ; disable timer 0 interrupt only
(c)
CLR IE.7 ; disable all interrupts
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 31 / 54
Example - 2
Program the interrupt priority (IP) register to perform the following
(a) Assign the highest priority to timer 0 and show the new priority order
(b) Discuss what happen if external hardware interrupts 0 and timer 0
interrupt are set at the same time.
Solution
– – PT2 PS PT1 PX1 PT0 PX0
0 0 0 0 0 0 1 0 02h
IP = 02h
(a) MOV IP, 02H
Or
SETB IP.2
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 32 / 54
Solution
(a)
Old priority order New priority order
External hardware interrupt 0 (INT0) Timer 0 interrupt (TF0)
Timer 0 interrupt (TF0) External hardware interrupt 0 (INT0)
External hardware interrupt 1 (INT1) External hardware interrupt 1 (INT1)
Timer 1 interrupt (TF1) Timer 1 interrupt (TF1)
Serial communication interrupt (RI/TI) Serial communication interrupt (RI/TI)
(b) Timer 0 is assigned the highest priority so the order of the interrupts
are
New priority order
Timer 0 interrupt (TF0)
External hardware interrupt 0 (INT0)
External hardware interrupt 1 (INT1)
Timer 1 interrupt (TF1)
Serial communication interrupt (RI/TI)
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 33 / 54
Example - 3
Assume that after reset, the IP register is program with the instruction
MOV IP, #0Bh. Discuss the sequence in which the interrupts are serviced.
Solution
– – PT2 PS PT1 PX1 PT0 PX0
0 0 0 0 1 0 1 1 0Bh
IP = 0Bh
This instruction sets external hardware interrupt 0 (INT0), timer 0 (TF0)
and timer 1 (TF1) to the higher priority level compared with rest of the
interrupts. So according to program bits old and new priority level of the
interrupts are shown below
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 34 / 54
Solution
Old priority order New priority order
External hardware interrupt 0 (INT0) External hardware interrupt 0 (INT0)
Timer 0 interrupt (TF0) Timer 0 interrupt (TF0)
External hardware interrupt 1 (INT1) Timer 1 interrupt (TF1)
Timer 1 interrupt (TF1) External hardware interrupt 1 (INT1)
Serial communication interrupt (RI/TI) Serial communication interrupt (RI/TI)
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 35 / 54
Example - 4
Write an assembly language program that continuously gets 8 - bit data
from port P0 and send to port P1 while simultaneously creating a square
wave of 250 µS period on port pin P2.1. Use timer 0 in mode 2 to create
the square wave, assume that crystal frequency of 8051 is 11.0592 MHz.
Solution
Step - I: Calculation of count value in TH0 Register
TON = TOFF = 125µs
TH0 = 8Dh
Step - II: Calculation of TMOD Register
TMOD = 02h
Step - III: Calculation of IE Register
IE = 82h
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 36 / 54
Assembly Language Program
ORG 0000H
SJMP MAIN ; bypass vector location
ORG 0030H
MAIN: MOV P0, #0FFH ; make port P0 as an input port
MOV TMOD, #02H ; Timer 0 in mode 2
MOV TH0, #8DH ; load TH0 with auto - reload value
MOV IE, #82H ; enable timer 0
SETB TR0 ; start timer 0
BACK: MOV A, P0 ; get data from port P0 until TF0 raised
MOV P1, A ; send data from P0 to port P1
SJMP BACK ; repeat the process
ORG 000BH
CPL P2.1 ; interrupt routine of timer 0
CLR TF0
RETI ; return from interrupt
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 37 / 54
Example - 5
Repeat example 4 using timer 0 in mode 1.
Solution
Step - I: Calculation of count value in TH0 - TL0 Register
TON = TOFF = 125µs
TH0 = 8Dh
TL0 = FFh
Step - II: Calculation of TMOD Register
TMOD = 01h
Step - III: Calculation of IE Register
IE = 82h
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 38 / 54
Assembly Language Program
ORG 0000H
SJMP MAIN ; bypass vector location
ORG 0030H
MAIN: MOV P0, #0FFH ; make port P0 as an input port
MOV TMOD, #01H ; Timer 0 in mode 1
MOV TH0, #0FFH ; Load timer 0 higher byte
MOV TL0, #8DH ; load timer 0 lower byte
MOV IE, #82H ; enable timer 0
SETB TR0 ; start timer 0
BACK: MOV A, P0 ; get data from port P0 until TF0 raised
MOV P1, A ; send data from P0 to port P1
SJMP BACK ; repeat the process
ORG 000BH
CPL P2.1 ; interrupt routine of timer 0
MOV TH0, #0FFH
MOV TL0, #0A4H
CLR TR0
CLR TF0
RETI ; return from interrupt
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 39 / 54
Example - 6
Write an assembly language program to generate square wave of 50 Hz
frequency on port pin P1.2 using interrupt for timer 0. Assume crystal
frequency of 8051 is 11.0592 MHz.
Solution
Step - I: Calculation of count value in TH0 - TL0 Register
TON = TOFF = 0.01s
TH0 = DCh
TL0 = 00h
Step - II: Calculation of TMOD Register
TMOD = 01h
Step - III: Calculation of IE Register
IE = 82h
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 40 / 54
Assembly Language Program
ORG 0000H
SJMP MAIN ; bypass vector location
ORG 0030H
MAIN: MOV TMOD, #01H ; Timer 0 in mode 1
MOV TH0, #0DCH ; Load timer 0 higher byte
MOV TL0, #00H ; load timer 0 lower byte
MOV IE, #82H ; enable timer 0
SETB TR0 ; start timer 0
BACK: SJMP BACK ; repeat the process
ORG 000BH
CPL P2.1 ; interrupt routine of timer 0
MOV TH0, #0DCH
MOV TL0, #00H
CLR TR0
CLR TF0
RETI ; return from interrupt
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 41 / 54
Example - 7
Write an assembly language program to get data from port P1 and sends
to port P2 continuously, while giving a copy to the serial port to be
transferred serially. Assume that crystal frequency of 8051 is 11.0592 MHz
and baud rate for the serial communication is 9600.
Solution
Step - I: Calculation of SCON Register
SCON = 50h
Step - II: Calculation of TMOD Register (Timer 1 in Mode 2
for Baud Rate)
TMOD = 20h
Step - III: Calculation of TH1 Register for Baud Rate
TH1 = FDh
Step - IV: Calculation of IE Register
IE = 90h
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 42 / 54
Assembly Language Program
ORG 0000H
SJMP MAIN
ORG 0030H
MAIN: MOV P1, #0FFH ; make port P1 as an input port
MOV TMOD, #20H ; timer 1 in mode 2 for baud rate
MOV TH1, #0FDH ; to set baud rate 9600
MOV SCON, #50H ; serial mode 1
MOV IE, #90H ; enable serial communication interrupt
SETB TR1 ; start timer 1 for baud rate
L1: MOV A, P1 ; get data from port P1
MOV SBUF, A ; send data serially
MOV P2, A ; send data to the port P2
SJMP L1 ; repeat process
ORG 0023H
JB TI, TRANS ; check for TI flag bit
CLR RI
RETI
TRANS: CLR TI
RETI
END
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 43 / 54
Example - 8
Write an assembly language program to get data from port P1 and send it
to the port P2 continuously, while sending; receive data from serial port
and transfer to port P0. Assume that crystal frequency of 8051 is 11.0592
MHz; baud rate for the serial communication is 9600.
Solution
Step - I: Calculation of SCON Register
SCON = 50h
Step - II: Calculation of TMOD Register (Timer 1 in Mode 2
for Baud Rate
TMOD = 20h
Step - III: Calculation of TH1 Register for Baud Rate
TH1 = FDh
Step - IV: Calculation of IE Register
IE = 90h
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 44 / 54
Assembly Language Program
ORG 0000H
SJMP MAIN
ORG 0030H
MAIN: MOV P1, #0FFH ; make port P2 as an input port
MOV TMOD, #20H ; timer 1 in mode 2 for baud rate
MOV TH1, #0FDH ; to set baud rate 9600
MOV SCON, #50H ; serial mode 1
MOV IE, #90H ; enable serial communication interrupt
SETB TR1 ; start timer 1 for baud rate
L1: MOV A, P1 ; get data from port P1
MOV P2, A ; send data to the port P2
SJMP L1 ; repeat process
ORG 0023H
JB RI, RECEV
CLR TI
RETI
RECEV: MOV A, SBUF
MOV P0, A
CLR RI
RETI
END
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 45 / 54
Example - 9
Assume that INT0 pin is connected to a switch that is normally high. When-
ever the switch goes low, it should turn ON LED. The LED is connected to
port pin P1.4 and is normally OFF. When it is turned ON it should stay ON
for a fraction of seconds. As long as switch is pressed low, the LED should
stay ON.
Solution
Step - I: Calculation of IE Register
IE = 81h
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 46 / 54
Assembly Language Program
ORG 0000H
SJMP MAIN
ORG 0030H
MAIN: MOV IE, #81H
HERE: SJMP HERE
END
ORG 0003H
SETB P1.4
MOV R2, #0FFH
REP: DJNZ R2, REP
CLR P1.4
RETI
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 47 / 54
Example - 10
Assume that INT1 pin is connected to a pulse generator; write a program in
which the falling edge of the pulse will send a high to port pin P1.4, which
is connected to an LED, i.e. LED is turned ON and OFF at the same rate
as the pulses are applied to the INT1 pin.
Solution
Step - I: Calculation of IE Register
IE = 84h
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 48 / 54
Assembly Language Program
ORG 0000H
SJMP MAIN
ORG 0030H
MAIN: SETB TCON.2 ; Initialize INT1 edge triggered interrupt
MOV IE, #84H
HERE: SJMP HERE
END
Interrupt service routine (ISR) for hardware interrupt INT1 to turn ON LED
ORG 0013H
SETB P1.4
MOV R2, #0FFH
REP: DJNZ R2, REP
CLR P1.4
RETI
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 49 / 54
Example - 11
Using interrupt, write an assembly language program to do the following
(a) Receive data serially and send it to port P0
(b) Get data from port P1 and transferred serially and give a copy to port
P2.
(c) Make timer 0 in auto - reload mode to generate a square wave of 250 µs
frequency on the port pin P0.7
Assume crystal frequency 11.0592 MHz and set baud rate for the serial
communication is 4800.
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 50 / 54
Solution
Step - I: Calculation of TH1 Register for Baud Rate
TH1 = FAh
Step - II: Calculation of TH0 Register for 250 micro - sec
time
TON = TOFF = 125µs TH0 = 8Dh
Step - III: Calculation of TMOD Register
TMOD = 22h
Step - IV: Calculation of SCON Register
SCON = 50h
Step - V: Calculation of IE Register
IE = 92h
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 51 / 54
Assembly Language Program
ORG 0000H
SJMP MAIN ; bypass vector location
ORG 0030H
MAIN: MOV P1, #0FFH ; make port P1 as an input port
MOV TMOD, #22H ; Timer 0 in mode 2 for square wave
;and timer 1 in mode 2 for baud rate generation
MOV TH0, #8DH ; load TH0 with auto - reload value
MOV TH1, #0FAH ; load TH1 value for 4800 baud rate
MOV SCON, #50H ; set serial mode 1
MOV IE, #92H ; enable serial communication and
; timer 0 interrupts
SETB TR1 ; start timer 1 for baud rate
SETB TR0 ; start timer 0 for square wave
BACK: MOV A, P1 ; get data from port P1 until TF0 raised
MOV P2, A ; send data from P1 to port P2
MOV SBUF, A ; transfers data serially
SJMP BACK ; repeat the process
Interrupt service routine (ISR) for timer 0 to generate square wave
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 52 / 54
Assembly Language Program
ORG 000BH
CPL P0.7 ; interrupt routine of timer 0
CLR TF0
RETI ; return from interrupt
Interrupt service routine (ISR) for serial port to check whether data is transmitted or received completely o
ORG 0023H
JB TI, TRANS
MOV A, SBUF
MOV P0, A
CLR RI
RETI
TRANS: CLR TI
RETI
END
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 53 / 54
Thank you
Please send your feedback at nbahadure@gmail.com
For more details and updates kindly visit
https://sites.google.com/site/nileshbbahadure/home
Main Slide
Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 54 / 54

More Related Content

What's hot

Addressing modes
Addressing modesAddressing modes
Addressing modes
karthiga selvaraju
 
Timer And Counter in 8051 Microcontroller
Timer And Counter in 8051 MicrocontrollerTimer And Counter in 8051 Microcontroller
Timer And Counter in 8051 Microcontroller
Jay Makwana
 
8051 MICROCONTROLLER
8051 MICROCONTROLLER 8051 MICROCONTROLLER
8051 MICROCONTROLLER
THANDAIAH PRABU
 
Interrupts for PIC18
Interrupts for PIC18Interrupts for PIC18
Interrupts for PIC18
raosandy11
 
8051 ch9-950217
8051 ch9-9502178051 ch9-950217
8051 ch9-950217
Gopal Krishna Murthy C R
 
8051 io interface
8051 io interface8051 io interface
8051 io interface
Abhinav Shubham
 
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware
Prof. Swapnil V. Kaware
 
8051 Inturrpt
8051 Inturrpt8051 Inturrpt
8051 Inturrpt
Ramasubbu .P
 
Serial communication in 8085
Serial communication in 8085Serial communication in 8085
Serial communication in 8085
Nitin Ahire
 
Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor  Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor
Mustapha Fatty
 
Interrupts in 8051
Interrupts in 8051Interrupts in 8051
Interrupts in 8051
Sudhanshu Janwadkar
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)
Aarav Soni
 
8051 Microcontroller I/O ports
8051 Microcontroller I/O ports8051 Microcontroller I/O ports
8051 Microcontroller I/O ports
anishgoel
 
Memory interfacing of microcontroller 8051
Memory interfacing of microcontroller 8051Memory interfacing of microcontroller 8051
Memory interfacing of microcontroller 8051
Nilesh Bhaskarrao Bahadure
 
List of 8085 programs
List of 8085 programsList of 8085 programs
Microcontroller pic 16 f877 registers memory ports
Microcontroller pic 16 f877 registers memory portsMicrocontroller pic 16 f877 registers memory ports
Microcontroller pic 16 f877 registers memory ports
Nilesh Bhaskarrao Bahadure
 
Interrupt programming with 8051 microcontroller
Interrupt programming with 8051  microcontrollerInterrupt programming with 8051  microcontroller
Interrupt programming with 8051 microcontroller
Ankit Bhatnagar
 
8085-microprocessor
8085-microprocessor8085-microprocessor
8085-microprocessor
ATTO RATHORE
 
8051 memory
8051 memory8051 memory
8051 memory
Mayank Garg
 
INTERFACING ANALAOG TO DIGITAL CONVERTER (ADC0808/09) TO 8051 MICROCONTROLLER
 INTERFACING ANALAOG TO DIGITAL CONVERTER (ADC0808/09) TO 8051 MICROCONTROLLER   INTERFACING ANALAOG TO DIGITAL CONVERTER (ADC0808/09) TO 8051 MICROCONTROLLER
INTERFACING ANALAOG TO DIGITAL CONVERTER (ADC0808/09) TO 8051 MICROCONTROLLER
SIRILsam
 

What's hot (20)

Addressing modes
Addressing modesAddressing modes
Addressing modes
 
Timer And Counter in 8051 Microcontroller
Timer And Counter in 8051 MicrocontrollerTimer And Counter in 8051 Microcontroller
Timer And Counter in 8051 Microcontroller
 
8051 MICROCONTROLLER
8051 MICROCONTROLLER 8051 MICROCONTROLLER
8051 MICROCONTROLLER
 
Interrupts for PIC18
Interrupts for PIC18Interrupts for PIC18
Interrupts for PIC18
 
8051 ch9-950217
8051 ch9-9502178051 ch9-950217
8051 ch9-950217
 
8051 io interface
8051 io interface8051 io interface
8051 io interface
 
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware
 
8051 Inturrpt
8051 Inturrpt8051 Inturrpt
8051 Inturrpt
 
Serial communication in 8085
Serial communication in 8085Serial communication in 8085
Serial communication in 8085
 
Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor  Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor
 
Interrupts in 8051
Interrupts in 8051Interrupts in 8051
Interrupts in 8051
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)
 
8051 Microcontroller I/O ports
8051 Microcontroller I/O ports8051 Microcontroller I/O ports
8051 Microcontroller I/O ports
 
Memory interfacing of microcontroller 8051
Memory interfacing of microcontroller 8051Memory interfacing of microcontroller 8051
Memory interfacing of microcontroller 8051
 
List of 8085 programs
List of 8085 programsList of 8085 programs
List of 8085 programs
 
Microcontroller pic 16 f877 registers memory ports
Microcontroller pic 16 f877 registers memory portsMicrocontroller pic 16 f877 registers memory ports
Microcontroller pic 16 f877 registers memory ports
 
Interrupt programming with 8051 microcontroller
Interrupt programming with 8051  microcontrollerInterrupt programming with 8051  microcontroller
Interrupt programming with 8051 microcontroller
 
8085-microprocessor
8085-microprocessor8085-microprocessor
8085-microprocessor
 
8051 memory
8051 memory8051 memory
8051 memory
 
INTERFACING ANALAOG TO DIGITAL CONVERTER (ADC0808/09) TO 8051 MICROCONTROLLER
 INTERFACING ANALAOG TO DIGITAL CONVERTER (ADC0808/09) TO 8051 MICROCONTROLLER   INTERFACING ANALAOG TO DIGITAL CONVERTER (ADC0808/09) TO 8051 MICROCONTROLLER
INTERFACING ANALAOG TO DIGITAL CONVERTER (ADC0808/09) TO 8051 MICROCONTROLLER
 

Similar to Interrupts of microcontroller 8051

Interrupts of microprocessor 8085
Interrupts of microprocessor 8085Interrupts of microprocessor 8085
Interrupts of microprocessor 8085
Nilesh Bhaskarrao Bahadure
 
Timers and counters of microcontroller 8051
Timers and counters of microcontroller 8051Timers and counters of microcontroller 8051
Timers and counters of microcontroller 8051
Nilesh Bhaskarrao Bahadure
 
Unit 5_interrupt programming_Part 1
Unit 5_interrupt programming_Part 1Unit 5_interrupt programming_Part 1
Unit 5_interrupt programming_Part 1
KanchanPatil34
 
Microcontrollers and Embedded system notes.pdf
Microcontrollers and Embedded system notes.pdfMicrocontrollers and Embedded system notes.pdf
Microcontrollers and Embedded system notes.pdf
helixmanglalina820
 
MEDICAL SHOP AUTOMATION USING VB. NET
MEDICAL SHOP AUTOMATION USING VB. NETMEDICAL SHOP AUTOMATION USING VB. NET
MEDICAL SHOP AUTOMATION USING VB. NET
Journal For Research
 
Induction Motor Protection Using PLC
Induction Motor Protection Using PLCInduction Motor Protection Using PLC
Induction Motor Protection Using PLC
vivatechijri
 
Programming of the ATE for Fuze calibration using Lab View Software
Programming of the ATE for Fuze calibration using Lab View SoftwareProgramming of the ATE for Fuze calibration using Lab View Software
Programming of the ATE for Fuze calibration using Lab View Software
ijsrd.com
 
Cn33543547
Cn33543547Cn33543547
Cn33543547
IJERA Editor
 
Cn33543547
Cn33543547Cn33543547
Cn33543547
IJERA Editor
 
Interrupts programming in embedded C using 8051
Interrupts programming in embedded C using 8051Interrupts programming in embedded C using 8051
Interrupts programming in embedded C using 8051
Vikas Dongre
 
Implementation of Effective Switching System for Controlling Home and Office ...
Implementation of Effective Switching System for Controlling Home and Office ...Implementation of Effective Switching System for Controlling Home and Office ...
Implementation of Effective Switching System for Controlling Home and Office ...
ijtsrd
 
Report (Electromagnetic Password Door Lock System)
Report (Electromagnetic Password Door Lock System)Report (Electromagnetic Password Door Lock System)
Report (Electromagnetic Password Door Lock System)
Siang Wei Lee
 
Wireless Bomb Disposal Robot
Wireless Bomb Disposal RobotWireless Bomb Disposal Robot
Wireless Bomb Disposal Robot
Abhishek Gupta
 
Wireless Bomb Disposal Robot
Wireless Bomb Disposal RobotWireless Bomb Disposal Robot
Wireless Bomb Disposal Robot
Abhishek Gupta
 
Mc module5 ppt_msj
Mc module5 ppt_msjMc module5 ppt_msj
Mc module5 ppt_msj
mangala jolad
 
DIFFERENT APPLICATIONS OF PROGRAMMABLE LOGIC CONTROLLER (PLC)
DIFFERENT APPLICATIONS OF PROGRAMMABLE LOGIC CONTROLLER (PLC)DIFFERENT APPLICATIONS OF PROGRAMMABLE LOGIC CONTROLLER (PLC)
DIFFERENT APPLICATIONS OF PROGRAMMABLE LOGIC CONTROLLER (PLC)
ijcseit
 
International Journal of Computer Science, Engineering and Information Techno...
International Journal of Computer Science, Engineering and Information Techno...International Journal of Computer Science, Engineering and Information Techno...
International Journal of Computer Science, Engineering and Information Techno...
ijcseit
 
Different applications of programmable logic controller (plc)
Different applications of programmable logic controller (plc)Different applications of programmable logic controller (plc)
Different applications of programmable logic controller (plc)
ijcseit
 
Performance analysis of voice operated wheel chair
Performance analysis of voice operated wheel chairPerformance analysis of voice operated wheel chair
Performance analysis of voice operated wheel chair
eSAT Publishing House
 
smartlock_final_report
smartlock_final_reportsmartlock_final_report
smartlock_final_report
Elliot Barer
 

Similar to Interrupts of microcontroller 8051 (20)

Interrupts of microprocessor 8085
Interrupts of microprocessor 8085Interrupts of microprocessor 8085
Interrupts of microprocessor 8085
 
Timers and counters of microcontroller 8051
Timers and counters of microcontroller 8051Timers and counters of microcontroller 8051
Timers and counters of microcontroller 8051
 
Unit 5_interrupt programming_Part 1
Unit 5_interrupt programming_Part 1Unit 5_interrupt programming_Part 1
Unit 5_interrupt programming_Part 1
 
Microcontrollers and Embedded system notes.pdf
Microcontrollers and Embedded system notes.pdfMicrocontrollers and Embedded system notes.pdf
Microcontrollers and Embedded system notes.pdf
 
MEDICAL SHOP AUTOMATION USING VB. NET
MEDICAL SHOP AUTOMATION USING VB. NETMEDICAL SHOP AUTOMATION USING VB. NET
MEDICAL SHOP AUTOMATION USING VB. NET
 
Induction Motor Protection Using PLC
Induction Motor Protection Using PLCInduction Motor Protection Using PLC
Induction Motor Protection Using PLC
 
Programming of the ATE for Fuze calibration using Lab View Software
Programming of the ATE for Fuze calibration using Lab View SoftwareProgramming of the ATE for Fuze calibration using Lab View Software
Programming of the ATE for Fuze calibration using Lab View Software
 
Cn33543547
Cn33543547Cn33543547
Cn33543547
 
Cn33543547
Cn33543547Cn33543547
Cn33543547
 
Interrupts programming in embedded C using 8051
Interrupts programming in embedded C using 8051Interrupts programming in embedded C using 8051
Interrupts programming in embedded C using 8051
 
Implementation of Effective Switching System for Controlling Home and Office ...
Implementation of Effective Switching System for Controlling Home and Office ...Implementation of Effective Switching System for Controlling Home and Office ...
Implementation of Effective Switching System for Controlling Home and Office ...
 
Report (Electromagnetic Password Door Lock System)
Report (Electromagnetic Password Door Lock System)Report (Electromagnetic Password Door Lock System)
Report (Electromagnetic Password Door Lock System)
 
Wireless Bomb Disposal Robot
Wireless Bomb Disposal RobotWireless Bomb Disposal Robot
Wireless Bomb Disposal Robot
 
Wireless Bomb Disposal Robot
Wireless Bomb Disposal RobotWireless Bomb Disposal Robot
Wireless Bomb Disposal Robot
 
Mc module5 ppt_msj
Mc module5 ppt_msjMc module5 ppt_msj
Mc module5 ppt_msj
 
DIFFERENT APPLICATIONS OF PROGRAMMABLE LOGIC CONTROLLER (PLC)
DIFFERENT APPLICATIONS OF PROGRAMMABLE LOGIC CONTROLLER (PLC)DIFFERENT APPLICATIONS OF PROGRAMMABLE LOGIC CONTROLLER (PLC)
DIFFERENT APPLICATIONS OF PROGRAMMABLE LOGIC CONTROLLER (PLC)
 
International Journal of Computer Science, Engineering and Information Techno...
International Journal of Computer Science, Engineering and Information Techno...International Journal of Computer Science, Engineering and Information Techno...
International Journal of Computer Science, Engineering and Information Techno...
 
Different applications of programmable logic controller (plc)
Different applications of programmable logic controller (plc)Different applications of programmable logic controller (plc)
Different applications of programmable logic controller (plc)
 
Performance analysis of voice operated wheel chair
Performance analysis of voice operated wheel chairPerformance analysis of voice operated wheel chair
Performance analysis of voice operated wheel chair
 
smartlock_final_report
smartlock_final_reportsmartlock_final_report
smartlock_final_report
 

More from Nilesh Bhaskarrao Bahadure

Biomedical Signal Origin and Dynamics
Biomedical Signal Origin and DynamicsBiomedical Signal Origin and Dynamics
Biomedical Signal Origin and Dynamics
Nilesh Bhaskarrao Bahadure
 
Introduction to Medical Image Processing
Introduction to Medical Image ProcessingIntroduction to Medical Image Processing
Introduction to Medical Image Processing
Nilesh Bhaskarrao Bahadure
 
Timing diagram of microprocessor 8085
Timing diagram of microprocessor 8085Timing diagram of microprocessor 8085
Timing diagram of microprocessor 8085
Nilesh Bhaskarrao Bahadure
 
Serial communication of microcontroller 8051
Serial communication of microcontroller 8051Serial communication of microcontroller 8051
Serial communication of microcontroller 8051
Nilesh Bhaskarrao Bahadure
 
Peripherals of Microprocessor 8085
Peripherals of Microprocessor 8085Peripherals of Microprocessor 8085
Peripherals of Microprocessor 8085
Nilesh Bhaskarrao Bahadure
 
Microprocessor 8085 Basics
Microprocessor 8085 BasicsMicroprocessor 8085 Basics
Microprocessor 8085 Basics
Nilesh Bhaskarrao Bahadure
 
Microcontroller 8051 instruction set and assemble directives
Microcontroller 8051 instruction set and assemble directivesMicrocontroller 8051 instruction set and assemble directives
Microcontroller 8051 instruction set and assemble directives
Nilesh Bhaskarrao Bahadure
 
Microcontroller 8051 basics (part I)
Microcontroller 8051 basics (part I)Microcontroller 8051 basics (part I)
Microcontroller 8051 basics (part I)
Nilesh Bhaskarrao Bahadure
 
Memory interfacing of microprocessor 8085
Memory interfacing of microprocessor 8085Memory interfacing of microprocessor 8085
Memory interfacing of microprocessor 8085
Nilesh Bhaskarrao Bahadure
 
Instruction sets of microprocessor 8085
Instruction sets of microprocessor 8085Instruction sets of microprocessor 8085
Instruction sets of microprocessor 8085
Nilesh Bhaskarrao Bahadure
 
Embedded Systems
Embedded Systems Embedded Systems
Embedded Systems
Nilesh Bhaskarrao Bahadure
 
Basic Electronics Semiconductor Diodes
Basic Electronics Semiconductor DiodesBasic Electronics Semiconductor Diodes
Basic Electronics Semiconductor Diodes
Nilesh Bhaskarrao Bahadure
 
Basic Electronics Electrical Transducers
Basic Electronics Electrical TransducersBasic Electronics Electrical Transducers
Basic Electronics Electrical Transducers
Nilesh Bhaskarrao Bahadure
 
Basic Electronics BJT
Basic Electronics BJTBasic Electronics BJT
Basic Electronics BJT
Nilesh Bhaskarrao Bahadure
 
Applications of Microcontroller 8051
Applications of Microcontroller 8051Applications of Microcontroller 8051
Applications of Microcontroller 8051
Nilesh Bhaskarrao Bahadure
 
Question Bank Programmable Logic Controller
Question Bank Programmable Logic ControllerQuestion Bank Programmable Logic Controller
Question Bank Programmable Logic Controller
Nilesh Bhaskarrao Bahadure
 
Question Bank Microprocessor 8085
Question Bank Microprocessor 8085Question Bank Microprocessor 8085
Question Bank Microprocessor 8085
Nilesh Bhaskarrao Bahadure
 
Question Bank linear integrated circuits and applications
Question Bank linear integrated circuits and applicationsQuestion Bank linear integrated circuits and applications
Question Bank linear integrated circuits and applications
Nilesh Bhaskarrao Bahadure
 
Question Bank Digital Signal Processing
Question Bank Digital Signal ProcessingQuestion Bank Digital Signal Processing
Question Bank Digital Signal Processing
Nilesh Bhaskarrao Bahadure
 
Question Bank Basic Electronics
Question Bank Basic ElectronicsQuestion Bank Basic Electronics
Question Bank Basic Electronics
Nilesh Bhaskarrao Bahadure
 

More from Nilesh Bhaskarrao Bahadure (20)

Biomedical Signal Origin and Dynamics
Biomedical Signal Origin and DynamicsBiomedical Signal Origin and Dynamics
Biomedical Signal Origin and Dynamics
 
Introduction to Medical Image Processing
Introduction to Medical Image ProcessingIntroduction to Medical Image Processing
Introduction to Medical Image Processing
 
Timing diagram of microprocessor 8085
Timing diagram of microprocessor 8085Timing diagram of microprocessor 8085
Timing diagram of microprocessor 8085
 
Serial communication of microcontroller 8051
Serial communication of microcontroller 8051Serial communication of microcontroller 8051
Serial communication of microcontroller 8051
 
Peripherals of Microprocessor 8085
Peripherals of Microprocessor 8085Peripherals of Microprocessor 8085
Peripherals of Microprocessor 8085
 
Microprocessor 8085 Basics
Microprocessor 8085 BasicsMicroprocessor 8085 Basics
Microprocessor 8085 Basics
 
Microcontroller 8051 instruction set and assemble directives
Microcontroller 8051 instruction set and assemble directivesMicrocontroller 8051 instruction set and assemble directives
Microcontroller 8051 instruction set and assemble directives
 
Microcontroller 8051 basics (part I)
Microcontroller 8051 basics (part I)Microcontroller 8051 basics (part I)
Microcontroller 8051 basics (part I)
 
Memory interfacing of microprocessor 8085
Memory interfacing of microprocessor 8085Memory interfacing of microprocessor 8085
Memory interfacing of microprocessor 8085
 
Instruction sets of microprocessor 8085
Instruction sets of microprocessor 8085Instruction sets of microprocessor 8085
Instruction sets of microprocessor 8085
 
Embedded Systems
Embedded Systems Embedded Systems
Embedded Systems
 
Basic Electronics Semiconductor Diodes
Basic Electronics Semiconductor DiodesBasic Electronics Semiconductor Diodes
Basic Electronics Semiconductor Diodes
 
Basic Electronics Electrical Transducers
Basic Electronics Electrical TransducersBasic Electronics Electrical Transducers
Basic Electronics Electrical Transducers
 
Basic Electronics BJT
Basic Electronics BJTBasic Electronics BJT
Basic Electronics BJT
 
Applications of Microcontroller 8051
Applications of Microcontroller 8051Applications of Microcontroller 8051
Applications of Microcontroller 8051
 
Question Bank Programmable Logic Controller
Question Bank Programmable Logic ControllerQuestion Bank Programmable Logic Controller
Question Bank Programmable Logic Controller
 
Question Bank Microprocessor 8085
Question Bank Microprocessor 8085Question Bank Microprocessor 8085
Question Bank Microprocessor 8085
 
Question Bank linear integrated circuits and applications
Question Bank linear integrated circuits and applicationsQuestion Bank linear integrated circuits and applications
Question Bank linear integrated circuits and applications
 
Question Bank Digital Signal Processing
Question Bank Digital Signal ProcessingQuestion Bank Digital Signal Processing
Question Bank Digital Signal Processing
 
Question Bank Basic Electronics
Question Bank Basic ElectronicsQuestion Bank Basic Electronics
Question Bank Basic Electronics
 

Recently uploaded

A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
nooriasukmaningtyas
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
nooriasukmaningtyas
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
PauloRodrigues104553
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
yokeleetan1
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
Divyam548318
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
University of Maribor
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 

Recently uploaded (20)

A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 

Interrupts of microcontroller 8051

  • 1. Interrupts of 8051 Microcontroller Dr. Nilesh Bhaskarrao Bahadure https://www.sites.google.com/site/nileshbbahadure/home July 25, 2021 Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 1 / 54
  • 2. Overview I 1 What is Interrupt Introduction to 8051 Microcontroller Interrupts 2 Interrupts of 8051 Microcontroller 3 Interrupt Vs Polling 4 IE register 5 IP register 6 What happens when an interrupt occurs? 7 What happens when an interrupt Ends? 8 Programming Timer Interrupt 9 Serial Interrupt 10 External Hardware Interrupt Level Triggered Interrupt Edge Triggered Interrupt TCON Register 11 Examples Example - 1: Example on IE Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 2 / 54
  • 3. Overview II Example - 2: Example on IP Example - 3: Example on IP Example - 4: Generation of Square Wave Using Timer 0 Mode 2 Example - 5: Generation of Square Wave Using Timer 0 Mode 1 Example - 6: Generation of Square Wave of 50 Hz Using Timer 0 Example - 7: Transmission of bits serially using Interrupt Example - 8: Reception of bits serially using Interrupt Example - 9: LED ON using External Hardware Interrupt Example - 10: LED ON using External Hardware Interrupt and Pulse generator Example - 11: Transfer - Receive & Square Wave using Interrupt Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 3 / 54
  • 4. What is Interrupt Interrupt is the routine program to break or stop the current execution and branch to another program. Interrupt of microcontroller 8051 consists two hardware interrupts as well as generated interrupts using timers and serial communication. Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 4 / 54
  • 5. Introduction to 8051 Microcontroller Interrupts Interrupts are signals that cause the Microcontroller to suspend what is doing and transfer to a special program called an interrupt handler. The interrupt handler is responsible for determining the cause of interrupt, servicing the interrupt and returning the control to the point from where the interrupt was caused. Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 5 / 54
  • 6. Introduction to 8051 Microcontroller Interrupts... When Microcontroller executes any program then it is called Main pro- gram. In between the main program, Microcontroller is interrupted then Microcontroller will branch from main program to subprogram this subpro- gram is called Interrupt service routine (ISR). After executing this ISR then RETI/RET instruction comes then Microcontroller returns back from ISR to the main program from where Microcontroller has left. Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 6 / 54
  • 7. Interrupts of 8051 Microcontroller Question What events can trigger interrupts, and where do they go? We can configure the 8051 so that any of the following events will cause an interrupt: 1 Timer 0 Overflow. 2 Timer 1 Overflow. 3 Reception/Transmission of Serial Character. 4 External Event 0. 5 External Event 1. Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 7 / 54
  • 8. Interrupts of 8051 Microcontroller... The six interrupts in the 8051 are allocated as follows: 1 RESET: When the reset pin is activated, the Microcontroller 8051 jumps to the address location 0000h. This is also referred as power on reset. 2 Timers: Two interrupts are set aside for the timers: Timer 0 and Timer 1. Memory location addresses 000Bh and 001Bh in the interrupt vector table belongs to timer 0 and timer 1, respectively. 3 Hardware external interrupts: Two interrupts are set aside for hardware external interrupts. Pin number 12 (P3.2) and 13 (P3.3) are for the external hardware interrupts also referred as EX 1 and EX 2. Memory location addresses 0003h and 0013h in the interrupt vector table are assigned to INT0 and INT1 external hardware interrupts respectively. 4 Serial communication: serial communication has a single interrupt that belongs to both transmit and receive. The interrupt vector table location 0023h belongs to the serial communication interrupt. Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 8 / 54
  • 9. Interrupts of 8051 Microcontroller... Table : Interrupts with their handler addresses Interrupt Flag Interrupt handler address/Vector location External 0 IE0 0003h Timer 0 TF0 000Bh External 1 IE1 0013h Timer 1 TF1 001Bh Serial RI/TI 0023h Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 9 / 54
  • 10. Interrupt Vs Polling A single Microcontroller can serve several devices. There are two ways to do that: Interrupts and polling. Interrupts: In the interrupt method, whenever any device needs its service, the device notifies the Microcontroller by sending an interrupt signal, upon receiving an interrupt signal, the Microcontroller interrupts whatever it is doing and serve the device. The program associated with the interrupt is called the interrupt service routine (ISR) or interrupt handler. Polling: In polling, the Microcontroller continuously monitors the status of a several devices, when the status condition is met, it perform the service, after that, it moves on to monitor the next device until each one is serviced. Although polling can monitors the status of several devices and serve each of them as certain conditions are met, it is not an efficient use of Microcontroller. Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 10 / 54
  • 11. Interrupt Vs Polling... Figure : Polling method to access several devices Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 11 / 54
  • 12. Interrupt Vs Polling... The advantage of the interrupts is that the Microcontroller can serve many devices, not all at the same time; each device can get the attention of the Microcontroller, based on the priority assigned to it. The polling method cannot assign priority since it checks all the devices in a round robin fashion as shown in the figure 1. Also in the interrupt method, the Microcontroller can also ignore or mask or reset a device request for service. This is not possible in polling. The most important reason that the interrupt method is preferable over the polling is that the polling method waste the time of Microcontroller in order to search the devices one by one, so in order to avoid tying down the Microcontroller, interrupts are used. For example, the instruction LABEL: JNB TFx, LABEL, waited until the timer rollover and while we were waiting we could not do anything else i.e. a waste of this Microcontroller’s time that could have been used to perform some other useful tasks. In this case, the Microcontroller can go about doing other tasks, and when the timer flag bit is raised, the timer will interrupt the Microcontroller in whatever it is doing. Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 12 / 54
  • 13. IE register D7 D6 D5 D4 D3 D2 D1 D0 EA – – ES ET1 EX1 ET0 EX0 Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 13 / 54
  • 14. IE register... Table : Explanation of function of IE register Bit Name Bit address Function 7 EA AFh Global Interrupt Enable / Disable 6 – AEh Undefined (don’t care) 5 – ADh Undefined (don’t care) 4 ES ACh Enable serial communication interrupt 3 ET1 ABh Enable timer 1 interrupt 2 EX1 AAh Enable external 1 hardware interrupt 1 ET0 A9h Enable timer 0 interrupt 0 EX0 A8h Enable external 0 hardware interrupt Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 14 / 54
  • 15. IE register... The schematic representations of the interrupt are as follows: Figure : Interrupt structure of 8051 Microcontroller Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 15 / 54
  • 16. IP register D7 D6 D5 D4 D3 D2 D1 D0 – – PT2 PS PT1 PX1 PT0 PX0 Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 16 / 54
  • 17. IP Register... Table : Explanation of function of IP register Bit Name Bit address Function 7 – BFh Undefined (don’t care) 6 – BEh Undefined (don’t care) 5 PT2 BDh Timer 2 interrupt priority (8052 only) 4 PS BCh Serial communication interrupt priority 3 PT1 BBh External 1 hardware interrupt priority 2 PX1 BAh Timer 1 interrupt priority 1 PT0 B9h External 0 hardware interrupt priority 0 PX0 B8h Timer 0 interrupt priority Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 17 / 54
  • 18. What happens when an interrupt occurs? When an interrupt is triggered, the following actions are taken automatically by the Microcontroller: 1 The current Program Counter is saved on the stack, low-byte first. 2 Interrupts of the same and lower priority are blocked. 3 In the case of Timer and External interrupts, the corresponding interrupt flag is set. 4 Program execution transfers to the corresponding interrupt handler vector address. 5 The Interrupt Handler Routine executes. Take special note of the third step: If the interrupt being handled is a Timer or External interrupt, the Microcontroller automatically clears the interrupt flag before passing control to your interrupt handler routine. Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 18 / 54
  • 19. What happens when an interrupt Ends? An interrupt ends when your program executes the RETI instruction. When the RETI instruction is executed the following actions are taken by the Microcontroller:: 1 Two bytes are popped off the stack into the Program Counter to restore normal program execution. 2 Interrupt status is restored to its pre-interrupt status. Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 19 / 54
  • 20. Programming Timer Interrupt Figure : Timer 0 and Timer 1 interrupt invoked by TF0 and TF1 Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 20 / 54
  • 21. Programming Timer Interrupt... We know that timer flag is raised when the timer rolls over i.e. overflows and the overflow condition are checked by monitoring TF bit using the in- struction “JNB TFx, Label”. In polling method, we have to wait until the timer flag bit TF is raised. The problem with this method is that the Micro- controller is tied down while waiting for TF flag bit to be raised and cannot do anything else. Using interrupts this problem getting solve and avoids tied down the Microcontroller. If the timer interrupt in IE (Interrupt enable) register is enabled, whenever the timer rolls over, timer flag TF bit is raised automatically and Microcontroller is interrupted in whatever it is doing, and jump to the interrupt vector table to service the interrupt service routine (ISR) of the timer. In this way the Microcontroller can do other things until it is notified that the timer has rolled over. Whenever the timer flag bit is raised and if the corresponding bit of the timer interrupt flag bit is set in the IE register, Microcontroller automatically switch or jump to the vector location of timers. Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 21 / 54
  • 22. Serial Interrupt of Microcontroller 8051 The working of Serial Interrupts is slightly different than the rest of the interrupts. This is due to the fact that there are two interrupt flags: RI and TI and only one interrupt flag bit is associated for both. If either flag is set, a serial interrupt is triggered. As you will recall from the previous section on the serial port, the RI bit is set when a byte is received by the serial port and the TI bit is set when a byte has been sent. This means that when your serial interrupt is executed, it may have been triggered because the RI flag was set or because the TI flag was set or because both flags were set. Thus, your routine must check the status of these flags to determine what action is appropriate. Also, since the 8051 does not automatically clear the RI and TI flags you must clear these bits in your interrupt handler. Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 22 / 54
  • 23. Serial Interrupt of Microcontroller 8051... INT SERIAL: JNB RI, CHECK TI ; If the RI flag is not set, we jump to check TI MOV A, SBUF ; If we got to this line, it’s because the RI bit was set CLR RI ; Clear the RI bit after we’ve processed it CHECK TI: JNB TI, EXIT INT ; If the TI flag is not set, we jump to the exit point CLR TI ; Clear the TI bit before we send another character MOV SBUF, #’A’ ; Send another character to the serial port EXIT INT: RETI Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 23 / 54
  • 24. Programming External Hardware Interrupt There are only two external hardware interrupts in the 8051 Microcontroller: INT0 and INT1. They are located on pin P3.2 and P3.3 of port 3 respectively. The interrupt vector table locations 0003h and 0013h are set aside for INT0 and INT1 respectively. They are enabled and disabled using IE register. There are two types of activation for the external hardware interrupts, they are 1. Level triggered 2. Edge triggered Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 24 / 54
  • 25. Programming External Hardware Interrupt... Figure : Level & Edge triggered for INT0 and INT1 Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 25 / 54
  • 26. Level Triggered Interrupt In the level triggered mode, INT0 and INT1 pins are normally high and if a low level signal (as they are low level active pins) is applied to them, it triggers the interrupt. Upon receiving the interrupt signal, Microcontroller stops whatever it is doing and jumps to the interrupt vector table to service the interrupt. This is called level triggered or level activated interrupt and is the default mode of activation upon reset of the 8051. The low level signal at the 8051 pin must be removed before the execution of the last instruction of interrupt service routine i.e. RETI, otherwise, another interrupt will be generated. Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 26 / 54
  • 27. Edge Triggered Interrupt Upon reset the 8051 makes INT0 and INT1 low level triggered interrupts. To make them edge triggered interrupts, we must program the bits of the TCON register. The TCON register consists of IT0 and IT1 flag bits that determine level or edge triggered mode of the hardware interrupts. IT0 and IT1 are bits D0 and D2 of the TCON register respectively. Since TCON is a bit addressable register, these bits are also referred as TCON.0 and TCON.2. Upon reset TCON.0 and TCON.2 are both 0s i.e. external hard- ware interrupts of INT0 and INT1 pins are low level triggered. By making TCON.0 and TCON.2 bits high with instruction such as SETB TCON.0 and SETB TCON.2 the external hardware interrupts INT0 and INT1 becomes edge triggered interrupts. For example by applying High to Low pulse on INT1 pin, then INT1 hardware interrupt becomes edge triggered hardware interrupts. Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 27 / 54
  • 28. TCON SFR D7 D6 D5 D4 D3 D2 D1 D0 TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0 Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 28 / 54
  • 29. TCON SFR... Bits Name Function 3 IE1 External hardware interrupts 1 edge flag. Set by CPU when the ex- ternal interrupt edge (High to Low transition) is detected. Cleared by CPU when the interrupt is processed 2 IT1 Interrupt 1 type control bit. Set/Cleared by software to specify falling edge (Edge triggered)/Level triggered external interrupts. 1 IE0 External hardware interrupts 0 edge flag. Set by CPU when the ex- ternal interrupt edge (High to Low transition) is detected. Cleared by CPU when the interrupt is processed 0 IT0 Interrupt 0 type control bit. Set/Cleared by software to specify falling edge (Edge triggered) / Level triggered external interrupts. (IT0 = 0, then low level triggered mode is set IT0 = 1, then edge triggered mode is set) Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 29 / 54
  • 30. Example - 1 Show the instruction to (a) Enable serial interrupt, timer 0 interrupt and hardware external interrupt 0. (b) Disable timer 0 interrupt (c) Show how to disable all the interrupts with a single instruction. Solution EA – ET2 ES ET1 EX1 ET0 EX0 1 0 0 1 0 0 0 1 93h IE = 93h Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 30 / 54
  • 31. Assembly Language Program (a) MOV IE, #93H Since IE register is a bit addressable register, we can use the following instructions to access individual bits of register SETB IE.7 ; EA = 1, global enable SETB IE.4 ; enable serial interrupt SETB IE.1 ; enable timer 0 interrupt SETB IE.0 ; enable external hardware interrupt 0 (b) CLR IE.1 ; disable timer 0 interrupt only (c) CLR IE.7 ; disable all interrupts Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 31 / 54
  • 32. Example - 2 Program the interrupt priority (IP) register to perform the following (a) Assign the highest priority to timer 0 and show the new priority order (b) Discuss what happen if external hardware interrupts 0 and timer 0 interrupt are set at the same time. Solution – – PT2 PS PT1 PX1 PT0 PX0 0 0 0 0 0 0 1 0 02h IP = 02h (a) MOV IP, 02H Or SETB IP.2 Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 32 / 54
  • 33. Solution (a) Old priority order New priority order External hardware interrupt 0 (INT0) Timer 0 interrupt (TF0) Timer 0 interrupt (TF0) External hardware interrupt 0 (INT0) External hardware interrupt 1 (INT1) External hardware interrupt 1 (INT1) Timer 1 interrupt (TF1) Timer 1 interrupt (TF1) Serial communication interrupt (RI/TI) Serial communication interrupt (RI/TI) (b) Timer 0 is assigned the highest priority so the order of the interrupts are New priority order Timer 0 interrupt (TF0) External hardware interrupt 0 (INT0) External hardware interrupt 1 (INT1) Timer 1 interrupt (TF1) Serial communication interrupt (RI/TI) Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 33 / 54
  • 34. Example - 3 Assume that after reset, the IP register is program with the instruction MOV IP, #0Bh. Discuss the sequence in which the interrupts are serviced. Solution – – PT2 PS PT1 PX1 PT0 PX0 0 0 0 0 1 0 1 1 0Bh IP = 0Bh This instruction sets external hardware interrupt 0 (INT0), timer 0 (TF0) and timer 1 (TF1) to the higher priority level compared with rest of the interrupts. So according to program bits old and new priority level of the interrupts are shown below Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 34 / 54
  • 35. Solution Old priority order New priority order External hardware interrupt 0 (INT0) External hardware interrupt 0 (INT0) Timer 0 interrupt (TF0) Timer 0 interrupt (TF0) External hardware interrupt 1 (INT1) Timer 1 interrupt (TF1) Timer 1 interrupt (TF1) External hardware interrupt 1 (INT1) Serial communication interrupt (RI/TI) Serial communication interrupt (RI/TI) Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 35 / 54
  • 36. Example - 4 Write an assembly language program that continuously gets 8 - bit data from port P0 and send to port P1 while simultaneously creating a square wave of 250 µS period on port pin P2.1. Use timer 0 in mode 2 to create the square wave, assume that crystal frequency of 8051 is 11.0592 MHz. Solution Step - I: Calculation of count value in TH0 Register TON = TOFF = 125µs TH0 = 8Dh Step - II: Calculation of TMOD Register TMOD = 02h Step - III: Calculation of IE Register IE = 82h Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 36 / 54
  • 37. Assembly Language Program ORG 0000H SJMP MAIN ; bypass vector location ORG 0030H MAIN: MOV P0, #0FFH ; make port P0 as an input port MOV TMOD, #02H ; Timer 0 in mode 2 MOV TH0, #8DH ; load TH0 with auto - reload value MOV IE, #82H ; enable timer 0 SETB TR0 ; start timer 0 BACK: MOV A, P0 ; get data from port P0 until TF0 raised MOV P1, A ; send data from P0 to port P1 SJMP BACK ; repeat the process ORG 000BH CPL P2.1 ; interrupt routine of timer 0 CLR TF0 RETI ; return from interrupt Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 37 / 54
  • 38. Example - 5 Repeat example 4 using timer 0 in mode 1. Solution Step - I: Calculation of count value in TH0 - TL0 Register TON = TOFF = 125µs TH0 = 8Dh TL0 = FFh Step - II: Calculation of TMOD Register TMOD = 01h Step - III: Calculation of IE Register IE = 82h Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 38 / 54
  • 39. Assembly Language Program ORG 0000H SJMP MAIN ; bypass vector location ORG 0030H MAIN: MOV P0, #0FFH ; make port P0 as an input port MOV TMOD, #01H ; Timer 0 in mode 1 MOV TH0, #0FFH ; Load timer 0 higher byte MOV TL0, #8DH ; load timer 0 lower byte MOV IE, #82H ; enable timer 0 SETB TR0 ; start timer 0 BACK: MOV A, P0 ; get data from port P0 until TF0 raised MOV P1, A ; send data from P0 to port P1 SJMP BACK ; repeat the process ORG 000BH CPL P2.1 ; interrupt routine of timer 0 MOV TH0, #0FFH MOV TL0, #0A4H CLR TR0 CLR TF0 RETI ; return from interrupt Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 39 / 54
  • 40. Example - 6 Write an assembly language program to generate square wave of 50 Hz frequency on port pin P1.2 using interrupt for timer 0. Assume crystal frequency of 8051 is 11.0592 MHz. Solution Step - I: Calculation of count value in TH0 - TL0 Register TON = TOFF = 0.01s TH0 = DCh TL0 = 00h Step - II: Calculation of TMOD Register TMOD = 01h Step - III: Calculation of IE Register IE = 82h Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 40 / 54
  • 41. Assembly Language Program ORG 0000H SJMP MAIN ; bypass vector location ORG 0030H MAIN: MOV TMOD, #01H ; Timer 0 in mode 1 MOV TH0, #0DCH ; Load timer 0 higher byte MOV TL0, #00H ; load timer 0 lower byte MOV IE, #82H ; enable timer 0 SETB TR0 ; start timer 0 BACK: SJMP BACK ; repeat the process ORG 000BH CPL P2.1 ; interrupt routine of timer 0 MOV TH0, #0DCH MOV TL0, #00H CLR TR0 CLR TF0 RETI ; return from interrupt Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 41 / 54
  • 42. Example - 7 Write an assembly language program to get data from port P1 and sends to port P2 continuously, while giving a copy to the serial port to be transferred serially. Assume that crystal frequency of 8051 is 11.0592 MHz and baud rate for the serial communication is 9600. Solution Step - I: Calculation of SCON Register SCON = 50h Step - II: Calculation of TMOD Register (Timer 1 in Mode 2 for Baud Rate) TMOD = 20h Step - III: Calculation of TH1 Register for Baud Rate TH1 = FDh Step - IV: Calculation of IE Register IE = 90h Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 42 / 54
  • 43. Assembly Language Program ORG 0000H SJMP MAIN ORG 0030H MAIN: MOV P1, #0FFH ; make port P1 as an input port MOV TMOD, #20H ; timer 1 in mode 2 for baud rate MOV TH1, #0FDH ; to set baud rate 9600 MOV SCON, #50H ; serial mode 1 MOV IE, #90H ; enable serial communication interrupt SETB TR1 ; start timer 1 for baud rate L1: MOV A, P1 ; get data from port P1 MOV SBUF, A ; send data serially MOV P2, A ; send data to the port P2 SJMP L1 ; repeat process ORG 0023H JB TI, TRANS ; check for TI flag bit CLR RI RETI TRANS: CLR TI RETI END Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 43 / 54
  • 44. Example - 8 Write an assembly language program to get data from port P1 and send it to the port P2 continuously, while sending; receive data from serial port and transfer to port P0. Assume that crystal frequency of 8051 is 11.0592 MHz; baud rate for the serial communication is 9600. Solution Step - I: Calculation of SCON Register SCON = 50h Step - II: Calculation of TMOD Register (Timer 1 in Mode 2 for Baud Rate TMOD = 20h Step - III: Calculation of TH1 Register for Baud Rate TH1 = FDh Step - IV: Calculation of IE Register IE = 90h Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 44 / 54
  • 45. Assembly Language Program ORG 0000H SJMP MAIN ORG 0030H MAIN: MOV P1, #0FFH ; make port P2 as an input port MOV TMOD, #20H ; timer 1 in mode 2 for baud rate MOV TH1, #0FDH ; to set baud rate 9600 MOV SCON, #50H ; serial mode 1 MOV IE, #90H ; enable serial communication interrupt SETB TR1 ; start timer 1 for baud rate L1: MOV A, P1 ; get data from port P1 MOV P2, A ; send data to the port P2 SJMP L1 ; repeat process ORG 0023H JB RI, RECEV CLR TI RETI RECEV: MOV A, SBUF MOV P0, A CLR RI RETI END Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 45 / 54
  • 46. Example - 9 Assume that INT0 pin is connected to a switch that is normally high. When- ever the switch goes low, it should turn ON LED. The LED is connected to port pin P1.4 and is normally OFF. When it is turned ON it should stay ON for a fraction of seconds. As long as switch is pressed low, the LED should stay ON. Solution Step - I: Calculation of IE Register IE = 81h Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 46 / 54
  • 47. Assembly Language Program ORG 0000H SJMP MAIN ORG 0030H MAIN: MOV IE, #81H HERE: SJMP HERE END ORG 0003H SETB P1.4 MOV R2, #0FFH REP: DJNZ R2, REP CLR P1.4 RETI Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 47 / 54
  • 48. Example - 10 Assume that INT1 pin is connected to a pulse generator; write a program in which the falling edge of the pulse will send a high to port pin P1.4, which is connected to an LED, i.e. LED is turned ON and OFF at the same rate as the pulses are applied to the INT1 pin. Solution Step - I: Calculation of IE Register IE = 84h Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 48 / 54
  • 49. Assembly Language Program ORG 0000H SJMP MAIN ORG 0030H MAIN: SETB TCON.2 ; Initialize INT1 edge triggered interrupt MOV IE, #84H HERE: SJMP HERE END Interrupt service routine (ISR) for hardware interrupt INT1 to turn ON LED ORG 0013H SETB P1.4 MOV R2, #0FFH REP: DJNZ R2, REP CLR P1.4 RETI Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 49 / 54
  • 50. Example - 11 Using interrupt, write an assembly language program to do the following (a) Receive data serially and send it to port P0 (b) Get data from port P1 and transferred serially and give a copy to port P2. (c) Make timer 0 in auto - reload mode to generate a square wave of 250 µs frequency on the port pin P0.7 Assume crystal frequency 11.0592 MHz and set baud rate for the serial communication is 4800. Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 50 / 54
  • 51. Solution Step - I: Calculation of TH1 Register for Baud Rate TH1 = FAh Step - II: Calculation of TH0 Register for 250 micro - sec time TON = TOFF = 125µs TH0 = 8Dh Step - III: Calculation of TMOD Register TMOD = 22h Step - IV: Calculation of SCON Register SCON = 50h Step - V: Calculation of IE Register IE = 92h Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 51 / 54
  • 52. Assembly Language Program ORG 0000H SJMP MAIN ; bypass vector location ORG 0030H MAIN: MOV P1, #0FFH ; make port P1 as an input port MOV TMOD, #22H ; Timer 0 in mode 2 for square wave ;and timer 1 in mode 2 for baud rate generation MOV TH0, #8DH ; load TH0 with auto - reload value MOV TH1, #0FAH ; load TH1 value for 4800 baud rate MOV SCON, #50H ; set serial mode 1 MOV IE, #92H ; enable serial communication and ; timer 0 interrupts SETB TR1 ; start timer 1 for baud rate SETB TR0 ; start timer 0 for square wave BACK: MOV A, P1 ; get data from port P1 until TF0 raised MOV P2, A ; send data from P1 to port P2 MOV SBUF, A ; transfers data serially SJMP BACK ; repeat the process Interrupt service routine (ISR) for timer 0 to generate square wave Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 52 / 54
  • 53. Assembly Language Program ORG 000BH CPL P0.7 ; interrupt routine of timer 0 CLR TF0 RETI ; return from interrupt Interrupt service routine (ISR) for serial port to check whether data is transmitted or received completely o ORG 0023H JB TI, TRANS MOV A, SBUF MOV P0, A CLR RI RETI TRANS: CLR TI RETI END Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 53 / 54
  • 54. Thank you Please send your feedback at nbahadure@gmail.com For more details and updates kindly visit https://sites.google.com/site/nileshbbahadure/home Main Slide Dr. Nilesh Bhaskarrao Bahadure () Unit - II (Part II) July 25, 2021 54 / 54