SlideShare a Scribd company logo
1 of 20
8051 Microcontroller 
Timers & Counters 
Prepared by: 
Manu Thomas 
manut46@gmail.com 1 12/11/2014
The 8051 Timers 
The 8051 comes equipped with two timers, both of which may be 
controlled, set, read, and configured individually. 
he 8051 timers have three general functions: 
1) Keeping time and/or calculating the amount of time between events, 
2) Counting the events themselves, or 
3) Generating baud rates for the serial port. 
The 8051 microcontroller has 2 timers/counters called T0 and T1. As their 
names suggest, their main purpose is to measure time and count external 
events. Besides, they can be used for generating clock pulses to be used in 
serial communication, so called Baud Rate. 
manut46@gmail.com 2 12/11/2014
Timer T0 
The timer T0 consists of two registers – TH0 and TL0 representing a low and a 
high byte of one 16-digit binary number. 
Formula used to calculate values in these two registers is very simple: 
TH0 × 256 + TL0 = T 
Since the timer T0 is virtually 16-bit register, the largest value it can store is 
65 535. In case of exceeding this value, the timer will be automatically cleared 
and counting starts from 0. This condition is called an overflow. 
Two registers TMOD and TCON are closely connected to this timer and 
control its operation. 
manut46@gmail.com 3 12/11/2014
TMOD Register (Timer Mode) 
The TMOD register selects the operational mode of the timers 
T0 and T1 
The low 4 bits (bit0 - bit3) refer to the timer 0, 
The high 4 bits (bit4 - bit7) refer to the timer 1 
manut46@gmail.com 4 12/11/2014
TMOD Register (Timer Mode) cont.. 
Bits of this register have the following function: 
GATE1 
Enables and disables Timer 1 by means of a signal brought to the 
INT1 pin (P3.3): 
1 - Timer 1 operates only if the INT1 bit is set. 
0 - Timer 1 operates regardless of the logic state of the INT1 bit. 
C/T1 
Selects pulses to be counted up by the timer/counter 1: 
1 - Timer counts pulses brought to the T1 pin (P3.5). 
0 - Timer counts pulses from internal oscillator. 
manut46@gmail.com 5 12/11/2014
TMOD Register (Timer Mode) cont.. 
T1M1,T1M0 
These two bits select the operational mode of the Timer 1. 
T1M1 T1M0 MODE DESCRIPTION 
0 0 0 13-bit timer 
0 1 1 16-bit timer 
1 0 2 8-bit auto-reload 
1 1 3 Split mode 
manut46@gmail.com 6 12/11/2014
TMOD Register (Timer Mode) cont.. 
GATE0 
Enables and disables Timer 0 by means of a signal brought to the 
INT1 pin (P3.2): 
1 - Timer 0 operates only if the INT0 bit is set. 
0 - Timer 0 operates regardless of the logic state of the INT0 bit. 
C/T10 
Selects pulses to be counted up by the timer/counter 0: 
1 - Timer counts pulses brought to the T0 pin (P3.4). 
0 - Timer counts pulses from internal oscillator. 
manut46@gmail.com 7 12/11/2014
TMOD Register (Timer Mode) cont.. 
T0M1,T0M0 
These two bits select the operational mode of the Timer 0. 
T0M1 T0M0 MODE DESCRIPTION 
0 0 0 13-bit timer 
0 1 1 16-bit timer 
1 0 2 8-bit auto-reload 
1 1 3 Split mode 
manut46@gmail.com 8 12/11/2014
TMOD Register (Timer Mode) cont.. 
manut46@gmail.com 9 12/11/2014
Timer Control (TCON) Register 
TCON register is also one of the registers whose bits are directly in 
control of timer operation. 
Only 4 bits of this register are used for this purpose, while rest of them 
is used for interrupt control 
manut46@gmail.com 10 12/11/2014
Timer Control (TCON) Register cont.. 
Bits of this register have the following function: 
TF1 
bit is automatically set on the Timer 1 overflow. 
TR1 
bit enables the Timer 1. 
1 - Timer 1 is enabled. 
0 - Timer 1 is disabled. 
TF0 
bit is automatically set on the Timer 0 overflow. 
TR0 
bit enables the timer 0. 
1 - Timer 0 is enabled. 
0 - Timer 0 is disabled. 
manut46@gmail.com 11 12/11/2014
manut46@gmail.com 12 12/11/2014
Timer 0 in mode 0 (13-bit timer) 
This mode configures timer 0 as a 13-bit timer which consists of all 8 bits 
of TH0 and the lower 5 bits of TL0. 
As a result, the Timer 0 uses only 13 of 16 bits 
How does it operate 
Each coming pulse causes the lower register bits to change their states. 
After receiving 32 pulses, this register is loaded and automatically cleared, 
while the higher byte (TH0) is incremented by 1. 
This process is repeated until registers count up 8192 pulses. 
After that, both registers are cleared and counting starts from 0. 
manut46@gmail.com 13 12/11/2014
Timer 0 in mode 0 (13-bit timer) Cont.. 
Configuration 
manut46@gmail.com 14 12/11/2014
Timer 0 in mode 1 (16-bit timer) 
Mode 1 configures timer 0 as a 16-bit timer 
It uses all the bits of both registers TH0 and TL0. 
This is one of the most commonly used modes. 
Timer operates in the same way as in mode 0, with difference that the 
registers count up to 65 536 as allowable by the 16 bits. 
manut46@gmail.com 15 12/11/2014
Timer 0 in mode 1 (16-bit timer) Cont.. 
manut46@gmail.com 16 12/11/2014
Timer 0 in mode 2 (Auto-Reload Timer) 
Mode 2 configures timer 0 as an 8-bit timer. 
Actually, timer 0 uses only one 8-bit register for counting and never counts 
from 0, but from an arbitrary value (0-255) stored in another (TH0) 
register. 
In fact, only the TL0 register operates as a timer, while another (TH0) 
register stores the value from which the counting starts 
When the TL0 register is loaded, instead of being cleared, the contents of 
TH0 will be reloaded to it. 
manut46@gmail.com 17 12/11/2014
Timer 0 in mode 2 (Auto-Reload Timer) 
manut46@gmail.com 18 12/11/2014
Timer 0 in Mode 3 (Split Timer) 
Mode 3 configures timer 0 so that registers TL0 and TH0 operate as separate 
8-bit timers. 
In other words, the 16-bit timer consisting of two registers TH0 and TL0 is 
split into two independent 8-bit timers. 
This mode is provided for applications requiring an additional 8-bit timer or 
counter. The TL0 timer turns into timer 0, while the TH0 timer turns into 
timer 1. 
All the control bits of 16-bit Timer 1 (consisting of the TH1 and TL1 register), 
now control the 8-bit Timer 1. 
Even though the 16-bit Timer 1 can still be configured to operate in any of 
modes (mode 1, 2 or 3), it is no longer possible to disable it as there is no 
control bit to do it. 
Thus, its operation is restricted when timer 0 is in mode 3. 
manut46@gmail.com 19 12/11/2014
Timer 0 in Mode 3 (Split Timer) 
manut46@gmail.com 20 12/11/2014

More Related Content

What's hot

8051 Microcontroller Tutorial and Architecture with Applications
8051 Microcontroller Tutorial and Architecture with Applications8051 Microcontroller Tutorial and Architecture with Applications
8051 Microcontroller Tutorial and Architecture with Applicationselprocus
 
Interrupt programming with 8051 microcontroller
Interrupt programming with 8051  microcontrollerInterrupt programming with 8051  microcontroller
Interrupt programming with 8051 microcontrollerAnkit Bhatnagar
 
Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor  Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor Mustapha Fatty
 
8051 microcontroller and it’s interface
8051 microcontroller and it’s interface8051 microcontroller and it’s interface
8051 microcontroller and it’s interfaceAbhishek Choksi
 
Serial Communication
Serial CommunicationSerial Communication
Serial CommunicationUshaRani289
 
8096 microcontrollers notes
8096 microcontrollers notes8096 microcontrollers notes
8096 microcontrollers notesDr.YNM
 
Memory organization of 8051
Memory organization of 8051Memory organization of 8051
Memory organization of 8051Muthu Manickam
 
MICROCONTROLLER 8051- Architecture & Pin Configuration
MICROCONTROLLER 8051- Architecture & Pin Configuration MICROCONTROLLER 8051- Architecture & Pin Configuration
MICROCONTROLLER 8051- Architecture & Pin Configuration AKHIL MADANKAR
 
8051 Microcontroller I/O ports
8051 Microcontroller I/O ports8051 Microcontroller I/O ports
8051 Microcontroller I/O portsanishgoel
 
8051 microcontroller
8051 microcontroller 8051 microcontroller
8051 microcontroller Gaurav Verma
 
8051 Timers / Counters
8051 Timers / Counters8051 Timers / Counters
8051 Timers / CountersPatricio Lima
 
8086 modes
8086 modes8086 modes
8086 modesPDFSHARE
 
8051 MICROCONTROLLER ARCHITECTURE.pptx
 8051 MICROCONTROLLER ARCHITECTURE.pptx 8051 MICROCONTROLLER ARCHITECTURE.pptx
8051 MICROCONTROLLER ARCHITECTURE.pptxMemonaMemon1
 
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
 

What's hot (20)

8051 Microcontroller Tutorial and Architecture with Applications
8051 Microcontroller Tutorial and Architecture with Applications8051 Microcontroller Tutorial and Architecture with Applications
8051 Microcontroller Tutorial and Architecture with Applications
 
Interrupt programming with 8051 microcontroller
Interrupt programming with 8051  microcontrollerInterrupt programming with 8051  microcontroller
Interrupt programming with 8051 microcontroller
 
Interrupts in 8051
Interrupts in 8051Interrupts in 8051
Interrupts in 8051
 
Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor  Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor
 
8051 microcontroller and it’s interface
8051 microcontroller and it’s interface8051 microcontroller and it’s interface
8051 microcontroller and it’s interface
 
Serial Communication
Serial CommunicationSerial Communication
Serial Communication
 
8051 serial communication-UART
8051 serial communication-UART8051 serial communication-UART
8051 serial communication-UART
 
8051 memory
8051 memory8051 memory
8051 memory
 
8051 instruction set
8051 instruction set8051 instruction set
8051 instruction set
 
8096 microcontrollers notes
8096 microcontrollers notes8096 microcontrollers notes
8096 microcontrollers notes
 
Interfacing Stepper motor with 8051
Interfacing Stepper motor with 8051Interfacing Stepper motor with 8051
Interfacing Stepper motor with 8051
 
Intel 8051 - pin description
Intel 8051  - pin descriptionIntel 8051  - pin description
Intel 8051 - pin description
 
Memory organization of 8051
Memory organization of 8051Memory organization of 8051
Memory organization of 8051
 
MICROCONTROLLER 8051- Architecture & Pin Configuration
MICROCONTROLLER 8051- Architecture & Pin Configuration MICROCONTROLLER 8051- Architecture & Pin Configuration
MICROCONTROLLER 8051- Architecture & Pin Configuration
 
8051 Microcontroller I/O ports
8051 Microcontroller I/O ports8051 Microcontroller I/O ports
8051 Microcontroller I/O ports
 
8051 microcontroller
8051 microcontroller 8051 microcontroller
8051 microcontroller
 
8051 Timers / Counters
8051 Timers / Counters8051 Timers / Counters
8051 Timers / Counters
 
8086 modes
8086 modes8086 modes
8086 modes
 
8051 MICROCONTROLLER ARCHITECTURE.pptx
 8051 MICROCONTROLLER ARCHITECTURE.pptx 8051 MICROCONTROLLER ARCHITECTURE.pptx
8051 MICROCONTROLLER ARCHITECTURE.pptx
 
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
 

Similar to 8051 timers

8051 Microcontroller Timer
8051 Microcontroller Timer8051 Microcontroller Timer
8051 Microcontroller Timeranishgoel
 
8051 timer
8051 timer8051 timer
8051 timerBkannan2
 
Timer And Counter in 8051 Microcontroller
Timer And Counter in 8051 MicrocontrollerTimer And Counter in 8051 Microcontroller
Timer And Counter in 8051 MicrocontrollerJay Makwana
 
lecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.pptlecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.pptHebaEng
 
6-Interrupts Programming-27-03-2024.pptx
6-Interrupts Programming-27-03-2024.pptx6-Interrupts Programming-27-03-2024.pptx
6-Interrupts Programming-27-03-2024.pptxRahultater4
 
5-Timer Mode 2 Programming-18-03-2024.pptx
5-Timer Mode 2 Programming-18-03-2024.pptx5-Timer Mode 2 Programming-18-03-2024.pptx
5-Timer Mode 2 Programming-18-03-2024.pptxRahultater4
 
Micro c lab7(timers)
Micro c lab7(timers)Micro c lab7(timers)
Micro c lab7(timers)Mashood
 
MICROCONTROLLER TIMERS.ppt
MICROCONTROLLER TIMERS.pptMICROCONTROLLER TIMERS.ppt
MICROCONTROLLER TIMERS.pptreemasajin1
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Aarav Soni
 

Similar to 8051 timers (20)

8051 Microcontroller Timer
8051 Microcontroller Timer8051 Microcontroller Timer
8051 Microcontroller Timer
 
Timers
TimersTimers
Timers
 
TIMERS.pptx
TIMERS.pptxTIMERS.pptx
TIMERS.pptx
 
Timers
TimersTimers
Timers
 
8051 timer
8051 timer8051 timer
8051 timer
 
Timer And Counter in 8051 Microcontroller
Timer And Counter in 8051 MicrocontrollerTimer And Counter in 8051 Microcontroller
Timer And Counter in 8051 Microcontroller
 
Timers
TimersTimers
Timers
 
lecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.pptlecture 12 counter_microcontroller2.ppt
lecture 12 counter_microcontroller2.ppt
 
8051 timers--2
   8051 timers--2   8051 timers--2
8051 timers--2
 
8051 ch9
8051 ch98051 ch9
8051 ch9
 
6-Interrupts Programming-27-03-2024.pptx
6-Interrupts Programming-27-03-2024.pptx6-Interrupts Programming-27-03-2024.pptx
6-Interrupts Programming-27-03-2024.pptx
 
5-Timer Mode 2 Programming-18-03-2024.pptx
5-Timer Mode 2 Programming-18-03-2024.pptx5-Timer Mode 2 Programming-18-03-2024.pptx
5-Timer Mode 2 Programming-18-03-2024.pptx
 
Timers of 8051
Timers of 8051Timers of 8051
Timers of 8051
 
8051 Timers
8051 Timers8051 Timers
8051 Timers
 
Micro c lab7(timers)
Micro c lab7(timers)Micro c lab7(timers)
Micro c lab7(timers)
 
9 timer programming
9 timer programming9 timer programming
9 timer programming
 
MICROCONTROLLER TIMERS.ppt
MICROCONTROLLER TIMERS.pptMICROCONTROLLER TIMERS.ppt
MICROCONTROLLER TIMERS.ppt
 
8051e
8051e8051e
8051e
 
4.Timer_1.ppt
4.Timer_1.ppt4.Timer_1.ppt
4.Timer_1.ppt
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)
 

Recently uploaded

VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01KreezheaRecto
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSrknatarajan
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 

Recently uploaded (20)

VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 

8051 timers

  • 1. 8051 Microcontroller Timers & Counters Prepared by: Manu Thomas manut46@gmail.com 1 12/11/2014
  • 2. The 8051 Timers The 8051 comes equipped with two timers, both of which may be controlled, set, read, and configured individually. he 8051 timers have three general functions: 1) Keeping time and/or calculating the amount of time between events, 2) Counting the events themselves, or 3) Generating baud rates for the serial port. The 8051 microcontroller has 2 timers/counters called T0 and T1. As their names suggest, their main purpose is to measure time and count external events. Besides, they can be used for generating clock pulses to be used in serial communication, so called Baud Rate. manut46@gmail.com 2 12/11/2014
  • 3. Timer T0 The timer T0 consists of two registers – TH0 and TL0 representing a low and a high byte of one 16-digit binary number. Formula used to calculate values in these two registers is very simple: TH0 × 256 + TL0 = T Since the timer T0 is virtually 16-bit register, the largest value it can store is 65 535. In case of exceeding this value, the timer will be automatically cleared and counting starts from 0. This condition is called an overflow. Two registers TMOD and TCON are closely connected to this timer and control its operation. manut46@gmail.com 3 12/11/2014
  • 4. TMOD Register (Timer Mode) The TMOD register selects the operational mode of the timers T0 and T1 The low 4 bits (bit0 - bit3) refer to the timer 0, The high 4 bits (bit4 - bit7) refer to the timer 1 manut46@gmail.com 4 12/11/2014
  • 5. TMOD Register (Timer Mode) cont.. Bits of this register have the following function: GATE1 Enables and disables Timer 1 by means of a signal brought to the INT1 pin (P3.3): 1 - Timer 1 operates only if the INT1 bit is set. 0 - Timer 1 operates regardless of the logic state of the INT1 bit. C/T1 Selects pulses to be counted up by the timer/counter 1: 1 - Timer counts pulses brought to the T1 pin (P3.5). 0 - Timer counts pulses from internal oscillator. manut46@gmail.com 5 12/11/2014
  • 6. TMOD Register (Timer Mode) cont.. T1M1,T1M0 These two bits select the operational mode of the Timer 1. T1M1 T1M0 MODE DESCRIPTION 0 0 0 13-bit timer 0 1 1 16-bit timer 1 0 2 8-bit auto-reload 1 1 3 Split mode manut46@gmail.com 6 12/11/2014
  • 7. TMOD Register (Timer Mode) cont.. GATE0 Enables and disables Timer 0 by means of a signal brought to the INT1 pin (P3.2): 1 - Timer 0 operates only if the INT0 bit is set. 0 - Timer 0 operates regardless of the logic state of the INT0 bit. C/T10 Selects pulses to be counted up by the timer/counter 0: 1 - Timer counts pulses brought to the T0 pin (P3.4). 0 - Timer counts pulses from internal oscillator. manut46@gmail.com 7 12/11/2014
  • 8. TMOD Register (Timer Mode) cont.. T0M1,T0M0 These two bits select the operational mode of the Timer 0. T0M1 T0M0 MODE DESCRIPTION 0 0 0 13-bit timer 0 1 1 16-bit timer 1 0 2 8-bit auto-reload 1 1 3 Split mode manut46@gmail.com 8 12/11/2014
  • 9. TMOD Register (Timer Mode) cont.. manut46@gmail.com 9 12/11/2014
  • 10. Timer Control (TCON) Register TCON register is also one of the registers whose bits are directly in control of timer operation. Only 4 bits of this register are used for this purpose, while rest of them is used for interrupt control manut46@gmail.com 10 12/11/2014
  • 11. Timer Control (TCON) Register cont.. Bits of this register have the following function: TF1 bit is automatically set on the Timer 1 overflow. TR1 bit enables the Timer 1. 1 - Timer 1 is enabled. 0 - Timer 1 is disabled. TF0 bit is automatically set on the Timer 0 overflow. TR0 bit enables the timer 0. 1 - Timer 0 is enabled. 0 - Timer 0 is disabled. manut46@gmail.com 11 12/11/2014
  • 13. Timer 0 in mode 0 (13-bit timer) This mode configures timer 0 as a 13-bit timer which consists of all 8 bits of TH0 and the lower 5 bits of TL0. As a result, the Timer 0 uses only 13 of 16 bits How does it operate Each coming pulse causes the lower register bits to change their states. After receiving 32 pulses, this register is loaded and automatically cleared, while the higher byte (TH0) is incremented by 1. This process is repeated until registers count up 8192 pulses. After that, both registers are cleared and counting starts from 0. manut46@gmail.com 13 12/11/2014
  • 14. Timer 0 in mode 0 (13-bit timer) Cont.. Configuration manut46@gmail.com 14 12/11/2014
  • 15. Timer 0 in mode 1 (16-bit timer) Mode 1 configures timer 0 as a 16-bit timer It uses all the bits of both registers TH0 and TL0. This is one of the most commonly used modes. Timer operates in the same way as in mode 0, with difference that the registers count up to 65 536 as allowable by the 16 bits. manut46@gmail.com 15 12/11/2014
  • 16. Timer 0 in mode 1 (16-bit timer) Cont.. manut46@gmail.com 16 12/11/2014
  • 17. Timer 0 in mode 2 (Auto-Reload Timer) Mode 2 configures timer 0 as an 8-bit timer. Actually, timer 0 uses only one 8-bit register for counting and never counts from 0, but from an arbitrary value (0-255) stored in another (TH0) register. In fact, only the TL0 register operates as a timer, while another (TH0) register stores the value from which the counting starts When the TL0 register is loaded, instead of being cleared, the contents of TH0 will be reloaded to it. manut46@gmail.com 17 12/11/2014
  • 18. Timer 0 in mode 2 (Auto-Reload Timer) manut46@gmail.com 18 12/11/2014
  • 19. Timer 0 in Mode 3 (Split Timer) Mode 3 configures timer 0 so that registers TL0 and TH0 operate as separate 8-bit timers. In other words, the 16-bit timer consisting of two registers TH0 and TL0 is split into two independent 8-bit timers. This mode is provided for applications requiring an additional 8-bit timer or counter. The TL0 timer turns into timer 0, while the TH0 timer turns into timer 1. All the control bits of 16-bit Timer 1 (consisting of the TH1 and TL1 register), now control the 8-bit Timer 1. Even though the 16-bit Timer 1 can still be configured to operate in any of modes (mode 1, 2 or 3), it is no longer possible to disable it as there is no control bit to do it. Thus, its operation is restricted when timer 0 is in mode 3. manut46@gmail.com 19 12/11/2014
  • 20. Timer 0 in Mode 3 (Split Timer) manut46@gmail.com 20 12/11/2014