Philips Semiconductors Product data
P87LPC767
Low power, low price, low pin count (20 pin)
microcontroller with 4-kbyte OTP and 8-bit A/D converter
2002 Mar 25
31
Timer/Counters
The P87LPC767 has two general purpose counter/timers which are
upward compatible with the standard 80C51 Timer 0 and Timer 1.
Both can be configured to operate either as timers or event counters
(see Figure 24). An option to automatically toggle the T0 and/or T1
pins upon timer overflow has been added.
In the “Timer” function, the register is incremented every machine
cycle. Thus, one can think of it as counting machine cycles. Since a
machine cycle consists of 6 CPU clock periods, the count rate is 1/6
of the CPU clock frequency. Refer to the section Enhanced CPU for
a description of the CPU clock.
In the “Counter” function, the register is incremented in response to
a 1-to-0 transition at its corresponding external input pin, T0 or T1.
In this function, the external input is sampled once during every
machine cycle. When the samples of the pin state show a high in
one cycle and a low in the next cycle, the count is incremented. The
new count value appears in the register during the cycle following
the one in which the transition was detected. Since it takes 2
machine cycles (12 CPU clocks) to recognize a 1-to-0 transition, the
maximum count rate is 1/6 of the CPU clock frequency. There are no
restrictions on the duty cycle of the external input signal, but to
ensure that a given level is sampled at least once before it changes,
it should be held for at least one full machine cycle.
The “Timer” or “Counter” function is selected by control bits C/T in
the Special Function Register TMOD. In addition to the “Timer” or
“Counter” selection, Timer 0 and Timer 1 have four operating
modes, which are selected by bit-pairs (M1, M0) in TMOD. Modes 0,
1, and 2 are the same for both Timers/Counters. Mode 3 is different.
The four operating modes are described in the following text.
BIT SYMBOL FUNCTION
TMOD.7 GATE Gating control for Timer 1. When set, Timer/Counter is enabled only while the INT1
pin is high and
the TR1 control pin is set. When cleared, Timer 1 is enabled when the TR1 control bit is set.
TMOD.6 C/T
Timer or Counter Selector for Timer 1. Cleared for Timer operation (input from internal system clock.)
Set for Counter operation (input from T1 input pin).
TMOD.5, 4 M1, M0 Mode Select for Timer 1 (see table below).
TMOD.3 GATE Gating control for Timer 0. When set, Timer/Counter is enabled only while the INT0
pin is high and
the TR0 control pin is set. When cleared, Timer 0 is enabled when the TR0 control bit is set.
TMOD.2 C/T
Timer or Counter Selector for Timer 0. Cleared for Timer operation (input from internal system clock.)
Set for Counter operation (input from T0 input pin).
TMOD.1, 0 M1, M0 Mode Select for Timer 0 (see table below).
M1, M0
Timer Mode
0 0 8048 Timer “TLn” serves as 5-bit prescaler.
0 1 16-bit Timer/Counter “THn” and “TLn” are cascaded; there is no prescaler.
1 0 8-bit auto-reload Timer/Counter. THn holds a value which is loaded into TLn when it overflows.
1 1 Timer 0 is a dual 8-bit Timer/Counter in this mode. TL0 is an 8-bit Timer/Counter controlled by the
standard Timer 0 control bits. TH0 is an 8-bit timer only, controlled by the Timer 1 control bits (see
text). Timer 1 in this mode is stopped.
M0
SU01171
M1C/TGATEM0M1C/TGATE
01234567
TMOD
Reset Value: 00h
Not Bit Addressable
Address: 89h
T1 T0
Figure 24. Timer/Counter Mode Control Register (TMOD)
Philips Semiconductors Product data
P87LPC767
Low power, low price, low pin count (20 pin)
microcontroller with 4-kbyte OTP and 8-bit A/D converter
2002 Mar 25
32
Mode 0
Putting either Timer into Mode 0 makes it look like an 8048 Timer,
which is an 8-bit Counter with a divide-by-32 prescaler. Figure 26
shows Mode 0 operation.
In this mode, the Timer register is configured as a 13-bit register. As
the count rolls over from all 1s to all 0s, it sets the Timer interrupt
flag TFn. The count input is enabled to the Timer when TRn = 1 and
either GATE = 0 or INTn
= 1. (Setting GATE = 1 allows the Timer to
be controlled by external input INTn
, to facilitate pulse width
measurements). TRn is a control bit in the Special Function Register
TCON (Figure 25). The GATE bit is in the TMOD register.
The 13-bit register consists of all 8 bits of THn and the lower 5 bits
of TLn. The upper 3 bits of TLn are indeterminate and should be
ignored. Setting the run flag (TRn) does not clear the registers.
Mode 0 operation is the same for Timer 0 and Timer 1. See
Figure 26. There are two different GATE bits, one for Timer 1
(TMOD.7) and one for Timer 0 (TMOD.3).
BIT SYMBOL FUNCTION
TCON.7 TF1 Timer 1 overflow flag. Set by hardware on Timer/Counter overflow. Cleared by hardware when the
interrupt is processed, or by software.
TCON.6 TR1 Timer 1 Run control bit. Set/cleared by software to turn Timer/Counter 1 on/off.
TCON.5 TF0 Timer 0 overflow flag. Set by hardware on Timer/Counter overflow. Cleared by hardware when the
processor vectors to the interrupt routine, or by software.
TCON.4 TR0 Timer 0 Run control bit. Set/cleared by software to turn Timer/Counter 0 on/off.
TCON.3 IE1 Interrupt 1 Edge flag. Set by hardware when external interrupt 1 edge is detected. Cleared by
hardware when the interrupt is processed, or by software.
TCON.2 IT1 Interrupt 1 Type control bit. Set/cleared by software to specify falling edge/low level triggered
external interrupts.
TCON.1 IE0 Interrupt 0 Edge flag. Set by hardware when external interrupt 0 edge is detected. Cleared by
hardware when the interrupt is processed, or by software.
TCON.0 IT0 Interrupt 0 Type control bit. Set/cleared by software to specify falling edge/low level triggered
external interrupts.
IT0
SU01172
IE0IT1IE1TR0TF0TR1TF1
01234567
TCON
Reset Value: 00h
Bit Addressable
Address: 88h
Figure 25. Timer/Counter Control Register (TCON)
SU01173
TLn
(5 BITS)
THn
(8 BITS)
OSC/6 OR
OSC/12
OVERFLOW
Tn PIN
TnOE
TOGGLE
CONTROL
C/T
= 1
C/T
= 0
Tn PIN
TRn
GATE
INTn
PIN
INTERRUPT
TFn
Figure 26. Timer/Counter 0 or 1 in Mode 0 (13-Bit Counter)
Philips Semiconductors Product data
P87LPC767
Low power, low price, low pin count (20 pin)
microcontroller with 4-kbyte OTP and 8-bit A/D converter
2002 Mar 25
33
Mode 1
Mode 1 is the same as Mode 0, except that all 16 bits of the timer
register (THn and TLn) are used. See Figure 27
Mode 2
Mode 2 configures the Timer register as an 8-bit Counter (TL1) with
automatic reload, as shown in Figure 28. Overflow from TLn not only
sets TFn, but also reloads TLn with the contents of THn, which must
be preset by software. The reload leaves THn unchanged. Mode 2
operation is the same for Timer 0 and Timer 1.
Mode 3
When Timer 1 is in Mode 3 it is stopped. The effect is the same as
setting TR1 = 0.
Timer 0 in Mode 3 establishes TL0 and TH0 as two separate 8-bit
counters. The logic for Mode 3 on Timer 0 is shown in Figure 29.
TL0 uses the Timer 0 control bits: C/T, GATE, TR0, INT0
, and TF0.
TH0 is locked into a timer function (counting machine cycles) and
takes over the use of TR1 and TF1 from Timer 1. Thus, TH0 now
controls the “Timer 1” interrupt.
Mode 3 is provided for applications that require an extra 8-bit timer.
With Timer 0 in Mode 3, an P87LPC767 can look like it has three
Timer/Counters. When Timer 0 is in Mode 3, Timer 1 can be turned
on and off by switching it into and out of its own Mode 3. It can still
be used by the serial port as a baud rate generator, or in any
application not requiring an interrupt.
SU01174
TLn
(8 BITS)
THn
(8 BITS)
OSC/6 OR
OSC/12
OVERFLOW
Tn PIN
TnOE
TOGGLE
CONTROL
C/T
= 1
C/T
= 0
Tn PIN
TRn
GATE
INTn
PIN
INTERRUPT
TFn
Figure 27. Timer/Counter 0 or 1 in Mode 1 (16-Bit Counter)
SU01392
TLn
(8 BITS)
THn
(8 BITS)
OSC/6 or
OSC/12
OVERFLOW
Tn PIN
TnOE
TOGGLE
CONTROL
C/T
= 1
C/T
= 0
Tn PIN
TRn
GATE
INTn
PIN
INTERRUPT
TFn
RELOAD
Figure 28. Timer/Counter 0 or 1 in Mode 2 (8-Bit Auto-Reload)

P87LPC767FN,112

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