Philips Semiconductors Product data
P89C660/P89C662/P89C664/
P89C668
80C51 8-bit Flash microcontroller family
16KB/32KB/64KB ISP/IAP Flash with 512B/1KB/2KB/8KB RAM
2002 Oct 28
37
OSC
÷ n*
C/T2 = 0
C/T
2 = 1
TR2
CONTROL
TL2
(8 BITS)
TH2
(8 BITS)
TF2
RCAP2L RCAP2H
EXEN2
CONTROL
EXF2
TIMER 2
INTERRUPT
T2EX PIN
TRANSITION
DETECTOR
T2 PIN
RELOAD
SU01253
* n = 6 in 6-clock mode, or 12 in 12-clock mode.
Figure 23. Timer 2 in Auto-Reload Mode (DCEN = 0)
÷ n*
C/T2 = 0
C/T
2 = 1
TL2 TH2
TR2
CONTROL
T2 PIN
SU01254
FFH FFH
RCAP2L RCAP2H
(UP COUNTING RELOAD VALUE) T2EX PIN
TF2
INTERRUPT
COUNT
DIRECTION
1 = UP
0 = DOWN
EXF2
OVERFLOW
(DOWN COUNTING RELOAD VALUE)
TOGGLE
OSC
* n = 6 in 6-clock mode, or 12 in 12-clock mode.
Figure 24. Timer 2 Auto Reload Mode (DCEN = 1)
Philips Semiconductors Product data
P89C660/P89C662/P89C664/
P89C668
80C51 8-bit Flash microcontroller family
16KB/32KB/64KB ISP/IAP Flash with 512B/1KB/2KB/8KB RAM
2002 Oct 28
38
OSC
C/T2 = 0
C/T
2 = 1
TR2
Control
TL2
(8-bits)
TH2
(8-bits)
÷ 16
RCAP2L RCAP2H
EXEN2
Control
EXF2
Timer 2
Interrupt
T2EX Pin
Transition
Detector
T2 Pin
Reload
÷ 2
“0” “1”
RX Clock
÷ 16
TX Clock
“0”“1”
“0”“1”
Timer 1
Overflow
Note availability of additional external interrupt.
SMOD
RCLK
TCLK
SU01213
Figure 25. Timer 2 in Baud Rate Generator Mode
Table 10. Timer 2 Commonly Used Generated
Baud Rates
Baud Rate Timer 2
12 clock
mode
6 clock
mode
Osc Freq
RCAP2H RCAP2L
375 k 750 k 12 MHz FF FF
9.6 k 19.2 k 12 MHz FF D9
2.8 k 5.6 k 12 MHz FF B2
2.4 k 4.8 k 12 MHz FF 64
1.2 k 2.4 k 12 MHz FE C8
300 600 12 MHz FB 1E
110 220 12 MHz F2 AF
300 600 6 MHz FD 8F
110 220 6 MHz F9 57
Baud Rate Generator Mode
Bits TCLK and/or RCLK in T2CON (see Figure 20) allow the serial
port transmit and receive baud rates to be derived from either Timer
1 or Timer 2. When TCLK = 0, Timer 1 is used as the serial port
transmit baud rate generator. When TCLK = 1, Timer 2 is used as
the serial port transmit baud rate generator. RCLK has the same
effect for the serial port receive baud rate. With these two bits, the
serial port can have different receive and transmit baud rates – one
generated by Timer 1, the other by Timer 2.
Table 10 shows commonly used baud rates and how they can be
obtained from Timer 2.
Figure 25 shows Timer 2 in baud rate generation mode. The baud
rate generation mode is similar to the auto-reload mode, in that 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/T
2 = 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 in 6 clock mode,
1
/
12
the oscillator
frequency in 12 clock mode). As a baud rate generator, it increments
at the oscillator frequency in 6 clock mode (f
OSC
/2 in 12 clock
mode). Thus the baud rate formula is as follows:
Oscillator Frequency
[n* [65536 ǒ (RCAP2H, RCAP2L)]]
Modes 1 and 3 Baud Rates =
* n = 16 in 6 clock mode
32 in 12 clock mode
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 shown in Figure 25, 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, 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 not cause a
reload from (RCAP2H, RCAP2L) to (TH2,TL2). Therefore when
Timer 2 is in use as a baud rate generator, T2EX can be used as an
additional external interrupt, if needed.
Philips Semiconductors Product data
P89C660/P89C662/P89C664/
P89C668
80C51 8-bit Flash microcontroller family
16KB/32KB/64KB ISP/IAP Flash with 512B/1KB/2KB/8KB RAM
2002 Oct 28
39
When Timer 2 is in the baud rate generator mode, one should not try
to read or write TH2 and TL2. As a baud rate generator, Timer 2 is
incremented every state time (f
OSC
/2) or asynchronously from pin
T2; under these conditions, a read or write of TH2 or TL2 may not
be accurate. The RCAP2 registers may be read, but should not be
written to, because a write might overlap a reload, and cause write
and/or reload errors. The timer should be turned off (clear TR2)
before accessing Timer 2 or RCAP2 registers.
Summary Of Baud Rate Equations: Timer 2 is in baud rate
generating mode. If Timer 2 is being clocked through pin T2(P1.0)
the baud rate is:
Baud Rate
Timer 2 Overflow Rate
16
If Timer 2 is being clocked internally, the baud rate is:
Baud Rate
f
OSC
[n* [65536 (RCAP2H, RCAP2L)]]
* n = 16 in 6 clock mode
32 in 12 clock mode
Where f
OSC
= Oscillator Frequency
To obtain the reload value for RCAP2H and RCAP2L, the above
equation can be rewritten as:
RCAP2H,RCAP2L 65536
f
OSC
n* Baud Rate
Timer/Counter 2 Set-up
Except for the baud rate generator mode, the values given for T2CON
do not include the setting of the TR2 bit. Therefore, bit TR2 must be
set, separately, to turn the timer on. See Table 11 for set-up of Timer 2
as a timer. Also see Table 12 for set-up of Timer 2 as a counter.
Table 11. Timer 2 as a Timer
T2CON
MODE
INTERNAL CONTROL
(Note 1)
EXTERNAL CONTROL
(Note 2)
16-bit Auto-Reload 00H 08H
16-bit Capture 01H 09H
Baud rate generator receive and transmit same baud rate 34H 36H
Receive only 24H 26H
Transmit only 14H 16H
Table 12. Timer 2 as a Counter
TMOD
MODE
INTERNAL CONTROL
(Note 1)
EXTERNAL CONTROL
(Note 2)
16-bit 02H 0AH
Auto-Reload 03H 0BH
NOTES:
1. Capture/reload occurs only on timer/counter overflow.
2. Capture/reload occurs on timer/counter overflow and a 1-to-0 transition on T2EX (P1.1) pin except when Timer 2 is used in the baud rate
generator mode.

P89C660HBA/00,512

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