
Using Timers to Measure Time
The individual bits of TMOD have the following functions:
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | Reset Value |
|
|
|
|
|
|
|
|
|
|
SFR 8EH | 0 | 0 | T2M | T1M | T0M | MD2 | MD1 | MD0 | 01H |
T2M (bit 5)— Timer 2 Clock Select. This bit controls the division of the system clock that drives Timer 2. This bit has no effect when the timer is in baud rate generator or clock output modes. Clearing this bit to 0 maintains 80C32 com- patibility. This bit has no effect on instruction cycle timing.
0:Timer 2 uses a divide by 12 of the crystal frequency.
1:Timer 2 uses a divide by 4 of the crystal frequency.
T1M (bit 4)— Timer 1 Clock Select. This bit controls the division of the system clock that drives Timer 1. Clearing this bit to 0 maintains 8051 compatibility. This bit has no effect on instruction cycle timing.
0:Timer 1 uses a divide by 12 of the crystal frequency.
1:Timer 1 uses a divide by 4 of the crystal frequency.
T0M (bit 3)— Timer 0 Clock Select. This bit controls the division of the system clock that drives Timer 0. Clearing this bit to 0 maintains 8051 compatibility. This bit has no effect on instruction cycle timing.
0:Timer 0 uses a divide by 12 of the crystal frequency.
1:Timer 0 uses a divide by 4 of the crystal frequency.
MD2, MD1, MD0 (bits
|
|
|
|
| RD or WR | RD or WR |
|
|
|
|
| Strobe | Strobe |
|
|
| Stretch |
| Width | Width (∝s) |
MD2 | MD1 | MD0 | Value | MOVX Duration | (SYS CLKs) | at 12MHz |
|
|
|
|
|
|
|
0 | 0 | 0 | 0 | 2 Instruction Cycles | 2 | 0.167 |
|
|
|
|
|
|
|
0 | 0 | 1 | 1 | 3 Instruction Cycles | 4 | 0.333 |
|
|
|
| (default) |
|
|
|
|
|
|
|
|
|
0 | 1 | 0 | 2 | 4 Instruction Cycles | 8 | 0.667 |
|
|
|
|
|
|
|
0 | 1 | 1 | 3 | 5 Instruction Cycles | 12 | 1.000 |
|
|
|
|
|
|
|
1 | 0 | 0 | 4 | 6 Instruction Cycles | 16 | 1.333 |
|
|
|
|
|
|
|
1 | 0 | 1 | 5 | 7 Instruction Cycles | 20 | 1.667 |
|
|
|
|
|
|
|
1 | 1 | 0 | 6 | 8 Instruction Cycles | 24 | 2.000 |
|
|
|
|
|
|
|
1 | 1 | 1 | 7 | 9 Instruction Cycles | 28 | 2.333 |
|
|
|
|
|
|
|
Timers8-3