SlideShare ist ein Scribd-Unternehmen logo
1 von 22
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

Weitere ähnliche Inhalte

Was ist angesagt?

COMPUTER INSTRUCTIONS & TIMING & CONTROL.
COMPUTER INSTRUCTIONS & TIMING & CONTROL.COMPUTER INSTRUCTIONS & TIMING & CONTROL.
COMPUTER INSTRUCTIONS & TIMING & CONTROL.ATUL KUMAR YADAV
 
8085 interfacing with memory chips
8085 interfacing with memory chips8085 interfacing with memory chips
8085 interfacing with memory chipsSrikrishna Thota
 
8086 modes
8086 modes8086 modes
8086 modesPDFSHARE
 
Interrupt programming with 8051 microcontroller
Interrupt programming with 8051  microcontrollerInterrupt programming with 8051  microcontroller
Interrupt programming with 8051 microcontrollerAnkit Bhatnagar
 
Counters &amp; time delay
Counters &amp; time delayCounters &amp; time delay
Counters &amp; time delayHemant Chetwani
 
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 KawareProf. Swapnil V. Kaware
 
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.kVijay Kumar
 
Architecture of 8085 microprocessor
Architecture of 8085 microprocessorArchitecture of 8085 microprocessor
Architecture of 8085 microprocessorAMAN SRIVASTAVA
 
Pin configuration of 8085
Pin configuration of 8085Pin configuration of 8085
Pin configuration of 808582338476
 
8085 microprocessor ramesh gaonkar
8085 microprocessor   ramesh gaonkar8085 microprocessor   ramesh gaonkar
8085 microprocessor ramesh gaonkarSAQUIB AHMAD
 
8051 microcontroller and it’s interface
8051 microcontroller and it’s interface8051 microcontroller and it’s interface
8051 microcontroller and it’s interfaceAbhishek Choksi
 
Architecture of 8086 microprocessor
Architecture of  8086 microprocessorArchitecture of  8086 microprocessor
Architecture of 8086 microprocessorAnirban Saha Anik
 

Was ist angesagt? (20)

Interrupts in 8051
Interrupts in 8051Interrupts in 8051
Interrupts in 8051
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
 
COMPUTER INSTRUCTIONS & TIMING & CONTROL.
COMPUTER INSTRUCTIONS & TIMING & CONTROL.COMPUTER INSTRUCTIONS & TIMING & CONTROL.
COMPUTER INSTRUCTIONS & TIMING & CONTROL.
 
8085 interfacing with memory chips
8085 interfacing with memory chips8085 interfacing with memory chips
8085 interfacing with memory chips
 
8086 modes
8086 modes8086 modes
8086 modes
 
8051 timer counter
8051 timer counter8051 timer counter
8051 timer counter
 
Interrupts in pic
Interrupts in picInterrupts in pic
Interrupts in pic
 
Interrupt programming with 8051 microcontroller
Interrupt programming with 8051  microcontrollerInterrupt programming with 8051  microcontroller
Interrupt programming with 8051 microcontroller
 
Counters &amp; time delay
Counters &amp; time delayCounters &amp; time delay
Counters &amp; time delay
 
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
 
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
 
Architecture of 8085 microprocessor
Architecture of 8085 microprocessorArchitecture of 8085 microprocessor
Architecture of 8085 microprocessor
 
Pin diagram 8085
Pin diagram 8085 Pin diagram 8085
Pin diagram 8085
 
8085 MICROPROCESSOR
8085 MICROPROCESSOR 8085 MICROPROCESSOR
8085 MICROPROCESSOR
 
8051 Inturrpt
8051 Inturrpt8051 Inturrpt
8051 Inturrpt
 
Pin configuration of 8085
Pin configuration of 8085Pin configuration of 8085
Pin configuration of 8085
 
8085 microprocessor ramesh gaonkar
8085 microprocessor   ramesh gaonkar8085 microprocessor   ramesh gaonkar
8085 microprocessor ramesh gaonkar
 
Instruction formats-in-8086
Instruction formats-in-8086Instruction formats-in-8086
Instruction formats-in-8086
 
8051 microcontroller and it’s interface
8051 microcontroller and it’s interface8051 microcontroller and it’s interface
8051 microcontroller and it’s interface
 
Architecture of 8086 microprocessor
Architecture of  8086 microprocessorArchitecture of  8086 microprocessor
Architecture of 8086 microprocessor
 

Ähnlich wie Interrupts programming in embedded C using 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 .pptxnaveen088888
 
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 programmingMohamed Ali
 
Chapter 4 - Interrupts of 8085
Chapter 4 - Interrupts of 8085Chapter 4 - Interrupts of 8085
Chapter 4 - Interrupts of 8085Bisrat Girma
 
Timing n interrupt.pptx
Timing n interrupt.pptxTiming n interrupt.pptx
Timing n interrupt.pptxJasaRChoudhary
 
Interrupt programming
Interrupt programming Interrupt programming
Interrupt programming vijaydeepakg
 
Microchip NANOWatt Technology
Microchip NANOWatt TechnologyMicrochip NANOWatt Technology
Microchip NANOWatt TechnologyEmanuele Bonanni
 
Interrupt in ATMEGA328P.pptx
Interrupt in ATMEGA328P.pptxInterrupt in ATMEGA328P.pptx
Interrupt in ATMEGA328P.pptxSujalKumar73
 
Types of Interrupts with details Mi ppt
Types of Interrupts with details Mi pptTypes of Interrupts with details Mi ppt
Types of Interrupts with details Mi pptsanjaytron
 

Ähnlich wie Interrupts programming in embedded C using 8051 (20)

Mc module5 ppt_msj
Mc module5 ppt_msjMc module5 ppt_msj
Mc module5 ppt_msj
 
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
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
 
8051 interrupts
8051 interrupts8051 interrupts
8051 interrupts
 
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
 
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
 
Interrupt in ATMEGA328P.pptx
Interrupt in ATMEGA328P.pptxInterrupt in ATMEGA328P.pptx
Interrupt in ATMEGA328P.pptx
 
Types of Interrupts with details Mi ppt
Types of Interrupts with details Mi pptTypes of Interrupts with details Mi ppt
Types of Interrupts with details Mi ppt
 

Mehr von 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 programmingVikas Dongre
 
Job opportunities for electronics engineering
Job opportunities for electronics engineeringJob opportunities for electronics engineering
Job opportunities for electronics engineeringVikas Dongre
 
Educational video creation: Tools and tips
Educational video creation: Tools and tipsEducational video creation: Tools and tips
Educational video creation: Tools and tipsVikas 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 HSCVikas Dongre
 
Introduction to digital logic gates
Introduction to digital logic gatesIntroduction to digital logic gates
Introduction to digital logic gatesVikas Dongre
 
Introduction to binary number system
Introduction to binary number systemIntroduction to binary number system
Introduction to binary number systemVikas 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 cVikas 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 CVikas 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 8051Vikas Dongre
 
Arithmetic and logic operations in c
Arithmetic and logic operations in cArithmetic and logic operations in c
Arithmetic and logic operations in cVikas Dongre
 
Arithmetic and logic operations in c
Arithmetic and logic operations in cArithmetic and logic operations in c
Arithmetic and logic operations in cVikas Dongre
 
Classification of embedded systems
Classification of embedded systemsClassification of embedded systems
Classification of embedded systemsVikas Dongre
 
Characteristics of embedded systems
Characteristics of embedded systemsCharacteristics of embedded systems
Characteristics of embedded systemsVikas 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 processorsVikas Dongre
 
Microcontroller architecture
Microcontroller architectureMicrocontroller architecture
Microcontroller architectureVikas 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 systemVikas 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 systemVikas Dongre
 
Serial communication
Serial communicationSerial communication
Serial communicationVikas 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 emlVikas 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
 

Mehr von 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...
 

Kürzlich hochgeladen

(DIYA) Call Girls Sinhagad Road ( 7001035870 ) HI-Fi Pune Escorts Service
(DIYA) Call Girls Sinhagad Road ( 7001035870 ) HI-Fi Pune Escorts Service(DIYA) Call Girls Sinhagad Road ( 7001035870 ) HI-Fi Pune Escorts Service
(DIYA) Call Girls Sinhagad Road ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
VIP Call Girl Gorakhpur Aashi 8250192130 Independent Escort Service Gorakhpur
VIP Call Girl Gorakhpur Aashi 8250192130 Independent Escort Service GorakhpurVIP Call Girl Gorakhpur Aashi 8250192130 Independent Escort Service Gorakhpur
VIP Call Girl Gorakhpur Aashi 8250192130 Independent Escort Service GorakhpurSuhani Kapoor
 
Horizon Net Zero Dawn – keynote slides by Ben Abraham
Horizon Net Zero Dawn – keynote slides by Ben AbrahamHorizon Net Zero Dawn – keynote slides by Ben Abraham
Horizon Net Zero Dawn – keynote slides by Ben Abrahamssuserbb03ff
 
Call Girls In Faridabad(Ballabgarh) Book ☎ 8168257667, @4999
Call Girls In Faridabad(Ballabgarh) Book ☎ 8168257667, @4999Call Girls In Faridabad(Ballabgarh) Book ☎ 8168257667, @4999
Call Girls In Faridabad(Ballabgarh) Book ☎ 8168257667, @4999Tina Ji
 
VIP Call Girls Service Bandlaguda Hyderabad Call +91-8250192130
VIP Call Girls Service Bandlaguda Hyderabad Call +91-8250192130VIP Call Girls Service Bandlaguda Hyderabad Call +91-8250192130
VIP Call Girls Service Bandlaguda Hyderabad Call +91-8250192130Suhani Kapoor
 
Russian Call Girls Nashik Anjali 7001305949 Independent Escort Service Nashik
Russian Call Girls Nashik Anjali 7001305949 Independent Escort Service NashikRussian Call Girls Nashik Anjali 7001305949 Independent Escort Service Nashik
Russian Call Girls Nashik Anjali 7001305949 Independent Escort Service Nashikranjana rawat
 
(NANDITA) Hadapsar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune ...
(NANDITA) Hadapsar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune ...(NANDITA) Hadapsar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune ...
(NANDITA) Hadapsar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune ...ranjana rawat
 
VIP Call Girls Saharanpur Aaradhya 8250192130 Independent Escort Service Saha...
VIP Call Girls Saharanpur Aaradhya 8250192130 Independent Escort Service Saha...VIP Call Girls Saharanpur Aaradhya 8250192130 Independent Escort Service Saha...
VIP Call Girls Saharanpur Aaradhya 8250192130 Independent Escort Service Saha...Suhani Kapoor
 
(ANAYA) Call Girls Hadapsar ( 7001035870 ) HI-Fi Pune Escorts Service
(ANAYA) Call Girls Hadapsar ( 7001035870 ) HI-Fi Pune Escorts Service(ANAYA) Call Girls Hadapsar ( 7001035870 ) HI-Fi Pune Escorts Service
(ANAYA) Call Girls Hadapsar ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Call Girls Budhwar Peth Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Budhwar Peth Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Budhwar Peth Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Budhwar Peth Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Contact Number Call Girls Service In Goa 9316020077 Goa Call Girls Service
Contact Number Call Girls Service In Goa  9316020077 Goa  Call Girls ServiceContact Number Call Girls Service In Goa  9316020077 Goa  Call Girls Service
Contact Number Call Girls Service In Goa 9316020077 Goa Call Girls Servicesexy call girls service in goa
 
Sustainable Clothing Strategies and Challenges
Sustainable Clothing Strategies and ChallengesSustainable Clothing Strategies and Challenges
Sustainable Clothing Strategies and ChallengesDr. Salem Baidas
 
(PARI) Viman Nagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune ...
(PARI) Viman Nagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune ...(PARI) Viman Nagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune ...
(PARI) Viman Nagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune ...ranjana rawat
 
Freegle User Survey as visual display - BH
Freegle User Survey as visual display - BHFreegle User Survey as visual display - BH
Freegle User Survey as visual display - BHbill846304
 
(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 

Kürzlich hochgeladen (20)

9953056974 ,Low Rate Call Girls In Adarsh Nagar Delhi 24hrs Available
9953056974 ,Low Rate Call Girls In Adarsh Nagar  Delhi 24hrs Available9953056974 ,Low Rate Call Girls In Adarsh Nagar  Delhi 24hrs Available
9953056974 ,Low Rate Call Girls In Adarsh Nagar Delhi 24hrs Available
 
(DIYA) Call Girls Sinhagad Road ( 7001035870 ) HI-Fi Pune Escorts Service
(DIYA) Call Girls Sinhagad Road ( 7001035870 ) HI-Fi Pune Escorts Service(DIYA) Call Girls Sinhagad Road ( 7001035870 ) HI-Fi Pune Escorts Service
(DIYA) Call Girls Sinhagad Road ( 7001035870 ) HI-Fi Pune Escorts Service
 
VIP Call Girl Gorakhpur Aashi 8250192130 Independent Escort Service Gorakhpur
VIP Call Girl Gorakhpur Aashi 8250192130 Independent Escort Service GorakhpurVIP Call Girl Gorakhpur Aashi 8250192130 Independent Escort Service Gorakhpur
VIP Call Girl Gorakhpur Aashi 8250192130 Independent Escort Service Gorakhpur
 
Horizon Net Zero Dawn – keynote slides by Ben Abraham
Horizon Net Zero Dawn – keynote slides by Ben AbrahamHorizon Net Zero Dawn – keynote slides by Ben Abraham
Horizon Net Zero Dawn – keynote slides by Ben Abraham
 
E Waste Management
E Waste ManagementE Waste Management
E Waste Management
 
young Whatsapp Call Girls in Delhi Cantt🔝 9953056974 🔝 escort service
young Whatsapp Call Girls in Delhi Cantt🔝 9953056974 🔝 escort serviceyoung Whatsapp Call Girls in Delhi Cantt🔝 9953056974 🔝 escort service
young Whatsapp Call Girls in Delhi Cantt🔝 9953056974 🔝 escort service
 
Gandhi Nagar (Delhi) 9953330565 Escorts, Call Girls Services
Gandhi Nagar (Delhi) 9953330565 Escorts, Call Girls ServicesGandhi Nagar (Delhi) 9953330565 Escorts, Call Girls Services
Gandhi Nagar (Delhi) 9953330565 Escorts, Call Girls Services
 
Green Banking
Green Banking Green Banking
Green Banking
 
Call Girls In Faridabad(Ballabgarh) Book ☎ 8168257667, @4999
Call Girls In Faridabad(Ballabgarh) Book ☎ 8168257667, @4999Call Girls In Faridabad(Ballabgarh) Book ☎ 8168257667, @4999
Call Girls In Faridabad(Ballabgarh) Book ☎ 8168257667, @4999
 
VIP Call Girls Service Bandlaguda Hyderabad Call +91-8250192130
VIP Call Girls Service Bandlaguda Hyderabad Call +91-8250192130VIP Call Girls Service Bandlaguda Hyderabad Call +91-8250192130
VIP Call Girls Service Bandlaguda Hyderabad Call +91-8250192130
 
Russian Call Girls Nashik Anjali 7001305949 Independent Escort Service Nashik
Russian Call Girls Nashik Anjali 7001305949 Independent Escort Service NashikRussian Call Girls Nashik Anjali 7001305949 Independent Escort Service Nashik
Russian Call Girls Nashik Anjali 7001305949 Independent Escort Service Nashik
 
(NANDITA) Hadapsar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune ...
(NANDITA) Hadapsar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune ...(NANDITA) Hadapsar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune ...
(NANDITA) Hadapsar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune ...
 
VIP Call Girls Saharanpur Aaradhya 8250192130 Independent Escort Service Saha...
VIP Call Girls Saharanpur Aaradhya 8250192130 Independent Escort Service Saha...VIP Call Girls Saharanpur Aaradhya 8250192130 Independent Escort Service Saha...
VIP Call Girls Saharanpur Aaradhya 8250192130 Independent Escort Service Saha...
 
(ANAYA) Call Girls Hadapsar ( 7001035870 ) HI-Fi Pune Escorts Service
(ANAYA) Call Girls Hadapsar ( 7001035870 ) HI-Fi Pune Escorts Service(ANAYA) Call Girls Hadapsar ( 7001035870 ) HI-Fi Pune Escorts Service
(ANAYA) Call Girls Hadapsar ( 7001035870 ) HI-Fi Pune Escorts Service
 
Call Girls Budhwar Peth Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Budhwar Peth Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Budhwar Peth Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Budhwar Peth Call Me 7737669865 Budget Friendly No Advance Booking
 
Contact Number Call Girls Service In Goa 9316020077 Goa Call Girls Service
Contact Number Call Girls Service In Goa  9316020077 Goa  Call Girls ServiceContact Number Call Girls Service In Goa  9316020077 Goa  Call Girls Service
Contact Number Call Girls Service In Goa 9316020077 Goa Call Girls Service
 
Sustainable Clothing Strategies and Challenges
Sustainable Clothing Strategies and ChallengesSustainable Clothing Strategies and Challenges
Sustainable Clothing Strategies and Challenges
 
(PARI) Viman Nagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune ...
(PARI) Viman Nagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune ...(PARI) Viman Nagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune ...
(PARI) Viman Nagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune ...
 
Freegle User Survey as visual display - BH
Freegle User Survey as visual display - BHFreegle User Survey as visual display - BH
Freegle User Survey as visual display - BH
 
(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 

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; } }