
20-18
x86 MICROPROCESSORS
Example 20.9
ORG 0
MOV TMOD,#02H ;timer 0 in mode 2
MOV TH0,#0H ;TH0 = 0
SETB TR0 ;start the timer
CHECK: JNB TF0,CHECK ;loop to CHECK if TF0 = 0
CLR TF0 ;clear TF0
CPL P1.3 ;complement P1.3
SJMP CHECK ;jump to CHECK
END
The program in Example 20.9 generates a square wave on pin P1.3. It uses Timer 0 in
mode 2. The count loaded in TH0 is 0. Note that, after TF0 is cleared, there is no ‘re-
load’ operation for TH0. The count is automatically re-loaded by the 8051, after the
timer flag is cleared.
Now let us calculate the frequency of the square wave, generated (assuming an 8051
with a clock frequency of 1MHz). ...