User Manual
59
T89C51AC2
Rev. B – 19-Dec-01
13. Timer 2 The T89C51A C 2 tim er 2 is c ompatible with timer 2 in the 80C52.
It is a 16-bit timer/counter: the count is mainta ined by tw o eight -bit timer registers, TH2
and TL2 that are cascade- con nec ted. It is contr olle d b y T 2CON regis ter (S ee Table )
and T2MOD regist er (See Table 28). T im er 2 operat ion is similar to Timer 0 and Timer
1. C/T2
selects F
T2 clock
/6 (timer operation) or external pin T2 (c ounter operation) as
timer clock. Setting TR2 allows T L2 to be incremented by the selec ted input.
Timer 2 includes t he following enhancements:
• Au to-reload m ode (up or down counter)
• Programmable clock-output
13.1 Auto-Reload Mode The auto-reload mode configures timer 2 as a 16-bit timer or event counter with auto-
matic reload. T his f eature is controlled by the DCEN bit in T2MOD register (See
Ta bl e 28 ). Se ttin g th e D CE N bit en ab les tim er 2 t o cou nt up or dow n a s sh ow n i n
Figure 27. In this mode the T2EX pin c ontrols the c ounting direct ion.
W hen T2E X is high, timer 2 c ounts up. Timer overflow oc c urs at F FFFh which s et s the
TF2 flag and generat es an interrupt request. T he overflow a lso causes the 16-bit value
in RCAP 2H and RCAP2L registers to be loaded into t he timer registers TH2 and TL2.
W hen T2EX is low, timer 2 c ounts down. Timer underflow o ccurs when the c ount in the
timer registers TH2 and TL2 equals the value sto red in RCAP2H and RCAP2L registers.
The underflow sets TF 2 flag and reloads F FFFh into the time r regist ers .
The EX F2 bit toggles when timer 2 overflow or underflow, depending on the direction of
the c ount . EXF2 do es not generat e a n int errupt . Th is b it can be use d to prov ide 17-bit
resolution.










