SlideShare a Scribd company logo
1 of 23
8051 counters/timers 
N.Bhaskar 
12MT06PED007
Introduction : 
• To generate precise time delay and to count the 
number of pulses timer / counter plays an 
important role 
Timer operations are basically three 
types 
1.software based approach 
2. hardware based approach 
3. combined software and hardware 
approach 
SJCET
SSooffttwwaarree bbaasseedd aapppprrooaacchh:: 
VNIT 
start 
Set P1.0 to 1 
Initialize counter 
register(CR) 
CR←CR-1 
is 
CR=0 
CPL P1.0 
N 
Y 
SETB P1.0 
Loop: MOV R6,#255 
Here: DJNZ R6,Here 
CPL P1.0 
SJMP Loop
HHaarrdd wwaarree bbaasseedd aapppprrooaacchh :: 
VNIT
CCoommbbiinneedd SS//WW aanndd HH//WW aapppprrooaacchh : 
Registers Used in Timers/Counters: 
– TH0, TL0, TH1, TL1 
– TMOD (Timer mode register) 
– TCON (Timer control register) 
SJCET
TTCCOONN RReeggiisstteerr 
Timer control register: TCON 
• Upper nibble for timer control, lower nibble for 
interrupts 
TR (run control bit) 
• TR0 for Timer 0 control; TR1 for Timer 1 control. 
• TR is set by programmer to turn timer/counter 
on/off. 
• TR=0: off (stop) 
• TR=1: on (start) 
(MSB) (LSB) 
TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0 
Timer 1 Timer0 for Interrupt
TF (timer overflow flag bit) 
TF0 is a timer 0 overflow flag bit; TF1 is a 
timer 1 overflow flag bit. 
TF is like a carry. Originally, TF=0. When TH-TL 
roll over to 0000 from FFFFH, the TF is set 
to 1. 
 TF=0 : not reach 
 TF=1: reach 
(MSB 
) 
(LSB) 
TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0 
Timer 1 Timer0 for Interrupt
Equivalent Instructions ffoorr tthhee TTiimmeerr CCoonnttrrooll 
RReeggiisstteerr:: 
VNIT
TTMMOODD RReeggiisstteerr 
Timer mode register: TMOD 
• An 8-bit register 
• Set the usage mode for two timers 
• Set lower 4 bits for Timer 0 (Set to 0000 
if not used) 
• Set upper 4 bits for Timer 1 (Set to 
0000 if not used) 
• Not bit-addressable 
(MSB) (LSB) 
GATE C/T M1 M0 GATE C/T M1 M0 
Timer 1 Timer 0
VNIT
SStteeppss FFOORR TTIIMMEERRSS OOPPEERRAATTIIOONN 
1. Choose mode 1 timer 0 
MOV TMOD,#01H 
1. Set the initiat value to TH0 and TL0. 
MOV TH0,#FFH 
MOV TL0,#FCH 
1. Better to clear the flag to monitor: TF0=0. 
CLR TF0 
1. Start the timer. 
SETB TR0
5.The 8051 starts to count up by incrementing the TH0-TL0. 
TH0-TL0= FFFCH,FFFDH,FFFEH,FFFFH,0000H
6. When TH0-TL0 rolls over from FFFFH to 
0000, the 8051 set TF0=1. 
Now TF0=1 
6. Keep monitoring the timer flag (TF) to see 
if it is raised. 
AGAIN: JNB TF0, AGAIN 
6. Clear TR0 to stop the process. 
CLR TR0 
6. Clear the TF flag for the next round. 
CLR TF0
Timer Delay CCaallccuullaattiioonn ffoorr XXTTAALL == 
1111..00559922 MMHHzz 
(a) in hex 
• (FFFF – YYXX ) × 1.085 ms 
• where YYXX are TH, TL initial values 
respectively. 
• Notice that values YYXX are in hex. 
(b) in decimal 
• Convert YYXX values of the TH, TL register to 
decimal to get a NNNNN decimal number 
• then (65536 – NNNNN) × 1.085 ms
• Assume that XTAL = 11.0592 MHz . 
• And we know desired delay 
• how to find the values for the TH,TL ? 
1. Divide the delay by 1.085 ms and get n. 
2. Perform 65536 –n 
3. Convert the result of Step 2 to hex ( yyxx) 
4. Set TH = yy and TL = xx.
Example 1: 
• Assuming XTAL = 11.0592 MHz, 
• write a program to generate a square wave of 50 Hz 
frequency on pin P2.3. 
Solution: 
1. The period of the square wave = 1 / 50 Hz = 20 
ms. 
2. The high or low portion of the square wave = 10 
ms. 
3. 10 ms / 1.085 ms = 9216 
4. 65536 – 9216 = 56320 in decimal = DC00H in 
hex. 
5. TL1 = 00H and TH1 = DCH.
MOV TMOD,#10H ;timer 1, mode 1 
AGAIN: MOV TL1,#00 ;Timer value= DC00H 
MOV TH1,#0DCH 
SETB TR1 ;start 
BACK: JNB TF1,BACK 
CLR TR1 ;stop 
CPL P2.3 
CLR TF1 ;clear timer flag 1 
SJMP AGAIN ;reload timer
Example 2: 
square wave of 50% duty on P1.5 
Timer 0 is used 
;each loop is a half clock 
MOV TMOD,#01 ;Timer 0,mode 1(16-bit) 
HERE: MOV TL0,#0F2H ;Timer value = FFF2H 
MOV TH0,#0FFH 
CPL P1.5 
ACALL DELAY 
SJMP HERE 
50% 50% 
whole clock 
P1.5
;generate delay using timer 0 
DELAY: 
SETB TR0 ;start the timer 0 
AGAIN:JNB TF0,AGAIN 
CLR TR0 ;stop timer 0 
CLR TF0 ;clear timer 0 flag 
RET 
FFF2 FFF3 FFF4 FFFF 0000 
TF0 =0 TF0 =0 TF0 =0 TF0 =0 TF0 =1
QUERIES 
VNIT
THANK YOU 
VNIT

More Related Content

What's hot

8051 timer counter
8051 timer counter8051 timer counter
8051 timer counterankit3991
 
8051 Microcontroller Timer
8051 Microcontroller Timer8051 Microcontroller Timer
8051 Microcontroller Timeranishgoel
 
8051 Timers and Counters
8051 Timers and Counters8051 Timers and Counters
8051 Timers and Counterscjbas
 
Chapter 16 timers and counters
Chapter 16 timers and countersChapter 16 timers and counters
Chapter 16 timers and countersforgotteniman
 
8051 Timers and Counters
8051 Timers and Counters8051 Timers and Counters
8051 Timers and CountersShreyans Pathak
 
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND C
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND CPIC18 TIMER PROGRAMMING IN ASSEMBLY AND C
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND C raosandy11
 
8051 Timers / Counters
8051 Timers / Counters8051 Timers / Counters
8051 Timers / CountersPatricio Lima
 
Timer And Counter in 8051 Microcontroller
Timer And Counter in 8051 MicrocontrollerTimer And Counter in 8051 Microcontroller
Timer And Counter in 8051 MicrocontrollerJay Makwana
 
Microprocessor and Controller
Microprocessor and ControllerMicroprocessor and Controller
Microprocessor and ControllerBHAVYA DOSHI
 
Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051logesh waran
 

What's hot (20)

8051 timers--2
   8051 timers--2   8051 timers--2
8051 timers--2
 
8051 timer counter
8051 timer counter8051 timer counter
8051 timer counter
 
8051 Microcontroller Timer
8051 Microcontroller Timer8051 Microcontroller Timer
8051 Microcontroller Timer
 
8051 timer counter
8051 timer counter8051 timer counter
8051 timer counter
 
8051 ch9
8051 ch98051 ch9
8051 ch9
 
8051 timers
8051 timers8051 timers
8051 timers
 
8051 Timers and Counters
8051 Timers and Counters8051 Timers and Counters
8051 Timers and Counters
 
Chapter 16 timers and counters
Chapter 16 timers and countersChapter 16 timers and counters
Chapter 16 timers and counters
 
9 timer programming
9 timer programming9 timer programming
9 timer programming
 
Timers
TimersTimers
Timers
 
8051e
8051e8051e
8051e
 
8051 Timers and Counters
8051 Timers and Counters8051 Timers and Counters
8051 Timers and Counters
 
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND C
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND CPIC18 TIMER PROGRAMMING IN ASSEMBLY AND C
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND C
 
Timers
TimersTimers
Timers
 
8051 Timers / Counters
8051 Timers / Counters8051 Timers / Counters
8051 Timers / Counters
 
Timer And Counter in 8051 Microcontroller
Timer And Counter in 8051 MicrocontrollerTimer And Counter in 8051 Microcontroller
Timer And Counter in 8051 Microcontroller
 
Digital timer
Digital timerDigital timer
Digital timer
 
Timers and pwm
Timers and pwmTimers and pwm
Timers and pwm
 
Microprocessor and Controller
Microprocessor and ControllerMicroprocessor and Controller
Microprocessor and Controller
 
Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051
 

Viewers also liked

Interrupt programming
Interrupt programming Interrupt programming
Interrupt programming vijaydeepakg
 
Dizee rascal analysis
Dizee rascal analysisDizee rascal analysis
Dizee rascal analysisLD7
 
Reeja b ed ict individual (1)
Reeja b ed ict individual (1)Reeja b ed ict individual (1)
Reeja b ed ict individual (1)REEJASHA
 
Keypad and dc motor
Keypad and dc motor Keypad and dc motor
Keypad and dc motor vijaydeepakg
 
Construction
ConstructionConstruction
ConstructionLD7
 
Https _doc-0o-c4-apps-viewer.googleusercontent
Https  _doc-0o-c4-apps-viewer.googleusercontent Https  _doc-0o-c4-apps-viewer.googleusercontent
Https _doc-0o-c4-apps-viewer.googleusercontent vijaydeepakg
 
Sudhir tms 320 f 2812
Sudhir tms 320 f 2812 Sudhir tms 320 f 2812
Sudhir tms 320 f 2812 vijaydeepakg
 
Reeja b ed ict individual (1)
Reeja b ed ict individual (1)Reeja b ed ict individual (1)
Reeja b ed ict individual (1)REEJASHA
 
Task 5 + 6
Task 5 + 6Task 5 + 6
Task 5 + 6LD7
 
Applications of microcontroller(8051)
Applications of microcontroller(8051) Applications of microcontroller(8051)
Applications of microcontroller(8051) vijaydeepakg
 
Acls bolsillo 2010
Acls bolsillo 2010Acls bolsillo 2010
Acls bolsillo 2010nvklnd
 
Deploy django apps using docker
Deploy django apps using dockerDeploy django apps using docker
Deploy django apps using dockerThomas Kremmel
 
Cinéma - Les bonnes pratiques pour promouvoir un film sur Facebook
Cinéma - Les bonnes pratiques pour promouvoir un film sur FacebookCinéma - Les bonnes pratiques pour promouvoir un film sur Facebook
Cinéma - Les bonnes pratiques pour promouvoir un film sur FacebookBenjamin Martin
 
Diapo chap 09-travail-emploi-chômage (14-15)
Diapo chap 09-travail-emploi-chômage (14-15)Diapo chap 09-travail-emploi-chômage (14-15)
Diapo chap 09-travail-emploi-chômage (14-15)Philippe Watrelot
 
Brand content et evenementiel : pari gagnant
Brand content et evenementiel : pari gagnantBrand content et evenementiel : pari gagnant
Brand content et evenementiel : pari gagnantLabCom
 

Viewers also liked (19)

Interrupt programming
Interrupt programming Interrupt programming
Interrupt programming
 
Dizee rascal analysis
Dizee rascal analysisDizee rascal analysis
Dizee rascal analysis
 
12 mt06ped001
12 mt06ped001 12 mt06ped001
12 mt06ped001
 
Reeja b ed ict individual (1)
Reeja b ed ict individual (1)Reeja b ed ict individual (1)
Reeja b ed ict individual (1)
 
Keypad and dc motor
Keypad and dc motor Keypad and dc motor
Keypad and dc motor
 
Construction
ConstructionConstruction
Construction
 
Https _doc-0o-c4-apps-viewer.googleusercontent
Https  _doc-0o-c4-apps-viewer.googleusercontent Https  _doc-0o-c4-apps-viewer.googleusercontent
Https _doc-0o-c4-apps-viewer.googleusercontent
 
Sudhir tms 320 f 2812
Sudhir tms 320 f 2812 Sudhir tms 320 f 2812
Sudhir tms 320 f 2812
 
Reeja b ed ict individual (1)
Reeja b ed ict individual (1)Reeja b ed ict individual (1)
Reeja b ed ict individual (1)
 
Jp
Jp Jp
Jp
 
Task 5 + 6
Task 5 + 6Task 5 + 6
Task 5 + 6
 
Lp 30
Lp 30Lp 30
Lp 30
 
Applications of microcontroller(8051)
Applications of microcontroller(8051) Applications of microcontroller(8051)
Applications of microcontroller(8051)
 
12 mt06ped008
12 mt06ped008 12 mt06ped008
12 mt06ped008
 
Acls bolsillo 2010
Acls bolsillo 2010Acls bolsillo 2010
Acls bolsillo 2010
 
Deploy django apps using docker
Deploy django apps using dockerDeploy django apps using docker
Deploy django apps using docker
 
Cinéma - Les bonnes pratiques pour promouvoir un film sur Facebook
Cinéma - Les bonnes pratiques pour promouvoir un film sur FacebookCinéma - Les bonnes pratiques pour promouvoir un film sur Facebook
Cinéma - Les bonnes pratiques pour promouvoir un film sur Facebook
 
Diapo chap 09-travail-emploi-chômage (14-15)
Diapo chap 09-travail-emploi-chômage (14-15)Diapo chap 09-travail-emploi-chômage (14-15)
Diapo chap 09-travail-emploi-chômage (14-15)
 
Brand content et evenementiel : pari gagnant
Brand content et evenementiel : pari gagnantBrand content et evenementiel : pari gagnant
Brand content et evenementiel : pari gagnant
 

Similar to 8051 Timers and Counters Guide for Precise Time Delays and Pulse Counting

Microcontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptxMicrocontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptxAmoghR3
 
lecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.pptlecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.pptHebaEng
 
MICROCONTROLLER TIMERS.ppt
MICROCONTROLLER TIMERS.pptMICROCONTROLLER TIMERS.ppt
MICROCONTROLLER TIMERS.pptreemasajin1
 
PIC-Chapter_10.pptx
PIC-Chapter_10.pptxPIC-Chapter_10.pptx
PIC-Chapter_10.pptxAliBzeih7
 
PIC timer programming
PIC timer programmingPIC timer programming
PIC timer programmingAkash Puri
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Aarav Soni
 
timer counter (1).pptx
timer counter (1).pptxtimer counter (1).pptx
timer counter (1).pptxSujalKumar73
 
EC8691 - UNIT 5.pdf
EC8691 - UNIT 5.pdfEC8691 - UNIT 5.pdf
EC8691 - UNIT 5.pdfSPonmalar1
 
ControlLogix Timers FA16
ControlLogix Timers FA16ControlLogix Timers FA16
ControlLogix Timers FA16John Todora
 
SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 2
SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 2SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 2
SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 2KanchanPatil34
 
Counters & time delay
Counters & time delayCounters & time delay
Counters & time delayHemant Chetwani
 
Microprocessor_Counter_and_Time_Delay.pptx
Microprocessor_Counter_and_Time_Delay.pptxMicroprocessor_Counter_and_Time_Delay.pptx
Microprocessor_Counter_and_Time_Delay.pptxamritsaravagi
 

Similar to 8051 Timers and Counters Guide for Precise Time Delays and Pulse Counting (20)

Microcontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptxMicrocontrollers-MODULE4.pptx
Microcontrollers-MODULE4.pptx
 
UNIT-5.ppt
UNIT-5.pptUNIT-5.ppt
UNIT-5.ppt
 
lecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.pptlecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.ppt
 
4.Timer_1.ppt
4.Timer_1.ppt4.Timer_1.ppt
4.Timer_1.ppt
 
Uc
UcUc
Uc
 
MICROCONTROLLER TIMERS.ppt
MICROCONTROLLER TIMERS.pptMICROCONTROLLER TIMERS.ppt
MICROCONTROLLER TIMERS.ppt
 
Class9
Class9Class9
Class9
 
timers.pdf
timers.pdftimers.pdf
timers.pdf
 
PIC-Chapter_10.pptx
PIC-Chapter_10.pptxPIC-Chapter_10.pptx
PIC-Chapter_10.pptx
 
AVRTIMER.pptx
AVRTIMER.pptxAVRTIMER.pptx
AVRTIMER.pptx
 
PIC timer programming
PIC timer programmingPIC timer programming
PIC timer programming
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)
 
timer counter (1).pptx
timer counter (1).pptxtimer counter (1).pptx
timer counter (1).pptx
 
EC8691 - UNIT 5.pdf
EC8691 - UNIT 5.pdfEC8691 - UNIT 5.pdf
EC8691 - UNIT 5.pdf
 
Chapter 08
Chapter 08Chapter 08
Chapter 08
 
ControlLogix Timers FA16
ControlLogix Timers FA16ControlLogix Timers FA16
ControlLogix Timers FA16
 
SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 2
SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 2SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 2
SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 2
 
Counters & time delay
Counters & time delayCounters & time delay
Counters & time delay
 
Timers in Arduino
Timers in ArduinoTimers in Arduino
Timers in Arduino
 
Microprocessor_Counter_and_Time_Delay.pptx
Microprocessor_Counter_and_Time_Delay.pptxMicroprocessor_Counter_and_Time_Delay.pptx
Microprocessor_Counter_and_Time_Delay.pptx
 

8051 Timers and Counters Guide for Precise Time Delays and Pulse Counting

  • 2. Introduction : • To generate precise time delay and to count the number of pulses timer / counter plays an important role Timer operations are basically three types 1.software based approach 2. hardware based approach 3. combined software and hardware approach SJCET
  • 3. SSooffttwwaarree bbaasseedd aapppprrooaacchh:: VNIT start Set P1.0 to 1 Initialize counter register(CR) CR←CR-1 is CR=0 CPL P1.0 N Y SETB P1.0 Loop: MOV R6,#255 Here: DJNZ R6,Here CPL P1.0 SJMP Loop
  • 4. HHaarrdd wwaarree bbaasseedd aapppprrooaacchh :: VNIT
  • 5. CCoommbbiinneedd SS//WW aanndd HH//WW aapppprrooaacchh : Registers Used in Timers/Counters: – TH0, TL0, TH1, TL1 – TMOD (Timer mode register) – TCON (Timer control register) SJCET
  • 6. TTCCOONN RReeggiisstteerr Timer control register: TCON • Upper nibble for timer control, lower nibble for interrupts TR (run control bit) • TR0 for Timer 0 control; TR1 for Timer 1 control. • TR is set by programmer to turn timer/counter on/off. • TR=0: off (stop) • TR=1: on (start) (MSB) (LSB) TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0 Timer 1 Timer0 for Interrupt
  • 7. TF (timer overflow flag bit) TF0 is a timer 0 overflow flag bit; TF1 is a timer 1 overflow flag bit. TF is like a carry. Originally, TF=0. When TH-TL roll over to 0000 from FFFFH, the TF is set to 1.  TF=0 : not reach  TF=1: reach (MSB ) (LSB) TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0 Timer 1 Timer0 for Interrupt
  • 8. Equivalent Instructions ffoorr tthhee TTiimmeerr CCoonnttrrooll RReeggiisstteerr:: VNIT
  • 9. TTMMOODD RReeggiisstteerr Timer mode register: TMOD • An 8-bit register • Set the usage mode for two timers • Set lower 4 bits for Timer 0 (Set to 0000 if not used) • Set upper 4 bits for Timer 1 (Set to 0000 if not used) • Not bit-addressable (MSB) (LSB) GATE C/T M1 M0 GATE C/T M1 M0 Timer 1 Timer 0
  • 10.
  • 11. VNIT
  • 12.
  • 13. SStteeppss FFOORR TTIIMMEERRSS OOPPEERRAATTIIOONN 1. Choose mode 1 timer 0 MOV TMOD,#01H 1. Set the initiat value to TH0 and TL0. MOV TH0,#FFH MOV TL0,#FCH 1. Better to clear the flag to monitor: TF0=0. CLR TF0 1. Start the timer. SETB TR0
  • 14. 5.The 8051 starts to count up by incrementing the TH0-TL0. TH0-TL0= FFFCH,FFFDH,FFFEH,FFFFH,0000H
  • 15. 6. When TH0-TL0 rolls over from FFFFH to 0000, the 8051 set TF0=1. Now TF0=1 6. Keep monitoring the timer flag (TF) to see if it is raised. AGAIN: JNB TF0, AGAIN 6. Clear TR0 to stop the process. CLR TR0 6. Clear the TF flag for the next round. CLR TF0
  • 16. Timer Delay CCaallccuullaattiioonn ffoorr XXTTAALL == 1111..00559922 MMHHzz (a) in hex • (FFFF – YYXX ) × 1.085 ms • where YYXX are TH, TL initial values respectively. • Notice that values YYXX are in hex. (b) in decimal • Convert YYXX values of the TH, TL register to decimal to get a NNNNN decimal number • then (65536 – NNNNN) × 1.085 ms
  • 17. • Assume that XTAL = 11.0592 MHz . • And we know desired delay • how to find the values for the TH,TL ? 1. Divide the delay by 1.085 ms and get n. 2. Perform 65536 –n 3. Convert the result of Step 2 to hex ( yyxx) 4. Set TH = yy and TL = xx.
  • 18. Example 1: • Assuming XTAL = 11.0592 MHz, • write a program to generate a square wave of 50 Hz frequency on pin P2.3. Solution: 1. The period of the square wave = 1 / 50 Hz = 20 ms. 2. The high or low portion of the square wave = 10 ms. 3. 10 ms / 1.085 ms = 9216 4. 65536 – 9216 = 56320 in decimal = DC00H in hex. 5. TL1 = 00H and TH1 = DCH.
  • 19. MOV TMOD,#10H ;timer 1, mode 1 AGAIN: MOV TL1,#00 ;Timer value= DC00H MOV TH1,#0DCH SETB TR1 ;start BACK: JNB TF1,BACK CLR TR1 ;stop CPL P2.3 CLR TF1 ;clear timer flag 1 SJMP AGAIN ;reload timer
  • 20. Example 2: square wave of 50% duty on P1.5 Timer 0 is used ;each loop is a half clock MOV TMOD,#01 ;Timer 0,mode 1(16-bit) HERE: MOV TL0,#0F2H ;Timer value = FFF2H MOV TH0,#0FFH CPL P1.5 ACALL DELAY SJMP HERE 50% 50% whole clock P1.5
  • 21. ;generate delay using timer 0 DELAY: SETB TR0 ;start the timer 0 AGAIN:JNB TF0,AGAIN CLR TR0 ;stop timer 0 CLR TF0 ;clear timer 0 flag RET FFF2 FFF3 FFF4 FFFF 0000 TF0 =0 TF0 =0 TF0 =0 TF0 =0 TF0 =1