beautypg.com

Timer 2, Figure 23. timer/counter mode 2: 8-bit auto-reload, Table 40. timer/counter 2 control register (t2con) – ST & T UPSD3212C User Manual

Page 51

background image

51/163

uPSD3212A, uPSD3212C, uPSD3212CV

Mode 2. Mode 2 configures the Timer register as
an 8-bit Counter (TL1) with automatic reload, as
shown in Figure

23

. Overflow from TL1 not only

sets TF1, but also reloads TL1 with the contents of
TH1, which is preset by software. The reload
leaves TH1 unchanged. Mode 2 operation is the
same for Timer/Counter 0.
Timer 2
Like Timer 0 and 1, Timer 2 can operate as either
an event timer or as an event counter. This is se-
lected by Bit C/T2 in the special function register
T2CON (see Table

40

). It has three operating

modes: Capture, Auto-reload, and Baud Rate
Generator (see

Table 41., page 52

), which are se-

lected by bits in the T2CON as shown in

Table

42., page 52

. In the Capture Mode there are two

options which are selected by Bit EXEN2 in
T2CON. if EXEN2 = 0, then Timer 2 is a 16-bit tim-
er or counter which upon overflowing sets Bit TF2,
the Timer 2 overflow bit, which can be used to gen-
erate an interrupt. If EXEN2 = 1, then Timer 2 still
does the 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. The Cap-
ture Mode is illustrated in

Figure 24., page 53

.

In the Auto-reload Mode, there are again two op-
tions, which are selected by bit EXEN2 in T2CON.
If EXEN2 = 0, then when Timer 2 rolls over it not
only sets TF2 but also causes the Timer 2 regis-
ters to be reloaded with the 16-bit value in regis-
ters RCAP2L and RCAP2H, which are preset by
software. If EXEN2 = 1, then Timer 2 still does the
above, but with the added feature that a 1-to-0
transition at external input T2EX will also trigger
the 16-bit reload and set EXF2. The Auto-reload
Mode is illustrated in Standard Serial Interface
(UART)

Figure 25., page 53

. The Baud Rate Gen-

eration Mode is selected by (RCLK, RCLK1) = 1
and/or (TCLK, TCLK1) = 1. It will be described in
conjunction with the serial port.

Figure 23. Timer/Counter Mode 2: 8-bit Auto-reload

Table 40. Timer/Counter 2 Control Register (T2CON)

7

6

5

4

3

2

1

0

TF2

EXF2

RCLK

TCLK

EXEN2

TR2

C/T2

CP/RL2

AI06623

f

OSC

TF1

Interrupt

Gate

TR1

INT1 pin

T1 pin

Control

TL1

(8 bits)

TH1

(8 bits)

C/T = 0

C/T = 1

ч 12

This manual is related to the following products: