SlideShare a Scribd company logo
16
Most read
17
Most read
21
Most read
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 (20)

PPT
Interfacing of io device to 8085
Nitin Ahire
 
PPTX
Microcontroller presentation
xavierpaulino
 
PPT
Memory organization of 8051
Muthu Manickam
 
PDF
DAC Interfacing with 8051.pdf
Srikrishna Thota
 
PPT
8085 Architecture & Memory Interfacing1
techbed
 
PPTX
Stacks & subroutines 1
deval patel
 
PPTX
80486 and pentium
Vikshit Ganjoo
 
PPTX
TRAFFIC LIGHT CONTROL SYSTEM USING 8085 MICROPROCESSOR
Subash Sambath Kumar
 
DOCX
Arm7 Interfacing examples
Dr.YNM
 
PPTX
8254 Programmable Interval Timer by vijay
Vijay Kumar
 
PPT
Pipeline hazard
AJAL A J
 
PPT
Decimation in time and frequency
SARITHA REDDY
 
PPTX
8086 Microprocessor Pipeline Architecture.pptx
Green University of Bangladesh
 
PPTX
Addressing modes of 8086
Dr. AISHWARYA N
 
PPTX
Signal descriptors of 8086
aviban
 
DOCX
8096 microcontrollers notes
Dr.YNM
 
PDF
Convolution codes - Coding/Decoding Tree codes and Trellis codes for multiple...
Madhumita Tamhane
 
PPTX
Interfacing memory with 8086 microprocessor
Vikas Gupta
 
PPTX
Internal architecture-of-8086
Estiak Khan
 
PPTX
Chebyshev filter
MOHAMMAD AKRAM
 
Interfacing of io device to 8085
Nitin Ahire
 
Microcontroller presentation
xavierpaulino
 
Memory organization of 8051
Muthu Manickam
 
DAC Interfacing with 8051.pdf
Srikrishna Thota
 
8085 Architecture & Memory Interfacing1
techbed
 
Stacks & subroutines 1
deval patel
 
80486 and pentium
Vikshit Ganjoo
 
TRAFFIC LIGHT CONTROL SYSTEM USING 8085 MICROPROCESSOR
Subash Sambath Kumar
 
Arm7 Interfacing examples
Dr.YNM
 
8254 Programmable Interval Timer by vijay
Vijay Kumar
 
Pipeline hazard
AJAL A J
 
Decimation in time and frequency
SARITHA REDDY
 
8086 Microprocessor Pipeline Architecture.pptx
Green University of Bangladesh
 
Addressing modes of 8086
Dr. AISHWARYA N
 
Signal descriptors of 8086
aviban
 
8096 microcontrollers notes
Dr.YNM
 
Convolution codes - Coding/Decoding Tree codes and Trellis codes for multiple...
Madhumita Tamhane
 
Interfacing memory with 8086 microprocessor
Vikas Gupta
 
Internal architecture-of-8086
Estiak Khan
 
Chebyshev filter
MOHAMMAD AKRAM
 

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

PPTX
Embedded systems, lesson 16
REKHASENCHAgs0801bm1
 
PPTX
Interrupts of 8051 microcontroller.newpp
amalajenni
 
PPTX
Interrupt in 8051
ssuser3a47cb
 
PPTX
Interrupt programming
vijaydeepakg
 
PPTX
Micro controller 8051 Interrupts
dharmesh nakum
 
PPTX
Mc module5 ppt_msj
mangala jolad
 
PPTX
Interrupts in 8051
Sudhanshu Janwadkar
 
PPTX
37471656 interrupts
tt_aljobory
 
PDF
Unit 5_interrupt programming_Part 1
KanchanPatil34
 
PDF
8051 Interrupts
SaravananVijayakumar4
 
PPT
Interrupt programming with 8051 microcontroller
Ankit Bhatnagar
 
PPT
8051 interrupts
Shreyans Pathak
 
PPTX
Interrupt in 8051 microcontrollers .pptx
neethujaaps
 
PDF
8051-interrupts-temporary suspension of a program
Jason J Pulikkottil
 
PPTX
hardware interrupts in 8051 microcontroller
veenagugri1
 
PDF
Interrupts of microcontroller 8051
Nilesh Bhaskarrao Bahadure
 
PPT
8051 Inturrpt
Ramasubbu .P
 
PPT
DPA
Ramasubbu .P
 
PPTX
Interrupt.pptx
PallaviHailkar
 
Embedded systems, lesson 16
REKHASENCHAgs0801bm1
 
Interrupts of 8051 microcontroller.newpp
amalajenni
 
Interrupt in 8051
ssuser3a47cb
 
Interrupt programming
vijaydeepakg
 
Micro controller 8051 Interrupts
dharmesh nakum
 
Mc module5 ppt_msj
mangala jolad
 
Interrupts in 8051
Sudhanshu Janwadkar
 
37471656 interrupts
tt_aljobory
 
Unit 5_interrupt programming_Part 1
KanchanPatil34
 
8051 Interrupts
SaravananVijayakumar4
 
Interrupt programming with 8051 microcontroller
Ankit Bhatnagar
 
8051 interrupts
Shreyans Pathak
 
Interrupt in 8051 microcontrollers .pptx
neethujaaps
 
8051-interrupts-temporary suspension of a program
Jason J Pulikkottil
 
hardware interrupts in 8051 microcontroller
veenagugri1
 
Interrupts of microcontroller 8051
Nilesh Bhaskarrao Bahadure
 
8051 Inturrpt
Ramasubbu .P
 
Interrupt.pptx
PallaviHailkar
 
Ad

More from Vikas Dongre (20)

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

Recently uploaded (20)

PPT
National Oil Spill Disaster contingency Plan &DOCUMENTATION.ppt
abhishek579y
 
PPTX
agile vs waterfall.pptxagile vs waterfall.pptagile vs waterfall.ppt
UdhayaKaviyan
 
PPTX
Contact Tracing during the covid 19 pandemic
RURALHEALTHCENTERTAM
 
PDF
Job Card - Developer.pdf is for the a new srping platform
sashko9
 
PDF
Advancing Energy Equity with Locally Led Solar- How CBOs Are Lighting the Pat...
World Resources Institute (WRI)
 
PPTX
1155 Helen Clayton_Tasha Clark - ESG Slides - Final - APM Conference 25.pptx
Association for Project Management
 
PPTX
DEMO-WALKTHROUGH WORKSHOoooooooooooooooooooooooooooooooooooooooP.pptx
ᜃᜇ᜔ᜎᜓ ᜉᜎ᜔ᜋ
 
PPTX
sst project 2 ppt.pptx789456133222255555
nischayagarwal007
 
DOCX
The Overlooked Impact of Growth Regulators on Fruit Quality.docx
jaydas201616
 
PPTX
Deltas. Definition, Formation, Structure,Morphology, Types
Mashrup Hasan
 
PPTX
People, Development and Environment.pptx
Anandakumar Natarajan
 
DOCX
Leading China Stainless Steel Fuel Oil Storage Tank Manufacturer Shaping the ...
AllenLin596164
 
PPTX
Understanding-Vermicompost-Calculations_1.pptx
qxtr95m9nf
 
PDF
Anthony Tony Mattei - An Environmental Scientist
Anthony "Tony" Mattei
 
PDF
Water Potential Data: Best Practices for Lab & Field Measurements
METER Group, Inc. USA
 
PPTX
PowerPoint on the topic continents.
smayank1205
 
PPTX
Cours_SF_1_11_03_25(tttyyuguuhhgfggh.pptx
benewendemakemoney
 
PPTX
ARSENIC REMOVAL BY PHYTOSTABILIZATION, RHIZOFILTERATION
SruthyRobert1
 
PDF
sanju research paper.pdfMultidrug Resistant Bacteria In Air Samples From Indo...
St. Xavier's college, maitighar,Kathmandu
 
DOCX
Ensuring Product Purity Stainless Steel Storage Tanks for Food Processing Pla...
AllenLin596164
 
National Oil Spill Disaster contingency Plan &DOCUMENTATION.ppt
abhishek579y
 
agile vs waterfall.pptxagile vs waterfall.pptagile vs waterfall.ppt
UdhayaKaviyan
 
Contact Tracing during the covid 19 pandemic
RURALHEALTHCENTERTAM
 
Job Card - Developer.pdf is for the a new srping platform
sashko9
 
Advancing Energy Equity with Locally Led Solar- How CBOs Are Lighting the Pat...
World Resources Institute (WRI)
 
1155 Helen Clayton_Tasha Clark - ESG Slides - Final - APM Conference 25.pptx
Association for Project Management
 
DEMO-WALKTHROUGH WORKSHOoooooooooooooooooooooooooooooooooooooooP.pptx
ᜃᜇ᜔ᜎᜓ ᜉᜎ᜔ᜋ
 
sst project 2 ppt.pptx789456133222255555
nischayagarwal007
 
The Overlooked Impact of Growth Regulators on Fruit Quality.docx
jaydas201616
 
Deltas. Definition, Formation, Structure,Morphology, Types
Mashrup Hasan
 
People, Development and Environment.pptx
Anandakumar Natarajan
 
Leading China Stainless Steel Fuel Oil Storage Tank Manufacturer Shaping the ...
AllenLin596164
 
Understanding-Vermicompost-Calculations_1.pptx
qxtr95m9nf
 
Anthony Tony Mattei - An Environmental Scientist
Anthony "Tony" Mattei
 
Water Potential Data: Best Practices for Lab & Field Measurements
METER Group, Inc. USA
 
PowerPoint on the topic continents.
smayank1205
 
Cours_SF_1_11_03_25(tttyyuguuhhgfggh.pptx
benewendemakemoney
 
ARSENIC REMOVAL BY PHYTOSTABILIZATION, RHIZOFILTERATION
SruthyRobert1
 
sanju research paper.pdfMultidrug Resistant Bacteria In Air Samples From Indo...
St. Xavier's college, maitighar,Kathmandu
 
Ensuring Product Purity Stainless Steel Storage Tanks for Food Processing Pla...
AllenLin596164
 

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