8051 Timers and Serial Port: Module - 4
8051 Timers and Serial Port: Module - 4
Mode 2:
Load the TMOD value register indicating which timer (0 or 1) is
to be used; select timer mode 2.
Load TH register with the initial count value. As it is an 8-bit
timer, the valid range is from 00 to FFH.
Start the timer.
Keep monitoring the timer flag (TFx) with the “JNB TFx, target”
instruction to see if it is raised. Get out of the loop when TFx goes
high.
Clear the TFx flag.
Go back to step 4, since mode 2 is auto-reload.
Example 4-1
Indicate which mode and which timer are selected for each
of the following.
(a) MOV TMOD, #01H (b) MOV TMOD, #20H (c) MOV
TMOD, #12H
Solution:
We convert the value from hex to binary. From Figure 9-3
we have:
(a) TMOD = 00000001, mode 1 of timer 0 is selected.
(b) TMOD = 00100000, mode 2 of timer 1 is selected.
(c) TMOD = 00010010, mode 2 of timer 0, and mode 1 of
timer 1 are selected
Example 4-2
Find the timer’s clock frequency and its period
for various 8051-based system, with the crystal
frequency 11.0592 MHz when C/T bit of TMOD
is 0.