单片机控制的智能密码锁
本密码锁控制器由AT
一、电路组成和原理图
工作原理图如附图一所示, 该电路由AT
图一
二、工作原理
通电复位,电路进入就绪状态,等待用户输入密码。当用户输入密码并按下“输入”键后,如输入密码正确则由P3.0输出开锁控制信号且绿灯亮,如输入密码错误则由P3.1输出密码错误指示信号红灯亮,如连续三次输入密码错误则由P3.2输出报警控制信号且黄灯亮,并且必须等待解出报警后方可重新开锁。
三、源程序
ORG 0000H
MOV P3,#0BFH
MOV R4,#00H
BEGIN: MOV R0,#01FH
MOV R3,#00H
KEY : MOV P1,#0FH
MOV A,P1
ANL A,#0FH
CJNE A,#0FH,KEY1
SJMP KEY
KEY1: MOV P3,#0BFH
LCALL DEL12
MOV A,#0EFH
KEY2: MOV R2,A
MOV P1,A
MOV A,P1
ANL A,#0FH
CJNE A,#0FH,KEY3
MOV A,R2
SETB C
RLC A
JC KEY2
SJMP KEY
KEY3: MOV B,#0FBH
KEY4: RRC A
INC B
JC KEY4
MOV A,R2
SWAP A
KEY5: RRC A
INC B
INC B
INC B
INC B
JC KEY5
KEY6: MOV A,P1
ANL A,#0FH
CJNE A,#0FH,KEY6
LCALL DEL12
LCALL OPREAT
LJMP KEY
ORG 0100H
DEL12: MOV R6,#01EH
DEL2: MOV R7,#64H
DEL1: DJNZ R7,DEL1
DJNZ R6,DEL2
RET
ORG 0200H
OPREAT:INC R0
MOV A,B
MOV @R0,A
CJNE A,#0FH,COUNT
CJNE R3,#08H,ERROR
MOV R1,#20H
MOV B,#00H
MOV DPTR,#TAB
MOVC A,@A+DPTR
CLR C
SUBB A,@R1
JNZ ERROR
INC R1
INC B
DJNZ R3,
OPEN: MOV P3,#0BEH
LJMP $
ERROR: MOV P3,#0BDH
INC R4
CJNE R4,#03H,AGAIN
ALARM: MOV P3,#0B9H
LJMP $
AGAIN: LJMP BEGIN
COUNT: INC R3
RET
TAB:DB 01H,03H,05H,07H,02H,04H,06H,08H
END