$NOPAGING
$MOD252
;BIT PSW.1 is used as general purpose flag ..
ORG 0000H
LJMP START
ORG 0003h
LJMP ExtInt0 ; External interrupt 0 ..
ORG 0100h
START:
SETB TCON.0 ; Int0 active at the edge..
SETB IE.7 ; General interrupt active..
SETB IE.0 ; Int0 is enabled..
START2:
SETB P2.0 ;Motion detector Input
; Metal detector to be connected to /INT0 .. SETB P2.1 - Metal detector Input
CLR P1.0
CLR P1.1
Loop:
JNB P2.0, X
; JNB P2.1, Z
JB PSW.1, Z
SJMP Loop
; = = = = = = = = = = = = = =
X:
SETB P1.0
CLR P1.1
LCALL Delay ;Call Delay
CLR P1.0
CLR P1.1
SJMP START2
Z:
CLR PSW.1 ; Clear flag ..
SETB P1.1
CLR P1.0
LCALL Delay ;Call Delay
CLR P1.0
CLR P1.1
SJMP START2
; = = = = = = = = = = = = = =
Delay:
MOV R2, #50 ;~1s
S1:
MOV R3, #200
S2:
MOV R4, #200
S3:
JB PSW.1, Del_Exit ; If interrupt occured exit delay ..
DJNZ R4, S3
DJNZ R3, S2
DJNZ R2, S1
Del_Exit:
RET
; = = = = = = = = = = = = =
ExtInt0:
SETB PSW.1 ; set flag on interrupt ..
RETI
END