
PROGRAMMING THE PERIPHERALS OF 8051 20-21
Example 20.12
ORG 0
SETB P3.5 ;make P3.5 an i/p pin
SETB P1.1 ;make P1.1 an i/p pin
OPEN: JNB P1.1,OPEN ;test if the transit is open
MOV TMOD,#50H ;timer 1 as counter
MOV TH1,#0FCH ;high byte of count
MOV TL1,#18H ;low byte of count
SETB TR1 ;start counting
CHECK: JNB TF1,CHECK ;test if TF1 is set
SETB P1.0 ;closes relay if count = 1000
CLR TR1 ;stop the counter
SJMP OPEN
END
In Example 20.12, how does the counter count ‘1000’ events?
An initial count of (65,536 – 1000 = 64536 = FC18H) is loaded in the registers. For each
incoming event, this count gets incremented and when it reaches the ...