Lecture 8: Timers
Lecture 8: Timers
Lecture 8: Timers
Timers / Counters
8051 has two 16-bit programmable UP timers/counters. They can be configured to operate either as timers or
as event counters. The names of the two counters are T0 and T1 respectively. The timer content is available
in four 8-bit special function registers, viz, TL0,TH0,TL1 and TH1 respectively.
In the "timer" function mode, the counter is incremented in every machine cycle. Thus, one can think of it as
counting machine cycles. Hence the clock rate is 1/12 th of the oscillator frequency.
In the "counter" function mode, the register is incremented in response to a 1 to 0 transition at its
corresponding external input pin (T0 or T1). It requires 2 machine cycles to detect a high to low transition.
Hence maximum count rate is 1/24 th of oscillator frequency.
The operation of the timers/counters is controlled by two special function registers, TMOD and TCON
respectively.
Timer Mode control (TMOD) Special Function Register:
TMOD register is not bit addressable.
TMOD
Address: 89 H
The input pulse is obtained from the previous stage. If TR1/0 bit is 1 and Gate bit is 0, the counter continues
counting up. If TR1/0 bit is 1 and Gate bit is 1, then the operation of the counter is controlled by input.
This mode is useful to measure the width of a given pulse fed to input.
Timer Mode-1:
This mode is similar to mode-0 except for the fact that the Timer operates in 16-bit mode.