6) B-1
6) B-1
Timers are
used to measure the time and for creating time delays . Counters are used to count the events
or tasks that are taking place outside the microcontrollers. We can setup these timers and
counters with the microcontrollers to make our tasks in different ways to fit in different
tasks.Types of 8051 Timers and Counters
The 8051 microcontroller mainly has two timers , Timer 0 and Timer 1. These are used as both
timers as well as counters. They are 16-bit long but the format of the microcontroller is 8-bit, due
to that the Timers or counters are divided into two 8-bit parts: a low byte and a high byte. Let’s
see one by one,
● TL0 is the lower 8-bit register of Timer 0.It stores the lower byte of the count value.When
timer 0 functions as a 16-bit timer, TL0 increases first, and TH0 increases by one
following an overflow (when 255 is achieved).
TH0 (Timer 0 High Byte)
● TH0 is the upper 8-bit register of Timer 0.It stores the higher byte of the count
value.When TL0 overflows, Timer 0 can count up to 65,535 (FFFFH) before spilling
since TH0 is increased.
Structure of Timer 0:
Timer Control Registers-TCON and TMOD
TCON and TMOD are the special function registers in the 8051 microcontroller. These are used
to control the timers and counters.
● So, to make the timers and counters work, you need to set up TCON and TMOD
properly. In this way, you can use the timers to measure time or count events, depending
on what you need for your task.
Structure of TCON:
The TCON register is an 8-bit register, where each bit has a specific function:
6–TR1 (Timer 1 Run Control Bit)-Set to 1 to start Timer 1, and set to 0 to stop Timer 1.
4–TR0 (Timer 0 Run Control Bit)-Set to 1 to start Timer 0, and set to 0 to stop Timer 0.
● The TMOD (Timer Mode Register) is a special function register in the 8051
microcontroller. Timer 0 and Timer 1 are the modes of operation that it is utilized to set.
Whether a timer or counter needs to be set, it is done so using this register. The
structure in detail is displayed below.