8051 Timers and Counters

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

10/3/2018 8051 Timers and Counters - Electronic Circuits and Diagrams-Electronic Projects and Design

Looking for Latest Electronics Project Kits? CLICK HERE (http://www.store.circuitstoday.com/)


(http://www.circuitstoday.com)

Circuit Diagrams 8051 Microcontroller Circuit Design

Delay Timer Count Down Timer Process Flow

8051 Timers and Counters


(http://www.circuitstoday.com/8051-timers-counters)
 jojo  October 27, 2014  3 Comments

Do Business with G Suite


Automatically saved changes keep the whole o ce in sync. Try it free for 14 days. gsuite.google.com

In this article, we focus on Timers/Counters of the 8051 micro controller. The 8051 has two counters/timers which can be used either as timer to generate a time
delay or as counter to count events happening outside the microcontroller.

                      The 8051 has two timers: timer0 and timer1. They can be used either as timers or as counters. Both timers are 16 bits wide. Since the 8051 has an 8-bit
architecture, each 16-bit is accessed as two separate registers of low byte and high byte. First we shall discuss about Timer0 registers.

Timer0 registers is a 16 bits register and accessed as low byte and high byte. The low byte is referred as a TL0 and the high byte is referred as TH0. These registers can
be accessed like any other registers.

(http://www.circuitstoday.com/wp-content/uploads/2014/10/timer0.png)

 Timer1 registers is also a 16 bits register and is split into two bytes, referred to as TL1 and TH1.

(http://www.circuitstoday.com/wp-content/uploads/2014/10/timer1.png)

http://www.circuitstoday.com/8051-timers-counters 1/11
10/3/2018 8051 Timers and Counters - Electronic Circuits and Diagrams-Electronic Projects and Design

TMOD (timer mode) Register:  This is an 8-bit register which is used by both timers 0 and 1 to set the various timer modes. In this TMOD register, lower 4 bits are set
aside for timer0 and the upper 4 bits are set aside for timer1. In each case, the lower 2 bits are used to set the timer mode and upper 2 bits to specify the operation.

(http://www.circuitstoday.com/wp-content/uploads/2014/10/TMOD.png)

TMOD

In upper or lower 4 bits, rst bit is a GATE bit. Every timer has a means of starting and stopping. Some timers do this by software, some by hardware, and some have
both software and hardware controls. The hardware way of starting and stopping the timer by an external source is achieved by making GATE=1 in the TMOD
register. And if we change to GATE=0 then we do no need external hardware to start and stop the timers.

        The second bit is C/T bit and is used to decide whether a timer is used as a time delay generator or an event counter. If this bit is 0 then it is used as a timer and if it
is 1 then it is used as a counter.

In upper or lower 4 bits, the last bits third and fourth are known as M1 and M0 respectively. These are used to select the timer mode.

M0       M1        Mode      Operating Mode

 0             0              0             13-bit timer mode, 8-bit timer/counter THx and TLx as 5-bit prescalar.

 0             1            1             16-bit timer mode, 16-bit timer/counters THx and TLx are cascaded; There are no prescalar.

 1             0             2             8-bit auto reload mode, 8-bit auto reload timer/counter; THx holds a value which is to be reloaded into TLx each                                                   time it
over ows.

  1             1             3              Spilt timer mode.

Mode 1-  It is a 16-bit timer; therefore it allows values from 0000 to FFFFH to be loaded into the timer’s registers TL and TH. After TH and TL are loaded with a 16-bit
initial value, the timer must be started.  We can do it by “SETB TR0” for timer 0 and “SETB TR1” for timer 1. After the timer is started. It starts count up until it reaches
its limit of FFFFH. When it rolls over from FFFF to 0000H, it sets high a ag bit called TF (timer ag). This timer ag can be monitored. When this timer ag is raised,
one option would be stop the timer with the instructions “CLR TR0“ or CLR TR1 for timer 0 and timer 1 respectively. Again, it must be noted that each timer ag TF0
for timer 0 and TF1 for timer1. After the timer reaches its limit and rolls over, in order to repeat the process the registers TH and TL must be reloaded with the original
value and TF must be reset to 0.

Mode0- Mode 0 is exactly same like mode 1 except that it is a 13-bit timer instead of 16-bit. The 13-bit counter can hold values between 0000 to 1FFFH in TH-TL.
Therefore, when the timer reaches its maximum of 1FFH, it rolls over to 0000, and TF is raised.

Mode 2-  It is  an 8 bit timer that allows only values of 00 to FFH to be loaded into the timer’s register TH. After TH is loaded with 8 bit value, the 8051 gives a copy of
it to TL. Then the timer must be started. It is done by the instruction “SETB TR0” for timer 0 and “SETB TR1” for timer1.  This is like mode 1. After timer is started, it
starts to count up by incrementing the TL register. It counts up   until it reaches its limit of FFH. When it rolls over from FFH to 00. It sets high the TF (timer ag). If  we
are using timer 0, TF0 goes high; if using TF1 then TF1 is raised.  When Tl register rolls from FFH to 00 and TF is set to 1, TL is reloaded automatically with the original
value kept by the TH register. To repeat the process, we must simply clear TF and let it go without any need by the programmer to reload the original value. This makes
mode 2 auto reload, in contrast in mode 1 in which programmer has to reload TH and TL.

Mode3- Mode 3 is also known as a split timer mode. Timer 0 and 1 may be programmed to be in mode 0, 1 and 2 independently of similar mode for other timer. This is
not true for mode 3; timers do not operate independently if mode 3 is chosen for timer 0. Placing timer 1 in mode 3 causes it to stop counting; the control bit TR1 and
the timer 1 ag TF1 are then used by timer0.

 TCON register- Bits and symbol and functions of every bits of TCON are as follows:

http://www.circuitstoday.com/8051-timers-counters 2/11
10/3/2018 8051 Timers and Counters - Electronic Circuits and Diagrams-Electronic Projects and Design

(http://www.circuitstoday.com/wp-content/uploads/2014/10/TCON.png)

BIT          Symbol                                  Functions

7               TF1                         Timer1 over ow ag. Set when timer rolls from all 1s to 0. Cleared

                                                 When the processor vectors to execute interrupt service routine

                                                 Located at program address 001Bh.

6              TR1                         Timer 1 run control bit. Set to 1 by programmer to enable timer to

                                                 count; Cleared to 0 by program to halt timer.

5               TF0                        Timer 0 over ow ag. Same as TF1.

4               TR0                       Timer 0 run control bit.  Same as TR1.

3               IE1                          External interrupt 1 Edge ag. Not related to timer operations.

2               IT1                          External interrupt1 signal type control bit. Set to 1 by program to

                                                 Enable external interrupt 1 to be triggered by a falling edge signal. Set

                                                 To 0 by program to enable a low level signal on external interrupt1 to

                                                 generate an interrupt.

1               IE0                         External interrupt 0 Edge ag. Not related to timer operations.

0               IT0                         External interrupt 0 signal type control bit. Same as IT0.

8051 Microcontroller Count Down Timer

Circuit Timer Set Timer

Categories: 8051 (http://www.circuitstoday.com/category/8051)

 Previous post (( Next post 


hh

tt

tt

pp

::

//
You may also like:
//

w
w
Interfacing External Memory EEPROM to 8051 Microcontroller (http://www.circuitstoday.com/8051-eeprom-
interfacing) w
w

w
w

http://www.circuitstoday.com/8051-timers-counters 3/11
10/3/2018 8051 Timers and Counters - Electronic Circuits and Diagrams-Electronic Projects and Design

Learn to Build Real Time Clock using 8051and DS1307 RTC..Module (http://www.circuitstoday.com/real-time-clock-
8051) cc

Digital Door Lock – Password based Electronic Code Lock using


ii 8051 (http://www.circuitstoday.com/digital-door-lock-
password-based-security-8051) rr

Interfacing stepper motor to 8051 (http://www.circuitstoday.com/interfacing-stepper-motor-to-8051)


cc

How to Interface GSM Module to 8051 Micro Controller-Send


uu and Receive SMS
(http://www.circuitstoday.com/interfacing-gsm-module-to-8051)
ii

tt

ss

tt
We recommend: oo

dd
Audio oscillator circuit (http://www.circuitstoday.com/audio-oscillator-circuit-2)
aa
How to recover/reset admin username and password of Vbulletin forum software (http://www.circuitstoday.com/how-
yy
to-recoverreset-admin-username-and-password-of-vbulletin-forum-software)
..
Handling the Digital Input Output in AVR Micro Controllers (http://www.circuitstoday.com/handling-the-digital-input-
output-in-avr-micro-controllers) cc

oo
Passive tone control circuit (http://www.circuitstoday.com/passive-tone-control-circuit)
m
m
Working of Circuit Breakers (http://www.circuitstoday.com/working-of-circuit-breakers)
//

oo

hu
COMMENTS m
r

m
-
jojo
es
February 4, 2015
to

ec
@Abdul – Please subscribe to our email newsletter.
ri

 -a

ul
sumit shrivastava s-
November 6, 2014
im

ne
A very nice article in suitable language not only for knowledge full person
gd
but also for beginner.The writer is surely having good and deep knowledge its re ects in the contents of the article. AWESOME! waiting for next article .
-i
THANKS A LOT aa

r-

dp
sumit shrivastava ur
November 6, 2014
io

nf
thank you sir
oi

)l

e

LEAVE A REPLY )

http://www.circuitstoday.com/8051-timers-counters 4/11
10/3/2018 8051 Timers and Counters - Electronic Circuits and Diagrams-Electronic Projects and Design

Your email address will not be published. Required elds are marked *

Comment

Name *

Email *

Website

POST COMMENT

SORT BY TYPE

101-Announcements (http://www.circuitstoday.com/category/announcements) (28)

555 Timer IC (http://www.circuitstoday.com/category/555-timer-ic) (16)

8051 (http://www.circuitstoday.com/category/8051) (26)

8051 projects (http://www.circuitstoday.com/category/8051-projects) (21)

Ampli er Circuits (http://www.circuitstoday.com/category/ampli er-circuits) (39)

Arduino (http://www.circuitstoday.com/category/arduino) (70)

ARM (http://www.circuitstoday.com/category/arm) (3)

Audio Circuits (http://www.circuitstoday.com/category/audio-circuits) (104)

Automotive Circuits (http://www.circuitstoday.com/category/automotive-circuits) (28)

AVR (http://www.circuitstoday.com/category/avr) (23)

http://www.circuitstoday.com/8051-timers-counters 5/11
10/3/2018 8051 Timers and Counters - Electronic Circuits and Diagrams-Electronic Projects and Design

Basic Electricity (http://www.circuitstoday.com/category/basic-electricity) (1)

Basic Electronics (http://www.circuitstoday.com/category/basic-electronics) (17)

Battery Circuits (http://www.circuitstoday.com/category/battery-related) (23)

C plus plus (http://www.circuitstoday.com/category/cpluplus) (7)

C Programming (http://www.circuitstoday.com/category/c-programming) (14)

Cable TV Circuits (http://www.circuitstoday.com/category/cable-tv) (1)

Camera Technology (http://www.circuitstoday.com/category/camera) (5)

Clipping and Clamping Circuits (http://www.circuitstoday.com/category/clipping-and-clamping-circuits) (7)

Clocking & Timer Circuits (http://www.circuitstoday.com/category/clocking-timer-circuits) (2)

Conversion Circuits (http://www.circuitstoday.com/category/conversion-circuits) (10)

Counter Circuits (http://www.circuitstoday.com/category/counter-circuits) (2)

Counters (http://www.circuitstoday.com/category/counters) (2)

Digital Electronics (http://www.circuitstoday.com/category/digital-electronics) (11)

Drones (http://www.circuitstoday.com/category/drones) (1)

Education & Training (http://www.circuitstoday.com/category/education-training) (7)

Electronic Components (http://www.circuitstoday.com/category/components) (31)

Electronic Keys & Locks (http://www.circuitstoday.com/category/electronic-keys-locks) (3)

Electronics Books (http://www.circuitstoday.com/category/electronics-books) (10)

Electronics Jobs (http://www.circuitstoday.com/category/electronics-jobs) (5)

Embedded Systems (http://www.circuitstoday.com/category/embedded-systems) (7)

Equipment Reviews (http://www.circuitstoday.com/category/equipment-reviews) (1)

Events (http://www.circuitstoday.com/category/events) (3)

Fan Circuits (http://www.circuitstoday.com/category/fan-circuits) (1)

Filter Circuits (http://www.circuitstoday.com/category/ lter-circuits) (16)

Fire Alarm (http://www.circuitstoday.com/category/ re-alarm) (3)

Fun & Game Circuits (http://www.circuitstoday.com/category/fun-game) (14)

Gadget Reviews (http://www.circuitstoday.com/category/gadget-reviews) (6)

Guides (http://www.circuitstoday.com/category/guides) (15)

Ham Radio Circuits (http://www.circuitstoday.com/category/ham-radio-circuits) (2)

High Voltage Circuits (http://www.circuitstoday.com/category/high-voltage-circuits) (1)

History (http://www.circuitstoday.com/category/history) (26)

Home Circuits (http://www.circuitstoday.com/category/home-circuits) (35)

Industrial Circuits (http://www.circuitstoday.com/category/industrial-circuits) (15)

Industry News (http://www.circuitstoday.com/category/industry-news) (1)

Infographics (http://www.circuitstoday.com/category/infographics) (1)

Instruments (http://www.circuitstoday.com/category/instruments) (13)

Integrated Circuits (http://www.circuitstoday.com/category/integrated-circuits) (20)

Inverters (http://www.circuitstoday.com/category/inverter) (5)

Lab Manuals (http://www.circuitstoday.com/category/lab-manual) (20)

LED related (http://www.circuitstoday.com/category/led-related) (3)

Light Related (http://www.circuitstoday.com/category/light-related) (14)

Lighting Circuits (http://www.circuitstoday.com/category/lighting-circuits) (44)

MATLAB (http://www.circuitstoday.com/category/matlab) (3)

Microcontrollers (http://www.circuitstoday.com/category/microcontrollers) (12)

Mobile Phone Related (http://www.circuitstoday.com/category/mobile-phone-related) (3)

Motor Related (http://www.circuitstoday.com/category/motor-related) (14)

Nanotechnology (http://www.circuitstoday.com/category/nanotechnology) (14)

http://www.circuitstoday.com/8051-timers-counters 6/11
10/3/2018 8051 Timers and Counters - Electronic Circuits and Diagrams-Electronic Projects and Design

Oscillators (http://www.circuitstoday.com/category/oscillators) (25)

PCB (http://www.circuitstoday.com/category/pcb) (2)

Peripheral Interface Controller (PIC) (http://www.circuitstoday.com/category/peripheral-interface-controller-pic) (29)

Power Controller Circuits (http://www.circuitstoday.com/category/power-controller-circuits) (8)

Power Electronics (http://www.circuitstoday.com/category/power-electronics) (3)

Power Supplies (http://www.circuitstoday.com/category/power-supplies) (72)

Product Reviews (http://www.circuitstoday.com/category/product-reviews) (12)

Project Ideas (http://www.circuitstoday.com/category/project-ideas) (1)

Projects (http://www.circuitstoday.com/category/projects) (7)

Proteus (http://www.circuitstoday.com/category/proteus) (16)

Proximity Detectors (http://www.circuitstoday.com/category/proximity-detectors) (3)

Radio Circuits (http://www.circuitstoday.com/category/radio-circuits) (30)

Radio Transmitters (http://www.circuitstoday.com/category/radio-transmitters) (19)

Raspberry Pi (http://www.circuitstoday.com/category/raspberry-pi) (3)

Relays (http://www.circuitstoday.com/category/relays) (3)

Remote Circuits (http://www.circuitstoday.com/category/remote-circuits) (12)

Reviews (http://www.circuitstoday.com/category/reviews) (8)

Robotics (http://www.circuitstoday.com/category/robotics) (7)

RTOS (http://www.circuitstoday.com/category/rtos) (2)

Security & Saftey (http://www.circuitstoday.com/category/security-saftey) (17)

Sensor Circuits (http://www.circuitstoday.com/category/sensor-circuits) (16)

Signal Conditioners (http://www.circuitstoday.com/category/signal-conditioners) (11)

Signal Generators (http://www.circuitstoday.com/category/signal-generators) (13)

Speed Controller Circuits (http://www.circuitstoday.com/category/speed-controller-circuits) (1)

State space analysis (http://www.circuitstoday.com/category/state-space-analysis) (2)

Switching Circuits (http://www.circuitstoday.com/category/switching-circuits) (6)

Tech News (http://www.circuitstoday.com/category/tech-news) (86)

Telephone Related (http://www.circuitstoday.com/category/telephone-related) (9)

Television Related (http://www.circuitstoday.com/category/television-related) (4)

Temperature Related (http://www.circuitstoday.com/category/temperature-related) (3)

Test & Measurement Circuits (http://www.circuitstoday.com/category/test-measurement-gadgets) (38)

Testing Components (http://www.circuitstoday.com/category/testing-components) (9)

Three phase circuits (http://www.circuitstoday.com/category/three-phase-circuits) (1)

Timer Circuits (http://www.circuitstoday.com/category/timer-circuits) (3)

Tone generator circuits (http://www.circuitstoday.com/category/tone-generator-circuits) (20)

Tools and Softwares (http://www.circuitstoday.com/category/tools-and-softwares) (6)

Transmitters (http://www.circuitstoday.com/category/transmitters) (7)

Tutorials (http://www.circuitstoday.com/category/tutorials) (163)

UPS (http://www.circuitstoday.com/category/ups) (2)

USB Circuits (http://www.circuitstoday.com/category/usb-circuits) (3)

Videos (http://www.circuitstoday.com/category/videos) (5)

VLSI (http://www.circuitstoday.com/category/vlsi) (36)

Voltage Regulators (http://www.circuitstoday.com/category/voltage-regulators) (15)

http://www.circuitstoday.com/8051-timers-counters 7/11
10/3/2018 8051 Timers and Counters - Electronic Circuits and Diagrams-Electronic Projects and Design

Instant Quote

Dimensions
Length x Width mm

Quantity
Choose Num (pcs)

Layers

2 Layers

Thickness
1.6mm

Get a $5.00 coupons Bonus

Quote Now

(https://www.wellpcb.com/)

OTHER LINKS

About (http://www.circuitstoday.com/about)

Advertise With Us (http://www.circuitstoday.com/advertise-with-us)

Authors (http://www.circuitstoday.com/authors)

Datasheets (http://www.circuitstoday.com/datasheets)

Disclaimer (http://www.circuitstoday.com/disclaimer)

Electronic Circuit Symbols (http://www.circuitstoday.com/electronic-circuit-symbols)

Electronic Project Kits (http://www.circuitstoday.com/project-kits)

Lab Manuals (http://www.circuitstoday.com/lab-manuals)

Electronic Circuits Lab (http://www.circuitstoday.com/lab-manuals/electronic-circuits-lab)

Microcontroller lab (http://www.circuitstoday.com/lab-manuals/microcontroller-lab)

Microprocessor Lab (http://www.circuitstoday.com/lab-manuals/microprocessor-lab)

Privacy Policy (http://www.circuitstoday.com/privacy-policy)

Resistor Color Code Calculator (http://www.circuitstoday.com/resistor-color-code-calculator)

Testing Components (http://www.circuitstoday.com/testing-components)

Write For Us (http://www.circuitstoday.com/write-for-us)

http://www.circuitstoday.com/8051-timers-counters 8/11
10/3/2018 8051 Timers and Counters - Electronic Circuits and Diagrams-Electronic Projects and Design
PCBFOX

PCB Manufacturers (http://pcbfox.com/)

© 2018 CircuitsToday. All rights reserved.

About (http://www.circuitstoday.com/about) | Privacy Policy (http://www.circuitstoday.com/privacy-policy) |


Write For Us|Earn Money (http://www.circuitstoday.com/write-for-us)

Latest Electronic Circuits

http://www.circuitstoday.com/8051-timers-counters 9/11
10/3/2018 8051 Timers and Counters - Electronic Circuits and Diagrams-Electronic Projects and Design

http://www.circuitstoday.com/8051-timers-counters 10/11
10/3/2018 8051 Timers and Counters - Electronic Circuits and Diagrams-Electronic Projects and Design

acebook.com/sharer.php)

http://www.circuitstoday.com/8051-timers-counters 11/11

You might also like