P89LV51RB2_RC2_RD2_5 © NXP B.V. 2009. All rights reserved.
Product data sheet Rev. 05 — 15 December 2009 34 of 76
NXP Semiconductors
P89LV51RB2/RC2/RD2
8-bit microcontrollers with 80C51 core
In this mode, there are two options selected by bit EXEN2 in T2CON register. If
EXEN2 = 0, then Timer 2 counts up to 0FFFFH and sets the TF2 (Overflow Flag) bit upon
overflow. This causes the Timer 2 registers to be reloaded with the 16-bit value in
RCAP2L and RCAP2H. The values in RCAP2L and RCAP2H are preset by software
means.
Auto reload frequency when Timer 2 is counting up can be determined from this formula:
(1)
Where Supply frequency is either f
osc
(C/T2 = 0) or frequency of signal on T2 pin
(C/T2 = 1).
If EXEN2 = 1, a 16-bit reload can be triggered either by an overflow or by a 1-to-0
transition at input T2EX. This transition also sets the EXF2 bit. The Timer 2 interrupt, if
enabled, can be generated when either TF2 or EXF2 is ‘1’.
Microcontroller’s hardware will need three consecutive machine cycles in order to
recognize the falling edge on T2EX and to set EXF2 = 1: in the first machine cycle pin
T2EX has to be sampled as ‘1’; in the second machine cycle it has to be sampled as ‘0’,
and in the third machine cycle EXF2 will be set to ‘1’.
In Figure 13, DCEN = 1 and Timer 2 is enabled to count up or down. This mode allows pin
T2EX to control the direction of count. When a logic ‘1’ is applied at pin T2EX Timer 2 will
count up. Timer 2 will overflow at 0FFFFH and sets the TF2 flag, which can then generate
an interrupt, if the interrupt is enabled. This timer overflow also causes the 16-bit value in
RCAP2L and RCAP2H to be reloaded into the timer registers TL2 and TH2.
Fig 12. Timer 2 in auto-reload mode (DCEN = 0)
002aaa524
OSC ÷6
T2 pin
C/T2 = 0
C/T2 = 1
TL2
(8-bits)
TH2
(8-bits)
TF2
control
reload
TR2
timer 2
interrupt
EXF2
RCAP2L RCAP2H
control
EXEN2
transition
detector
T2EX pin
Supply Frequency
65536 RCAP2H RCAP2L,()()
--------------------------------------------------------------------------------
P89LV51RB2_RC2_RD2_5 © NXP B.V. 2009. All rights reserved.
Product data sheet Rev. 05 — 15 December 2009 35 of 76
NXP Semiconductors
P89LV51RB2/RC2/RD2
8-bit microcontrollers with 80C51 core
A logic 0 applied at pin T2EX causes Timer 2 to count down. The timer will underflow
when TL2 and TH2 become equal to the value stored in RCAP2L and RCAP2H. Timer 2
underflow sets the TF2 flag and causes 0FFFFH to be reloaded into the timer registers
TL2 and TH2. The external flag EXF2 toggles when Timer 2 underflows or overflows. This
EXF2 bit can be used as a 17th bit of resolution if needed.
6.5.3 Programmable clock-out
A 50 % duty cycle clock can be programmed to come out on pin T2 (P1.0). This pin,
besides being a I/O pin, has two additional functions. It can be programmed:
To input the external clock for Timer/counter 2, or
To output a 50 % duty cycle clock ranging from 122 Hz to 8 MHz at a 16 MHz
operating frequency.
To configure the Timer/counter 2 as a clock generator, bit C/T2 (in T2CON) must be
cleared and bit T2OE in T2MOD must be set. Bit TR2 (T2CON.2) also must be set to start
the timer.
The Clock-Out frequency depends on the oscillator frequency and the reload value of
Timer 2 capture registers (RCAP2H, RCAP2L) as shown in Equation 2:
(2)
Where (RCAP2H, RCAP2L) = the content of RCAP2H and RCAP2L taken as a 16-bit
unsigned integer.
In the Clock-Out mode, Timer 2 roll-overs will not generate an interrupt. This is similar to
when it is used as a baud-rate generator.
6.5.4 Baud rate generator mode
Bits TCLK and/or RCLK in T2CON allow the UART transmit and receive baud rates to be
derived from either Timer 1 or Timer 2 (See Section 6.6 “UART” on page 37 for details).
When TCLK = 0, Timer 1 is used as the UART transmit baud rate generator. When
Fig 13. Timer 2 in Auto Reload mode (DCEN = 1)
002aaa525
TL2
(8-bits)
TH2
(8-bits)
TF2
EXF2
underflow
timer 2
interrupt
RCAP2L RCAP2H
FFH FFH
overflow
(down-counting reload value)
(up-counting reload value)
count direction
1 = up
0 = down
T2EX pin
toggle
OSC ÷6
T2 pin
C/T2 = 0
C/T2 = 1
control
TR2
Oscillator Frequency
2 65536 RCAP2H, RCAP2L()()×
-------------------------------------------------------------------------------------
P89LV51RB2_RC2_RD2_5 © NXP B.V. 2009. All rights reserved.
Product data sheet Rev. 05 — 15 December 2009 36 of 76
NXP Semiconductors
P89LV51RB2/RC2/RD2
8-bit microcontrollers with 80C51 core
TCLK = 1, Timer 2 is used as the UART transmit baud rate generator. RCLK has the same
effect for the UART receive baud rate. With these two bits, the serial port can have
different receive and transmit baud rates – Timer 1 or Timer 2.
Figure 14 shows Timer 2 in baud rate generator mode.
The baud rate generation mode is like the auto-reload mode, when a rollover in TH2
causes the Timer 2 registers to be reloaded with the 16-bit value in registers RCAP2H and
RCAP2L, which are preset by software.
The baud rates in modes 1 and 3 are determined by Timer 2’s overflow rate given below:
Modes 1 and 3 baud rates = Timer 2 Overflow Rate / 16
The timer can be configured for either ‘timer’ or ‘counter’ operation. In many applications,
it is configured for ‘timer' operation (C/T2 = 0). Timer operation is different for Timer 2
when it is being used as a baud rate generator.
Usually, as a timer it would increment every machine cycle (i.e.,
1
6
the oscillator
frequency). As a baud rate generator, it increments at the oscillator frequency. Thus the
baud rate formula is as follows:
Modes 1 and 3 baud rates =
(3)
Where: (RCAP2H, RCAP2L) = the content of RCAP2H and RCAP2L taken as a 16-bit
unsigned integer.
The Timer 2 as a baud rate generator mode is valid only if RCLK and/or TCLK = 1 in
T2CON register. Note that a rollover in TH2 does not set TF2, and will not generate an
interrupt. Thus, the Timer 2 interrupt does not have to be disabled when Timer 2 is in the
baud rate generator mode. Also if the EXEN2 (T2 external enable flag) is set, a 1-to-0
transition in T2EX (Timer/counter 2 trigger input) will set EXF2 (T2 external flag) but will
Fig 14. Timer 2 in Baud Rate Generator mode
002aaa526
TX/RX baud rate
timer 2
interrupt
OSC ÷2
T2 pin
C/T2 = 0
C/T2 = 1
TL2
(8-bits)
TH2
(8-bits)
control
TR2
EXF2
RCAP2L RCAP2H
control
EXEN2
transition
detector
T2EX pin
reload
Oscillator Frequency
16 65536 RCAP2H RCAP2L,()()×()
------------------------------------------------------------------------------------------------

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