Professional Documents
Culture Documents
The 8051 MCU has two timers/counters T0, T1 there main purposes are to either measure the time
between two events or Count external events. In addition, they can be used to generate clock pulses
to be used in serial communication, so called a Baud rate.
o Bit7 GATE1, Bit3 GATE0: enable or disable TimerX by means of signal from INT1,INT0
[Port 3.3 , Port 3.2 respectively].
o Bits5-4 T1M1,T1M0, Bits1-0 T0M1, T0M0 Are the operation mode of T1,T0 there are four
modes:
TxM1 TxM0 mode Operation
0 0 0 13 bit timer
0 1 1 16 bit timer
1 0 2 8 bit auto-reload
1 1 3 Split mode
Timer's modes
0- Mode 0 13-bit timer [Rarely used only for compatibility with older circuits]. This will use all
8 bit from THx and the LOW 5 bits from TLx i.e. [TH(7-0) , TL(5-0)].
So on each pulse the value of TL will be incremented by one until it reach 31 (32 count). On
the 32nd count, TL will be cleared and TH will be incremented by one until 255 (256 count)
thus total count will be 256 x 32 = 8192 count.
On the End timer Overflow flag in TCON (sBit TFx) will be set.
You need to manually reset the overflow time TFx to continue. [Discussed later].
1- Mode 1 16-bit timer same as Mode 0 but uses the whole THx , TLx
In this mode the counter will count from the value in THx till 0x0FF and automatically reload.
When it is goes from 0x0ff to 0x00 it sets the Timer overflow flag TF. In this case programmer
does not need to reload the counter value manually like on Mode 0 and Mode 1.
3- Mode 3 Split mode [Rarely used and we will leave it to rest in peace]
- TCON : (Bit addressable) Timer control register , this register is shared between Timer
operations (the upper four bits) and Interrupt operation [Discussed later] (the lower four bits):
o Bit 7 TF1, Bit 5 TF0: Timer overflow will be set automatically when timer finish and stops
the timer, must be manually reset to repeat the counting.
o Bit 6 TR1, Bit4 TR0: Enable the timer (start) when it is high.