MS51
Nov. 28, 2019
Page
287
of 491
Rev 1.00
MS51
32K
SE
RIES
TE
CHNICAL RE
F
EREN
CE MA
N
UAL
6.5
Timer
6.5.1
Timer/Counter 0 And 1
Overview
6.5.1.1
Timer/Counter 0 and 1 on MS51 are two 16-bit Timers/Counters. Each of them has two 8-bit registers
those form the 16-bit counting register. For Timer/Counter 0 they are TH0, the upper 8-bit register, and
TL0, the lower 8-bit register. Similarly Timer/Counter 1 has two 8-bit registers, TH1 and TL1. TCON
and TMOD can configure modes of Timer/Counter 0 and 1.
The Timer or Counter function is selected by the
C/T
̅
bit in TMOD. Each Timer/Counter has its own
selection bit. TMOD.2 selects the function for Timer/Counter 0 and TMOD.6 selects the function for
Timer/Counter 1
When configured as a “Timer”, the timer counts the system clock cycles. The timer clock is 1/12 of the
system clock (F
SYS
) for standard 8051 capability or direct the system clock for enhancement, which is
selected by T0M (CKCON.3) bit for Timer 0 and T1M (CKCON.4) bit for Timer 1. In the “Counter”
mode, the countering register increases on the falling edge of the external input pin T0. If the sampled
value is high in one clock cycle and low in the next, a valid 1-to-0 transition is recognized on T0 or T1
pin.
The Timers 0 and 1 can be configured to automatically to toggle output whenever a timer overflow
occurs. The same device pins that are used for the T0 and T1 count inputs are also used for the timer
toggle outputs. This function is enabled by control bits T0OE and T1OE in the CKCON register, and
apply to Timer 0 and Timer 1 respectively. The port outputs will be logic 1 prior to the first timer
overflow when this mode is turned on. In order for this mode to function, the
C/T
̅
bit should be cleared
selecting the system clock as the clock source for the timer.
Note that the TH0 (TH1) and TL0 (TL1) are accessed separately. It is strongly recommended that in
mode 0 or 1, user should stop Timer temporally by clearing TR0 (TR1) bit before reading from or
writing to TH0 (TH1) and TL0 (TL1). The free-running reading or writing may cause unpredictable
result.
Mode 0 (13-Bit Timer)
6.5.1.2
In Mode 0, the Timer/Counter is a 13-bit counter. The 13-bit counter consists of TH0 (TH1) and the
five lower bits of TL0 (TL1). The upper three bits of TL0 (TL1) are ignored. The Timer/Counter is
enabled when TR0 (TR1) is set and either GATE is 0 or
INT0
̅̅̅̅̅̅̅
(
INT1
̅̅̅̅̅̅̅
) is 1. Gate setting as 1 allows the
Timer to calculate the pulse width on external input pin
INT0
̅̅̅̅̅̅̅
(
INT1
̅̅̅̅̅̅̅
). When the 13-bit value moves
from 1FFFH to 0000H, the Timer overflow flag TF0 (TF1) is set and an interrupt occurs if enabled.
TF0
(TF1)
TH0 (TH1)
TL0 (TL1)
Timer Interrupt
0
4
7
0
7
T0 (T1) pin
T0OE
(T1OE)
0
1
T0 (T1) pin
C/T
GATE
TR0 (TR1)
F
SYS
INT0 (INT1) pin
1/12
0
1
T0M
(T1M)