Using Timers to Measure Time
As shown, the value of TH0 never changed. In fact, when mode 2 is used, THx is almost always set to a known value and TLx is the SFR that is constantly incremented. THx is initialized once, and then left unchanged.
The benefit of
When mode 2 is used, the microcontroller takes care of this. Once a timer has been configured in mode 2, it does not have to be checked to see if the timer has overflowed, nor does the value need to be
The
8.3.3.4Split-Timer Mode (mode 3)
Timer mode 3 is a
While Timer 0 is in split mode, the real Timer 1 (i.e. TH1 and TL1) can be put into modes 0, 1, or 2 normally. However, the real Timer 1 may not be started or stopped, because the bits that do that are now linked to TH0. The real Timer 1, in this case, will be incremented every machine cycle no matter what. The real Timer 1 may be stopped by setting it to mode 3.
The only real use of note in using
8.3.4TCON SFR
Finally, there is one more SFR that controls the two timers and provides valu- able information about them. The TCON SFR has the structure described in Table 8−4.
Table 8−4. TCON (88 H ) SFR
Bit | Name | Bit Address | Explanation of Function | Timer |
|
|
|
|
|
|
|
| Timer 1 overflow. This bit is set by the microcontroller |
|
7 | TF1 | 8FH | when Timer 1 overflows. | 1 |
|
|
| Timer 1 run. When this bit is set, Timer 1 is turned on. |
|
6 | TR1 | 8EH | When this bit is clear, Timer 1 is off. | 1 |
|
|
| Timer 0 overflow. This bit is set by the microcontroller |
|
5 | TF0 | 8DH | when Timer 0 overflows. | 0 |
|
|
| Timer 0 run. When this bit is set, Timer 0 is turned on. |
|
4 | TR0 | 8CH | When this bit is clear, Timer 0 is off. | 0 |