8XC251SA, SB, SP, SQ USER’S MANUAL
8-10
3.
Enter an eight-bit reload value (n
R
) in register TH0. This can be the same as n
0
or
different, depending on the application.
4.
Set the TR0 bit in the TCON register (Figure 8-6) to start the timer. Timer overflow occurs
after FFH + 1 - n
0
peripheral cycles, setting the TF0 flag and loading n
R
into TL0 from
TH0. When the interrupt is serviced, hardware clears TF0.
5.
The timer continues to overflow and generate interrupt requests every FFH + 1 - n
R
peripheral cycles.
6.
To halt the timer, clear the TR0 bit.
8.5.2
Pulse Width Measurements
For timer 0 and timer 1, setting GATEx and TRx allows an external waveform at pin INTx# to
turn the timer on and off. This setup can be used to measure the width of a positive-going pulse
present at pin INTx#. Pulse width measurements using timer 0 in mode 1 can be made as follows:
1.
Program the four low-order bits of the TMOD register (Figure 8-5) to specify: mode 1 for
timer 0, C/T0# = 0 to select F
OSC
/12 as the timer input, and GATE0 = 1 to select INT0 as
timer run control.
2.
Enter an initial value of all zeros in the 16-bit timer register TH0/TL0, or read and store
the current contents of the register.
3.
Set the TR0 bit in the TCON register (Figure 8-6) to enable INT0.
4.
Apply the pulse to be measured to pin INT0. The timer runs when the waveform is high.
5.
Clear the TR0 bit to disable INT0.
6.
Read timer register TH0/TL0 to obtain the new value.
7.
Calculate pulse width = 12 T
OSC
× (new value - initial value).
8.
Example: F
OSC
= 16 MHz and 12T
OSC
= 750 ns. If the new value = 10,000
10
and the initial
value = 0, the pulse width = 750 ns × 10,000 = 7.5 ms.
8.6
TIMER 2
Timer 2 is a 16-bit timer/counter. The count is maintained by two eight-bit timer registers, TH2
and TL2, connected in cascade. The timer/counter 2 mode control register (T2MOD, as shown in
Figure 8-11 on page 8-16) and the timer/counter 2 control register (T2CON, as shown in Figure
8-12 on page 8-17) control the operation of timer 2.
Summary of Contents for 8XC251SA
Page 2: ......
Page 3: ...May 1996 8XC251SA 8XC251SB 8XC251SP 8XC251SQ Embedded Microcontroller User s Manual...
Page 18: ......
Page 19: ...1 Guide to This Manual...
Page 20: ......
Page 30: ......
Page 31: ...2 Architectural Overview...
Page 32: ......
Page 41: ...3 Address Spaces...
Page 42: ......
Page 63: ...4 Device Configuration...
Page 64: ......
Page 81: ...5 Programming...
Page 82: ......
Page 102: ......
Page 103: ...6 Interrupt System...
Page 104: ......
Page 120: ......
Page 121: ...7 Input Output Ports...
Page 122: ......
Page 132: ......
Page 133: ...8 Timer Counters and Watchdog Timer...
Page 134: ......
Page 153: ...9 Programmable Counter Array...
Page 154: ......
Page 170: ......
Page 171: ...10 Serial I O Port...
Page 172: ......
Page 187: ...11 Minimum Hardware Setup...
Page 188: ......
Page 197: ...12 Special Operating Modes...
Page 198: ......
Page 206: ......
Page 207: ...13 External Memory Interface...
Page 208: ......
Page 239: ...14 Programming and Verifying Nonvolatile Memory...
Page 240: ......
Page 250: ......
Page 251: ...A Instruction Set Reference...
Page 252: ......
Page 390: ......
Page 391: ...B Signal Descriptions...
Page 392: ......
Page 400: ......
Page 401: ...C Registers...
Page 402: ......
Page 436: ......
Page 437: ...Glossary...
Page 438: ......
Page 446: ......
Page 447: ...Index...
Page 448: ......
Page 458: ......