
PROGRAMMING THE PERIPHERALS OF 8051 20-13
ORG 0
MOV TMOD,#10H ;mode 1 timer 1
BACK: MOV TL1,#42H ;load low byte of count
MOV TH1,#80H ;load high byte of count
SETB TR1 ;start the timer
CPL P2.4 ;complement P2.4
ACALL DELAY ;call delay procedure
SJMP BACK ;jump to BACK
DELAY: JNB TF1,DELAY ;jump to delay if TF1! = 1
CLR TR1 ;stop the timer
CLR TF1 ;clear the timer flag
RET ;return to main program
END
This program generates a square wave as shown in Fig. 20.14, on pin P2.4. The delay is
written as a procedure. The pin is complemented for every delay of 32 msecs.
Example 20.4
Write a program to generate a square wave of 20 msecs at pin P1.4, ...