SlideShare a Scribd company logo
Interrupts in 8051
 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
 Whenever any device needs its service, the device notifies the
microcontroller by sending it an interrupt signal
 Upon receiving an interrupt signal, the microcontroller
interrupts whatever it is doing and serves the device
 The program which is associated with the interrupt is called
the interrupt service routine (ISR) or interrupt handler
 Polling
 The microcontroller continuously monitors the status of a given device
 When the conditions met, it performs the service
 After that, it moves on to monitor the next device until every one is
serviced
 Polling can monitor the status of several devices and serve each
of them as certain conditions are met
 The polling method is not efficient, since it wastes much of the
microcontroller’s time by polling devices that do not need service
 ex. JNB TF,target
 The advantage of interrupts is that the microcontroller
can serve many devices (not all at the same time)
 Each devices can get the attention of the
microcontroller based on the assigned priority
 For the polling method, it is not possible to assign priority
since it checks all devices in a round-robin fashion
 The microcontroller can also ignore (mask) a
device request for service
 This is not possible for the polling method
 For every interrupt, there must be an interrupt
service routine (ISR), or interrupt handler
 When an interrupt is invoked, the micro- controller
runs the interrupt service routine
 For every interrupt, there is a fixed location in
memory that holds the address of its ISR
 The group of memory locations set aside to hold the
addresses of ISRs is called interrupt vector table
 Upon activation of an interrupt, the microcontroller
goes through the following steps
1. It finishes the instruction it is executing and
saves the address of the next instruction (PC) on
the stack
2. It also saves the current status of all the interrupts
internally (i.e: not on the stack)
3. It jumps to a fixed location in memory, called the
interrupt vector table, that holds the address of
the ISR
4. The microcontroller gets the address of the ISR from
the interrupt vector table and jumps to it
 It starts to execute the interrupt service subroutine until it reaches
the last instruction of the subroutine which is RETI (return from
interrupt)
5. Upon executing the RETI instruction, the
microcontroller returns to the place where it was
interrupted
 First, it gets the program counter (PC) address from the stack
by popping the top two bytes of the stack into the PC
 Then it starts to execute from that address
 Six interrupts are allocated as follows
 Reset – power-up reset
 Two interrupts are set aside for the timers: one for timer
0 and one for timer 1
 Two interrupts are set aside for hardware external
interrupts
 P3.2 and P3.3 are for the external hardware interrupts INT0 (or
EX1), and INT1 (or EX2)
 Serial communication has a single interrupt that
belongs to both receive and transfer
Interrupt ROM
Location
(hex)
Name Pin Priority
Reset 0000 9 1
External HW (INT0) 0003 P3.2 (12) 2
Timer 0 (TF0) 000B 3
External HW (INT1) 0013 P3.3 (13) 4
Timer 1 (TF1) 001B 5
Serial COM (RI and TI) 0023 6
EA -- ET2 ES ET1 EX1 ET0 EX0
EA IE.7 Disables all interrupts
-- IE.6 Not implemented, reserved for future use
ET2 IE.5 Enables or disables timer 2 overflow or capture interrupt (8952)
ES IE.4 Enables or disables the serial port interrupt
ET1 IE.3 Enables or disables timer 1 overflow interrupt
EX1 IE.2 Enables or disables external interrupt 1
ET0 IE.1 Enables or disables timer 0 overflow interrupt
EX0 IE.0 Enables or disables external interrupt 0
IE (Interrupt Enable) Register
 The TCON register holds four of the interrupt
flags, in the 8051 the SCON register has the RI
and TI flags
Interrupt Flag SFR Register Bit
External 0 IE0 TCON.1
External 1 IE1 TCON.3
Timer 0 TF0 TCON.5
Timer 1 TF1 TCON.7
Serial Port TI SCON.1
Serial Port RI SCON.0
Interrupt flag bits
TCON SFR
IT1/IT0--- 0-> Level trigger (LOW LEVEL Trigger)
1-> Edge trigger (Falling edge Trigger)
 To enable an interrupt, we take the
following steps:
1. Bit D7 of the IE register (EA) must be set to
high to allow the rest of register to take
effect
2. The value of EA
 If EA = 1, interrupts are enabled and will be responded
to if their corresponding bits in IE are high
 If EA = 0, no interrupt will be responded to, even if the
associated bit in the IE register is high
Interrupt Priority Register (Bit-addressable)
D7 D0
Write a C program using interrupts to do the following:
(a) Generate a 10 KHz frequency on P2.1 using T0 8-bit auto-reload
(b) Use timer 1 as an event counter to count up a 1-Hz pulse and display it on
P0. The pulse is connected to EX1.
Assume that XTAL = 11.0592 MHz. Set the baud rate at 9600.
#include <reg51.h>
sbit WAVE = P2^1;
unsigned char cnt;
void timer0() interrupt 1
{
WAVE = ~WAVE;
}
void timer1() interrupt 3
{
cnt++;
P0 = cnt;
}
void main()
{
cnt = 0;
TMOD = 0x42;
TH0 = 0x46;
IE = 0x86;
TR0 = 1;
TR1 = 1;
while(1);
}
Write an 8051 C program to create a frequency of 2500 Hz
on pin P2.7. Use Timer 1, mode 2 to create delay.
1/2500 Hz = 400 μs
400 μs /2 = 200 μs
200 μs / 1.085 μs = 184
Solution
#include <reg51.h>
void T1M2Delay(void);
sbit mybit=P2^7;
void main(void)
{
unsigned char x;
while(1)
{
mybit=~mybit;
T1M2Delay();
}
}
void T1M2Delay(void)
{
TMOD=0x20;
TH1=-184;
TR1=1;
while(TF1==0);
TR1=0;
TF1=0;
}
Write a C program that continuously gets a single bit of data
from P1.7 and sends it to P1.0, while simultaneously
creating a square wave of 200 μs period on pin P2.5.
Use Timer 0 to create the square wave.
Assume that XTAL = 11.0592 MHz.
Solution:
We will use timer 0 mode 2 (auto-reload). One half of the
period is
100 μs. 100/1.085 μs = 92, and TH0 = 256 - 92 = 164 or A4H
#include <reg51.h>
sbit SW = P1^7;
sbit IND = P1^0;
sbit WAVE = P2^5;
void timer0(void) interrupt 1
{
WAVE = ~WAVE;
}
void main()
{
SW = 1;
TMOD = 0x02;
TH0 = 0xA4;
IE = 0x82;
TR0=1;
while(1)
{ IND = SW; }
}
Thank you

More Related Content

What's hot

Solution manual 8051 microcontroller by mazidi
Solution manual 8051 microcontroller by mazidiSolution manual 8051 microcontroller by mazidi
Solution manual 8051 microcontroller by mazidiMuhammad Abdullah
 
8051 timer counter
8051 timer counter8051 timer counter
8051 timer counter
vishalgohel12195
 
Interrupts in pic
Interrupts in picInterrupts in pic
Interrupts in pic
v Kalairajan
 
Sampling Theorem
Sampling TheoremSampling Theorem
Sampling Theorem
Dr Naim R Kidwai
 
Interrupts in 8051
Interrupts in 8051Interrupts in 8051
Interrupts in 8051
Sudhanshu Janwadkar
 
3. Concept of pole and zero.pptx
3. Concept of pole and zero.pptx3. Concept of pole and zero.pptx
3. Concept of pole and zero.pptx
AMSuryawanshi
 
Minimum mode and Maximum mode Configuration in 8086
Minimum mode and Maximum mode Configuration in 8086Minimum mode and Maximum mode Configuration in 8086
Minimum mode and Maximum mode Configuration in 8086
Jismy .K.Jose
 
Controllability and observability
Controllability and observabilityControllability and observability
Controllability and observability
jawaharramaya
 
Interrupt programming with 8051 microcontroller
Interrupt programming with 8051  microcontrollerInterrupt programming with 8051  microcontroller
Interrupt programming with 8051 microcontroller
Ankit Bhatnagar
 
Logical Instructions used in 8086 microprocessor
Logical Instructions used in 8086 microprocessorLogical Instructions used in 8086 microprocessor
Logical Instructions used in 8086 microprocessor
Rabin BK
 
PIC Microcontroller | ADC Interfacing
PIC Microcontroller | ADC InterfacingPIC Microcontroller | ADC Interfacing
PIC Microcontroller | ADC Interfacing
International Institute of Information Technology (I²IT)
 
Fir filter design using windows
Fir filter design using windowsFir filter design using windows
Fir filter design using windows
Sarang Joshi
 
Vhdl programming
Vhdl programmingVhdl programming
Vhdl programming
Yogesh Mashalkar
 
Microcontroller pic 16f877 addressing modes instructions and programming
Microcontroller pic 16f877 addressing modes instructions and programmingMicrocontroller pic 16f877 addressing modes instructions and programming
Microcontroller pic 16f877 addressing modes instructions and programming
Nilesh Bhaskarrao Bahadure
 
Timing diagram 8085 microprocessor
Timing diagram 8085 microprocessorTiming diagram 8085 microprocessor
Timing diagram 8085 microprocessor
Velalar College of Engineering and Technology
 
Four way traffic light conrol using Verilog
Four way traffic light conrol using VerilogFour way traffic light conrol using Verilog
Four way traffic light conrol using Verilog
Utkarsh De
 
Automatic Door Opener using PIR Sensor
Automatic Door Opener using PIR SensorAutomatic Door Opener using PIR Sensor
Automatic Door Opener using PIR Sensor
RAGHUVARMA09
 
Multipliers in VLSI
Multipliers in VLSIMultipliers in VLSI
Multipliers in VLSI
Kiranmai Sony
 
PIC Microcontrollers
PIC MicrocontrollersPIC Microcontrollers
PIC Microcontrollers
Abdullah Saghir Ahmad
 

What's hot (20)

Solution manual 8051 microcontroller by mazidi
Solution manual 8051 microcontroller by mazidiSolution manual 8051 microcontroller by mazidi
Solution manual 8051 microcontroller by mazidi
 
8051 timer counter
8051 timer counter8051 timer counter
8051 timer counter
 
Interrupts in pic
Interrupts in picInterrupts in pic
Interrupts in pic
 
Sampling Theorem
Sampling TheoremSampling Theorem
Sampling Theorem
 
Interrupts in 8051
Interrupts in 8051Interrupts in 8051
Interrupts in 8051
 
3. Concept of pole and zero.pptx
3. Concept of pole and zero.pptx3. Concept of pole and zero.pptx
3. Concept of pole and zero.pptx
 
Minimum mode and Maximum mode Configuration in 8086
Minimum mode and Maximum mode Configuration in 8086Minimum mode and Maximum mode Configuration in 8086
Minimum mode and Maximum mode Configuration in 8086
 
Controllability and observability
Controllability and observabilityControllability and observability
Controllability and observability
 
Timers
TimersTimers
Timers
 
Interrupt programming with 8051 microcontroller
Interrupt programming with 8051  microcontrollerInterrupt programming with 8051  microcontroller
Interrupt programming with 8051 microcontroller
 
Logical Instructions used in 8086 microprocessor
Logical Instructions used in 8086 microprocessorLogical Instructions used in 8086 microprocessor
Logical Instructions used in 8086 microprocessor
 
PIC Microcontroller | ADC Interfacing
PIC Microcontroller | ADC InterfacingPIC Microcontroller | ADC Interfacing
PIC Microcontroller | ADC Interfacing
 
Fir filter design using windows
Fir filter design using windowsFir filter design using windows
Fir filter design using windows
 
Vhdl programming
Vhdl programmingVhdl programming
Vhdl programming
 
Microcontroller pic 16f877 addressing modes instructions and programming
Microcontroller pic 16f877 addressing modes instructions and programmingMicrocontroller pic 16f877 addressing modes instructions and programming
Microcontroller pic 16f877 addressing modes instructions and programming
 
Timing diagram 8085 microprocessor
Timing diagram 8085 microprocessorTiming diagram 8085 microprocessor
Timing diagram 8085 microprocessor
 
Four way traffic light conrol using Verilog
Four way traffic light conrol using VerilogFour way traffic light conrol using Verilog
Four way traffic light conrol using Verilog
 
Automatic Door Opener using PIR Sensor
Automatic Door Opener using PIR SensorAutomatic Door Opener using PIR Sensor
Automatic Door Opener using PIR Sensor
 
Multipliers in VLSI
Multipliers in VLSIMultipliers in VLSI
Multipliers in VLSI
 
PIC Microcontrollers
PIC MicrocontrollersPIC Microcontrollers
PIC Microcontrollers
 

Similar to Interrupts programming in embedded C using 8051

Mc module5 ppt_msj
Mc module5 ppt_msjMc module5 ppt_msj
Mc module5 ppt_msj
mangala jolad
 
Micro controller 8051 Interrupts
Micro controller 8051 InterruptsMicro controller 8051 Interrupts
Micro controller 8051 Interrupts
dharmesh nakum
 
Interrupt in 8051
Interrupt in 8051Interrupt in 8051
Interrupt in 8051
ssuser3a47cb
 
Unit 3 timer and counter and there application .pptx
Unit 3 timer and counter and there application .pptxUnit 3 timer and counter and there application .pptx
Unit 3 timer and counter and there application .pptx
naveen088888
 
Microcontroller part 2
Microcontroller part 2Microcontroller part 2
Microcontroller part 2
Keroles karam khalil
 
DPA
DPADPA
Interrupt 8085
Interrupt 8085Interrupt 8085
Interrupt 8085
Shubham Singh
 
Embedded systems, lesson 16
Embedded systems, lesson 16Embedded systems, lesson 16
Embedded systems, lesson 16
REKHASENCHAgs0801bm1
 
AVR_Course_Day7 timers counters and interrupt programming
AVR_Course_Day7 timers counters and  interrupt programmingAVR_Course_Day7 timers counters and  interrupt programming
AVR_Course_Day7 timers counters and interrupt programming
Mohamed Ali
 
Chapter 4 - Interrupts of 8085
Chapter 4 - Interrupts of 8085Chapter 4 - Interrupts of 8085
Chapter 4 - Interrupts of 8085
Bisrat Girma
 
Timing n interrupt.pptx
Timing n interrupt.pptxTiming n interrupt.pptx
Timing n interrupt.pptx
JasaRChoudhary
 
8051 Inturrpt
8051 Inturrpt8051 Inturrpt
8051 Inturrpt
Ramasubbu .P
 
Interrupt programming
Interrupt programming Interrupt programming
Interrupt programming vijaydeepakg
 
Microchip NANOWatt Technology
Microchip NANOWatt TechnologyMicrochip NANOWatt Technology
Microchip NANOWatt Technology
Emanuele Bonanni
 
Interrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.kInterrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.k
Vijay Kumar
 
Interrupt in ATMEGA328P.pptx
Interrupt in ATMEGA328P.pptxInterrupt in ATMEGA328P.pptx
Interrupt in ATMEGA328P.pptx
SujalKumar73
 

Similar to Interrupts programming in embedded C using 8051 (20)

Mc module5 ppt_msj
Mc module5 ppt_msjMc module5 ppt_msj
Mc module5 ppt_msj
 
Micro controller 8051 Interrupts
Micro controller 8051 InterruptsMicro controller 8051 Interrupts
Micro controller 8051 Interrupts
 
Interrupt in 8051
Interrupt in 8051Interrupt in 8051
Interrupt in 8051
 
Unit 3 timer and counter and there application .pptx
Unit 3 timer and counter and there application .pptxUnit 3 timer and counter and there application .pptx
Unit 3 timer and counter and there application .pptx
 
Microcontroller part 2
Microcontroller part 2Microcontroller part 2
Microcontroller part 2
 
DPA
DPADPA
DPA
 
Interrupt
InterruptInterrupt
Interrupt
 
Interrupt 8085
Interrupt 8085Interrupt 8085
Interrupt 8085
 
Embedded systems, lesson 16
Embedded systems, lesson 16Embedded systems, lesson 16
Embedded systems, lesson 16
 
Interrupt
InterruptInterrupt
Interrupt
 
AVR_Course_Day7 timers counters and interrupt programming
AVR_Course_Day7 timers counters and  interrupt programmingAVR_Course_Day7 timers counters and  interrupt programming
AVR_Course_Day7 timers counters and interrupt programming
 
Chapter 4 - Interrupts of 8085
Chapter 4 - Interrupts of 8085Chapter 4 - Interrupts of 8085
Chapter 4 - Interrupts of 8085
 
Timing n interrupt.pptx
Timing n interrupt.pptxTiming n interrupt.pptx
Timing n interrupt.pptx
 
8051 Inturrpt
8051 Inturrpt8051 Inturrpt
8051 Inturrpt
 
Interrupt programming
Interrupt programming Interrupt programming
Interrupt programming
 
Microchip NANOWatt Technology
Microchip NANOWatt TechnologyMicrochip NANOWatt Technology
Microchip NANOWatt Technology
 
Interrupts
InterruptsInterrupts
Interrupts
 
lesson24.ppt
lesson24.pptlesson24.ppt
lesson24.ppt
 
Interrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.kInterrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.k
 
Interrupt in ATMEGA328P.pptx
Interrupt in ATMEGA328P.pptxInterrupt in ATMEGA328P.pptx
Interrupt in ATMEGA328P.pptx
 

More from Vikas Dongre

Lcd interfaing using 8051 and assambly language programming
Lcd interfaing using 8051 and assambly language programmingLcd interfaing using 8051 and assambly language programming
Lcd interfaing using 8051 and assambly language programming
Vikas Dongre
 
Job opportunities for electronics engineering
Job opportunities for electronics engineeringJob opportunities for electronics engineering
Job opportunities for electronics engineering
Vikas Dongre
 
Educational video creation: Tools and tips
Educational video creation: Tools and tipsEducational video creation: Tools and tips
Educational video creation: Tools and tips
Vikas Dongre
 
Scope of job education and business after HSC
Scope of job  education and business after HSCScope of job  education and business after HSC
Scope of job education and business after HSC
Vikas Dongre
 
Introduction to digital logic gates
Introduction to digital logic gatesIntroduction to digital logic gates
Introduction to digital logic gates
Vikas Dongre
 
Introduction to binary number system
Introduction to binary number systemIntroduction to binary number system
Introduction to binary number system
Vikas Dongre
 
Timer programming for 8051 using embedded c
Timer programming for 8051 using embedded cTimer programming for 8051 using embedded c
Timer programming for 8051 using embedded c
Vikas Dongre
 
Arithmetic and Logic instructions in Embedded C
Arithmetic and Logic instructions in Embedded CArithmetic and Logic instructions in Embedded C
Arithmetic and Logic instructions in Embedded C
Vikas Dongre
 
Introduction to Embedded system programming using 8051
Introduction to Embedded system programming using 8051Introduction to Embedded system programming using 8051
Introduction to Embedded system programming using 8051
Vikas Dongre
 
Arithmetic and logic operations in c
Arithmetic and logic operations in cArithmetic and logic operations in c
Arithmetic and logic operations in c
Vikas Dongre
 
Arithmetic and logic operations in c
Arithmetic and logic operations in cArithmetic and logic operations in c
Arithmetic and logic operations in c
Vikas Dongre
 
Classification of embedded systems
Classification of embedded systemsClassification of embedded systems
Classification of embedded systems
Vikas Dongre
 
Characteristics of embedded systems
Characteristics of embedded systemsCharacteristics of embedded systems
Characteristics of embedded systems
Vikas Dongre
 
Features of 89c51,pic,avr &amp; arm processors
Features of 89c51,pic,avr &amp; arm processorsFeatures of 89c51,pic,avr &amp; arm processors
Features of 89c51,pic,avr &amp; arm processors
Vikas Dongre
 
Microcontroller architecture
Microcontroller architectureMicrocontroller architecture
Microcontroller architecture
Vikas Dongre
 
2. block diagram and components of embedded system
2. block diagram and components of embedded system2. block diagram and components of embedded system
2. block diagram and components of embedded system
Vikas Dongre
 
1. advantages and applications of embedded system
1. advantages and applications of embedded system1. advantages and applications of embedded system
1. advantages and applications of embedded system
Vikas Dongre
 
Serial communication
Serial communicationSerial communication
Serial communication
Vikas Dongre
 
Innovative improvements in electronic engineering laboratory education using eml
Innovative improvements in electronic engineering laboratory education using emlInnovative improvements in electronic engineering laboratory education using eml
Innovative improvements in electronic engineering laboratory education using eml
Vikas Dongre
 
Devnagari handwritten numeral recognition using geometric features and statis...
Devnagari handwritten numeral recognition using geometric features and statis...Devnagari handwritten numeral recognition using geometric features and statis...
Devnagari handwritten numeral recognition using geometric features and statis...
Vikas Dongre
 

More from Vikas Dongre (20)

Lcd interfaing using 8051 and assambly language programming
Lcd interfaing using 8051 and assambly language programmingLcd interfaing using 8051 and assambly language programming
Lcd interfaing using 8051 and assambly language programming
 
Job opportunities for electronics engineering
Job opportunities for electronics engineeringJob opportunities for electronics engineering
Job opportunities for electronics engineering
 
Educational video creation: Tools and tips
Educational video creation: Tools and tipsEducational video creation: Tools and tips
Educational video creation: Tools and tips
 
Scope of job education and business after HSC
Scope of job  education and business after HSCScope of job  education and business after HSC
Scope of job education and business after HSC
 
Introduction to digital logic gates
Introduction to digital logic gatesIntroduction to digital logic gates
Introduction to digital logic gates
 
Introduction to binary number system
Introduction to binary number systemIntroduction to binary number system
Introduction to binary number system
 
Timer programming for 8051 using embedded c
Timer programming for 8051 using embedded cTimer programming for 8051 using embedded c
Timer programming for 8051 using embedded c
 
Arithmetic and Logic instructions in Embedded C
Arithmetic and Logic instructions in Embedded CArithmetic and Logic instructions in Embedded C
Arithmetic and Logic instructions in Embedded C
 
Introduction to Embedded system programming using 8051
Introduction to Embedded system programming using 8051Introduction to Embedded system programming using 8051
Introduction to Embedded system programming using 8051
 
Arithmetic and logic operations in c
Arithmetic and logic operations in cArithmetic and logic operations in c
Arithmetic and logic operations in c
 
Arithmetic and logic operations in c
Arithmetic and logic operations in cArithmetic and logic operations in c
Arithmetic and logic operations in c
 
Classification of embedded systems
Classification of embedded systemsClassification of embedded systems
Classification of embedded systems
 
Characteristics of embedded systems
Characteristics of embedded systemsCharacteristics of embedded systems
Characteristics of embedded systems
 
Features of 89c51,pic,avr &amp; arm processors
Features of 89c51,pic,avr &amp; arm processorsFeatures of 89c51,pic,avr &amp; arm processors
Features of 89c51,pic,avr &amp; arm processors
 
Microcontroller architecture
Microcontroller architectureMicrocontroller architecture
Microcontroller architecture
 
2. block diagram and components of embedded system
2. block diagram and components of embedded system2. block diagram and components of embedded system
2. block diagram and components of embedded system
 
1. advantages and applications of embedded system
1. advantages and applications of embedded system1. advantages and applications of embedded system
1. advantages and applications of embedded system
 
Serial communication
Serial communicationSerial communication
Serial communication
 
Innovative improvements in electronic engineering laboratory education using eml
Innovative improvements in electronic engineering laboratory education using emlInnovative improvements in electronic engineering laboratory education using eml
Innovative improvements in electronic engineering laboratory education using eml
 
Devnagari handwritten numeral recognition using geometric features and statis...
Devnagari handwritten numeral recognition using geometric features and statis...Devnagari handwritten numeral recognition using geometric features and statis...
Devnagari handwritten numeral recognition using geometric features and statis...
 

Recently uploaded

ppt on beauty of the nature by Palak.pptx
ppt on  beauty of the nature by Palak.pptxppt on  beauty of the nature by Palak.pptx
ppt on beauty of the nature by Palak.pptx
RaniJaiswal16
 
NRW Board Paper - DRAFT NRW Recreation Strategy
NRW Board Paper - DRAFT NRW Recreation StrategyNRW Board Paper - DRAFT NRW Recreation Strategy
NRW Board Paper - DRAFT NRW Recreation Strategy
Robin Grant
 
growbilliontrees.com-Trees for Granddaughter (1).pdf
growbilliontrees.com-Trees for Granddaughter (1).pdfgrowbilliontrees.com-Trees for Granddaughter (1).pdf
growbilliontrees.com-Trees for Granddaughter (1).pdf
yadavakashagra
 
Summary of the Climate and Energy Policy of Australia
Summary of the Climate and Energy Policy of AustraliaSummary of the Climate and Energy Policy of Australia
Summary of the Climate and Energy Policy of Australia
yasmindemoraes1
 
Presentación Giulio Quaggiotto-Diálogo improbable .pptx.pdf
Presentación Giulio Quaggiotto-Diálogo improbable .pptx.pdfPresentación Giulio Quaggiotto-Diálogo improbable .pptx.pdf
Presentación Giulio Quaggiotto-Diálogo improbable .pptx.pdf
Innovation and Technology for Development Centre
 
Navigating the complex landscape of AI governance
Navigating the complex landscape of AI governanceNavigating the complex landscape of AI governance
Navigating the complex landscape of AI governance
Piermenotti Mauro
 
AGRICULTURE Hydrophonic FERTILISER PPT.pptx
AGRICULTURE Hydrophonic FERTILISER PPT.pptxAGRICULTURE Hydrophonic FERTILISER PPT.pptx
AGRICULTURE Hydrophonic FERTILISER PPT.pptx
BanitaDsouza
 
UNDERSTANDING WHAT GREEN WASHING IS!.pdf
UNDERSTANDING WHAT GREEN WASHING IS!.pdfUNDERSTANDING WHAT GREEN WASHING IS!.pdf
UNDERSTANDING WHAT GREEN WASHING IS!.pdf
JulietMogola
 
Characterization and the Kinetics of drying at the drying oven and with micro...
Characterization and the Kinetics of drying at the drying oven and with micro...Characterization and the Kinetics of drying at the drying oven and with micro...
Characterization and the Kinetics of drying at the drying oven and with micro...
Open Access Research Paper
 
Artificial Reefs by Kuddle Life Foundation - May 2024
Artificial Reefs by Kuddle Life Foundation - May 2024Artificial Reefs by Kuddle Life Foundation - May 2024
Artificial Reefs by Kuddle Life Foundation - May 2024
punit537210
 
How about Huawei mobile phone-www.cfye-commerce.shop
How about Huawei mobile phone-www.cfye-commerce.shopHow about Huawei mobile phone-www.cfye-commerce.shop
How about Huawei mobile phone-www.cfye-commerce.shop
laozhuseo02
 
一比一原版(UMTC毕业证书)明尼苏达大学双城分校毕业证如何办理
一比一原版(UMTC毕业证书)明尼苏达大学双城分校毕业证如何办理一比一原版(UMTC毕业证书)明尼苏达大学双城分校毕业证如何办理
一比一原版(UMTC毕业证书)明尼苏达大学双城分校毕业证如何办理
zm9ajxup
 
Alert-driven Community-based Forest monitoring: A case of the Peruvian Amazon
Alert-driven Community-based Forest monitoring: A case of the Peruvian AmazonAlert-driven Community-based Forest monitoring: A case of the Peruvian Amazon
Alert-driven Community-based Forest monitoring: A case of the Peruvian Amazon
CIFOR-ICRAF
 
Sustainable farming practices in India .pptx
Sustainable farming  practices in India .pptxSustainable farming  practices in India .pptx
Sustainable farming practices in India .pptx
chaitaliambole
 
Willie Nelson Net Worth: A Journey Through Music, Movies, and Business Ventures
Willie Nelson Net Worth: A Journey Through Music, Movies, and Business VenturesWillie Nelson Net Worth: A Journey Through Music, Movies, and Business Ventures
Willie Nelson Net Worth: A Journey Through Music, Movies, and Business Ventures
greendigital
 
Celebrating World-environment-day-2024.pdf
Celebrating  World-environment-day-2024.pdfCelebrating  World-environment-day-2024.pdf
Celebrating World-environment-day-2024.pdf
rohankumarsinghrore1
 
DRAFT NRW Recreation Strategy - People and Nature thriving together
DRAFT NRW Recreation Strategy - People and Nature thriving togetherDRAFT NRW Recreation Strategy - People and Nature thriving together
DRAFT NRW Recreation Strategy - People and Nature thriving together
Robin Grant
 
Sustainable Rain water harvesting in india.ppt
Sustainable Rain water harvesting in india.pptSustainable Rain water harvesting in india.ppt
Sustainable Rain water harvesting in india.ppt
chaitaliambole
 
Environmental Science Book By Dr. Y.K. Singh
Environmental Science Book By Dr. Y.K. SinghEnvironmental Science Book By Dr. Y.K. Singh
Environmental Science Book By Dr. Y.K. Singh
AhmadKhan917612
 
Daan Park Hydrangea flower season I like it
Daan Park Hydrangea flower season I like itDaan Park Hydrangea flower season I like it
Daan Park Hydrangea flower season I like it
a0966109726
 

Recently uploaded (20)

ppt on beauty of the nature by Palak.pptx
ppt on  beauty of the nature by Palak.pptxppt on  beauty of the nature by Palak.pptx
ppt on beauty of the nature by Palak.pptx
 
NRW Board Paper - DRAFT NRW Recreation Strategy
NRW Board Paper - DRAFT NRW Recreation StrategyNRW Board Paper - DRAFT NRW Recreation Strategy
NRW Board Paper - DRAFT NRW Recreation Strategy
 
growbilliontrees.com-Trees for Granddaughter (1).pdf
growbilliontrees.com-Trees for Granddaughter (1).pdfgrowbilliontrees.com-Trees for Granddaughter (1).pdf
growbilliontrees.com-Trees for Granddaughter (1).pdf
 
Summary of the Climate and Energy Policy of Australia
Summary of the Climate and Energy Policy of AustraliaSummary of the Climate and Energy Policy of Australia
Summary of the Climate and Energy Policy of Australia
 
Presentación Giulio Quaggiotto-Diálogo improbable .pptx.pdf
Presentación Giulio Quaggiotto-Diálogo improbable .pptx.pdfPresentación Giulio Quaggiotto-Diálogo improbable .pptx.pdf
Presentación Giulio Quaggiotto-Diálogo improbable .pptx.pdf
 
Navigating the complex landscape of AI governance
Navigating the complex landscape of AI governanceNavigating the complex landscape of AI governance
Navigating the complex landscape of AI governance
 
AGRICULTURE Hydrophonic FERTILISER PPT.pptx
AGRICULTURE Hydrophonic FERTILISER PPT.pptxAGRICULTURE Hydrophonic FERTILISER PPT.pptx
AGRICULTURE Hydrophonic FERTILISER PPT.pptx
 
UNDERSTANDING WHAT GREEN WASHING IS!.pdf
UNDERSTANDING WHAT GREEN WASHING IS!.pdfUNDERSTANDING WHAT GREEN WASHING IS!.pdf
UNDERSTANDING WHAT GREEN WASHING IS!.pdf
 
Characterization and the Kinetics of drying at the drying oven and with micro...
Characterization and the Kinetics of drying at the drying oven and with micro...Characterization and the Kinetics of drying at the drying oven and with micro...
Characterization and the Kinetics of drying at the drying oven and with micro...
 
Artificial Reefs by Kuddle Life Foundation - May 2024
Artificial Reefs by Kuddle Life Foundation - May 2024Artificial Reefs by Kuddle Life Foundation - May 2024
Artificial Reefs by Kuddle Life Foundation - May 2024
 
How about Huawei mobile phone-www.cfye-commerce.shop
How about Huawei mobile phone-www.cfye-commerce.shopHow about Huawei mobile phone-www.cfye-commerce.shop
How about Huawei mobile phone-www.cfye-commerce.shop
 
一比一原版(UMTC毕业证书)明尼苏达大学双城分校毕业证如何办理
一比一原版(UMTC毕业证书)明尼苏达大学双城分校毕业证如何办理一比一原版(UMTC毕业证书)明尼苏达大学双城分校毕业证如何办理
一比一原版(UMTC毕业证书)明尼苏达大学双城分校毕业证如何办理
 
Alert-driven Community-based Forest monitoring: A case of the Peruvian Amazon
Alert-driven Community-based Forest monitoring: A case of the Peruvian AmazonAlert-driven Community-based Forest monitoring: A case of the Peruvian Amazon
Alert-driven Community-based Forest monitoring: A case of the Peruvian Amazon
 
Sustainable farming practices in India .pptx
Sustainable farming  practices in India .pptxSustainable farming  practices in India .pptx
Sustainable farming practices in India .pptx
 
Willie Nelson Net Worth: A Journey Through Music, Movies, and Business Ventures
Willie Nelson Net Worth: A Journey Through Music, Movies, and Business VenturesWillie Nelson Net Worth: A Journey Through Music, Movies, and Business Ventures
Willie Nelson Net Worth: A Journey Through Music, Movies, and Business Ventures
 
Celebrating World-environment-day-2024.pdf
Celebrating  World-environment-day-2024.pdfCelebrating  World-environment-day-2024.pdf
Celebrating World-environment-day-2024.pdf
 
DRAFT NRW Recreation Strategy - People and Nature thriving together
DRAFT NRW Recreation Strategy - People and Nature thriving togetherDRAFT NRW Recreation Strategy - People and Nature thriving together
DRAFT NRW Recreation Strategy - People and Nature thriving together
 
Sustainable Rain water harvesting in india.ppt
Sustainable Rain water harvesting in india.pptSustainable Rain water harvesting in india.ppt
Sustainable Rain water harvesting in india.ppt
 
Environmental Science Book By Dr. Y.K. Singh
Environmental Science Book By Dr. Y.K. SinghEnvironmental Science Book By Dr. Y.K. Singh
Environmental Science Book By Dr. Y.K. Singh
 
Daan Park Hydrangea flower season I like it
Daan Park Hydrangea flower season I like itDaan Park Hydrangea flower season I like it
Daan Park Hydrangea flower season I like it
 

Interrupts programming in embedded C using 8051

  • 2.  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  Whenever any device needs its service, the device notifies the microcontroller by sending it an interrupt signal  Upon receiving an interrupt signal, the microcontroller interrupts whatever it is doing and serves the device  The program which is associated with the interrupt is called the interrupt service routine (ISR) or interrupt handler
  • 3.  Polling  The microcontroller continuously monitors the status of a given device  When the conditions met, it performs the service  After that, it moves on to monitor the next device until every one is serviced  Polling can monitor the status of several devices and serve each of them as certain conditions are met  The polling method is not efficient, since it wastes much of the microcontroller’s time by polling devices that do not need service  ex. JNB TF,target
  • 4.  The advantage of interrupts is that the microcontroller can serve many devices (not all at the same time)  Each devices can get the attention of the microcontroller based on the assigned priority  For the polling method, it is not possible to assign priority since it checks all devices in a round-robin fashion  The microcontroller can also ignore (mask) a device request for service  This is not possible for the polling method
  • 5.  For every interrupt, there must be an interrupt service routine (ISR), or interrupt handler  When an interrupt is invoked, the micro- controller runs the interrupt service routine  For every interrupt, there is a fixed location in memory that holds the address of its ISR  The group of memory locations set aside to hold the addresses of ISRs is called interrupt vector table
  • 6.  Upon activation of an interrupt, the microcontroller goes through the following steps 1. It finishes the instruction it is executing and saves the address of the next instruction (PC) on the stack 2. It also saves the current status of all the interrupts internally (i.e: not on the stack) 3. It jumps to a fixed location in memory, called the interrupt vector table, that holds the address of the ISR
  • 7. 4. The microcontroller gets the address of the ISR from the interrupt vector table and jumps to it  It starts to execute the interrupt service subroutine until it reaches the last instruction of the subroutine which is RETI (return from interrupt) 5. Upon executing the RETI instruction, the microcontroller returns to the place where it was interrupted  First, it gets the program counter (PC) address from the stack by popping the top two bytes of the stack into the PC  Then it starts to execute from that address
  • 8.  Six interrupts are allocated as follows  Reset – power-up reset  Two interrupts are set aside for the timers: one for timer 0 and one for timer 1  Two interrupts are set aside for hardware external interrupts  P3.2 and P3.3 are for the external hardware interrupts INT0 (or EX1), and INT1 (or EX2)  Serial communication has a single interrupt that belongs to both receive and transfer
  • 9. Interrupt ROM Location (hex) Name Pin Priority Reset 0000 9 1 External HW (INT0) 0003 P3.2 (12) 2 Timer 0 (TF0) 000B 3 External HW (INT1) 0013 P3.3 (13) 4 Timer 1 (TF1) 001B 5 Serial COM (RI and TI) 0023 6
  • 10. EA -- ET2 ES ET1 EX1 ET0 EX0 EA IE.7 Disables all interrupts -- IE.6 Not implemented, reserved for future use ET2 IE.5 Enables or disables timer 2 overflow or capture interrupt (8952) ES IE.4 Enables or disables the serial port interrupt ET1 IE.3 Enables or disables timer 1 overflow interrupt EX1 IE.2 Enables or disables external interrupt 1 ET0 IE.1 Enables or disables timer 0 overflow interrupt EX0 IE.0 Enables or disables external interrupt 0 IE (Interrupt Enable) Register
  • 11.  The TCON register holds four of the interrupt flags, in the 8051 the SCON register has the RI and TI flags Interrupt Flag SFR Register Bit External 0 IE0 TCON.1 External 1 IE1 TCON.3 Timer 0 TF0 TCON.5 Timer 1 TF1 TCON.7 Serial Port TI SCON.1 Serial Port RI SCON.0 Interrupt flag bits
  • 13. IT1/IT0--- 0-> Level trigger (LOW LEVEL Trigger) 1-> Edge trigger (Falling edge Trigger)
  • 14.  To enable an interrupt, we take the following steps: 1. Bit D7 of the IE register (EA) must be set to high to allow the rest of register to take effect 2. The value of EA  If EA = 1, interrupts are enabled and will be responded to if their corresponding bits in IE are high  If EA = 0, no interrupt will be responded to, even if the associated bit in the IE register is high
  • 15. Interrupt Priority Register (Bit-addressable) D7 D0
  • 16. Write a C program using interrupts to do the following: (a) Generate a 10 KHz frequency on P2.1 using T0 8-bit auto-reload (b) Use timer 1 as an event counter to count up a 1-Hz pulse and display it on P0. The pulse is connected to EX1. Assume that XTAL = 11.0592 MHz. Set the baud rate at 9600.
  • 17. #include <reg51.h> sbit WAVE = P2^1; unsigned char cnt; void timer0() interrupt 1 { WAVE = ~WAVE; } void timer1() interrupt 3 { cnt++; P0 = cnt; } void main() { cnt = 0; TMOD = 0x42; TH0 = 0x46; IE = 0x86; TR0 = 1; TR1 = 1; while(1); }
  • 18. Write an 8051 C program to create a frequency of 2500 Hz on pin P2.7. Use Timer 1, mode 2 to create delay. 1/2500 Hz = 400 μs 400 μs /2 = 200 μs 200 μs / 1.085 μs = 184 Solution
  • 19. #include <reg51.h> void T1M2Delay(void); sbit mybit=P2^7; void main(void) { unsigned char x; while(1) { mybit=~mybit; T1M2Delay(); } } void T1M2Delay(void) { TMOD=0x20; TH1=-184; TR1=1; while(TF1==0); TR1=0; TF1=0; }
  • 20. Write a C program that continuously gets a single bit of data from P1.7 and sends it to P1.0, while simultaneously creating a square wave of 200 μs period on pin P2.5. Use Timer 0 to create the square wave. Assume that XTAL = 11.0592 MHz. Solution: We will use timer 0 mode 2 (auto-reload). One half of the period is 100 μs. 100/1.085 μs = 92, and TH0 = 256 - 92 = 164 or A4H
  • 21. #include <reg51.h> sbit SW = P1^7; sbit IND = P1^0; sbit WAVE = P2^5; void timer0(void) interrupt 1 { WAVE = ~WAVE; } void main() { SW = 1; TMOD = 0x02; TH0 = 0xA4; IE = 0x82; TR0=1; while(1) { IND = SW; } }