Objectives:: Timers/Counters
Objectives:: Timers/Counters
OBJECTIVES:
MATERIALS:
8051 KEIL IDE
Program 1
Code:
ORG 0000H
MOV TMOD,#01H ; Timer 0 Mode1
HERE:MOV TL0,#66H
MOV TH0,#0FCH TF0=0 TF0 =1
CPL P1.0
ACALL DELAY (FC66,FC67,FC68,….. FFFF) 0000
SJMP HERE
DELAY:SETB TR0
AGAIN:JNB TF0,AGAIN
CLR TR0
CLR TF0
RET
END
Program 2
Code:
MOV TMOD,#20H
MOV TH1,#5
SETB TR1
BACK: JNB TF1,BACK
CPL P1.0
CLR TF1
SJMP BACK
END
Program 3
Assuming that clock pulses are fed into pin T1, write a program for counter 1 in
mode 2 to count the pulses and display the state of the TL1 count on P2, which
connects to 8 LEDs.
Code:
MOV TMOD,#60H
MOV TH1,#0 ;clear TH1
SETB P3.5 ; make T1 input
AGAIN: SETB TR1 ; start the counter
BACK: MOV A,TL1 ;get copy of TL
MOV P2,A ;display it on port 2
JNB TF1,Back ;keep doing, if TF = 0
CLR TR1 ; stop the counter 1
CLR TF1 ; make TF=0
SJMP AGAIN
END