P89LV51RB2_RC2_RD2_5 © NXP B.V. 2009. All rights reserved.
Product data sheet Rev. 05 — 15 December 2009 31 of 76
NXP Semiconductors
P89LV51RB2/RC2/RD2
8-bit microcontrollers with 80C51 core
6.5 Timer 2
Timer 2 is a 16-bit Timer/counter which can operate as either an event timer or an event
counter, as selected by C/T2 in the special function register T2CON. Timer 2 has four
operating modes: Capture, Auto-reload (up or down counting), Clock-out, and Baud Rate
Generator which are selected according to Table 19 using T2CON (Table 20 and
Table 21) and T2MOD (Table 22 and Table 23).
Fig 10. Timer/counter 0 mode 3 (two 8-bit counters)
002aaa522
osc/2
TR1
TR0
TnGate
INT0 pin
TL0
(8-bits)
TF0
control
overflow
interrupt
TH0
(8-bits)
TF1
control
overflow
interrupt
osc/6
T0 pin
C/T = 0
C/T = 1
Table 19. Timer 2 operating mode
RCLK + TCLK CP/RL2 TR2 T2OE Mode
001016-bit auto reload
011016-bit capture
0011programmable clock-out
1 X 1 0 baud rate generator
XX0Xoff
Table 20. T2CON - Timer/counter 2 control register (address C8H) bit allocation
Bit addressable; reset value: 00H.
Bit 7 6 5 4 3 2 1 0
Symbol TF2 EXF2 RCLK TCLK EXEN2 TR2 C/
T2 CP/RL2
Table 21. T2CON - Timer/counter 2 control register (address C8H) bit descriptions
Bit Symbol Description
7 TF2 Timer 2 overflow flag set by a Timer 2 overflow and must be cleared by
software. TF2 will not be set when either RCLK or TCLK = 1 or when
Timer 2 is in Clock-out mode.
6 EXF2 Timer 2 external flag is set when Timer 2 is in capture, reload or
baud-rate mode, EXEN2 = 1 and a negative transition on T2EX occurs.
If Timer 2 interrupt is enabled, EXF2 = 1 causes the CPU to vector to
the Timer 2 interrupt routine. EXF2 must be cleared by software.
5 RCLK Receive clock flag. When set, causes the UART to use Timer 2
overflow pulses for its receive clock in modes 1 and 3. RCLK = 0
causes Timer 1 overflow to be used for the receive clock.
P89LV51RB2_RC2_RD2_5 © NXP B.V. 2009. All rights reserved.
Product data sheet Rev. 05 — 15 December 2009 32 of 76
NXP Semiconductors
P89LV51RB2/RC2/RD2
8-bit microcontrollers with 80C51 core
6.5.1 Capture mode
In the Capture mode there are two options which are selected by bit EXEN2 in T2CON. If
EXEN2 = 0, Timer 2 is a 16-bit timer or counter (as selected by C/T2 in T2CON) which
upon overflowing sets bit TF2, the Timer 2 overflow bit.
The capture mode is illustrated in Figure 11.
4 TCLK Transmit clock flag. When set, causes the UART to use Timer 2
overflow pulses for its transmit clock in modes 1 and 3. TCLK = 0
causes Timer 1 overflows to be used for the transmit clock.
3 EXEN2 Timer 2 external enable flag. When set, allows a capture or reload to
occur as a result of a negative transition on T2EX if Timer 2 is not being
used to clock the serial port. EXEN2 = 0 causes Timer 2 to ignore
events at T2EX.
2 TR2 Start/stop control for Timer 2. A logic ‘1’ enables the timer to run.
1C/
T2 Timer or counter select. (Timer 2)
0 = internal timer (f
osc
/ 6)
1 = external event counter (falling edge triggered; external clock’s
maximum rate = f
osc
/12
0 CP/
RL2 Capture/Reload flag. When set, captures will occur on negative
transitions at T2EX if EXEN2 = 1. When cleared, auto-reloads will
occur either with Timer 2 overflows or negative transitions at T2EX
when EXEN2 = 1. When either RCLK = 1 or TCLK = 1, this bit is
ignored and the timer is forced to auto-reload on Timer 2 overflow.
Table 22. T2MOD - Timer 2 mode control register (address C9H) bit allocation
Not bit addressable; Reset value: XX00 0000B.
Bit 7 6 5 4 3 2 1 0
Symbol - - - - - - T2OE DCEN
Table 23. T2MOD - Timer 2 mode control register (address C9H) bit descriptions
Bit Symbol Description
7 to 2 - Reserved for future use. Should be set to ‘0’ by user programs.
1 T2OE Timer 2 Output Enable bit. Used in programmable clock-out mode only.
0 DCEN Down Count Enable bit. When set, this allows Timer 2 to be configured
as an up/down counter.
Table 21. T2CON - Timer/counter 2 control register (address C8H) bit descriptions
Bit Symbol Description
P89LV51RB2_RC2_RD2_5 © NXP B.V. 2009. All rights reserved.
Product data sheet Rev. 05 — 15 December 2009 33 of 76
NXP Semiconductors
P89LV51RB2/RC2/RD2
8-bit microcontrollers with 80C51 core
This bit can be used to generate an interrupt (by enabling the Timer 2 interrupt bit in the
IEN0 register). If EXEN2 = 1, Timer 2 operates as described above, but with the added
feature that a 1-to-0 transition at external input T2EX causes the current value in the
Timer 2 registers, TL2 and TH2, to be captured into registers RCAP2L and RCAP2H,
respectively.
In addition, the transition at T2EX causes bit EXF2 in T2CON to be set, and EXF2 like
TF2 can generate an interrupt (which vectors to the same location as Timer 2 overflow
interrupt). The Timer 2 interrupt service routine can interrogate TF2 and EXF2 to
determine which event caused the interrupt.
There is no reload value for TL2 and TH2 in this mode. Even when a capture event occurs
from T2EX, the counter keeps on counting T2 pin transitions or f
osc
/ 6 pulses. Since once
loaded contents of RCAP2L and RCAP2H registers are not protected, once Timer2
interrupt is signalled it has to be serviced before a new capture event on T2EX pin occurs.
Otherwise, the next falling edge on T2EX pin will initiate reload of the current value from
TL2 and TH2 to RCAP2L and RCAP2H and consequently corrupt their content related to
the previously reported interrupt.
6.5.2 Auto-reload mode (up or down counter)
In the 16-bit auto-reload mode, Timer 2 can be configured as either a timer or counter (via
C/T2 in T2CON), then programmed to count up or down. The counting direction is
determined by bit DCEN (Down Counter Enable) which is located in the T2MOD register
(see Table 22 and Table 23). When reset is applied, DCEN = 0 and Timer 2 will default to
counting up. If the DCEN bit is set, Timer 2 can count up or down depending on the value
of the T2EX pin.
Figure 12 shows Timer 2 counting up automatically (DCEN = 0).
Fig 11. Timer 2 in Capture mode
002aaa523
OSC ÷6
T2 pin
C/T2 = 0
C/T2 = 1
TL2
(8-bits)
TH2
(8-bits)
TF2
control
capture
TR2
timer 2
interrupt
EXF2
RCAP2L RCAP2H
control
EXEN2
transition
detector
T2EX pin

P89LV51RD2BN,112

Mfr. #:
Manufacturer:
NXP Semiconductors
Description:
IC MCU 8BIT 64KB FLASH 40DIP
Lifecycle:
New from this manufacturer.
Delivery:
DHL FedEx Ups TNT EMS
Payment:
T/T Paypal Visa MoneyGram Western Union