本密碼鎖控制器由AT89C2051單片機組成, 工作穩(wěn)定可靠, 保密性高, 實用性強, 并具有報警控制功能。?
一、電路組成和原理圖
工作原理圖如附圖一所示, 該電路由AT89C2051做控制元件, P1口為鍵盤口, 其中P1.4~P1.7為鍵盤掃描輸出口, P1.0~P1.3為鍵盤掃描輸入口; P3口為信號輸出口, 其中P3.0輸出開鎖控制信號去驅(qū)動電磁鎖, P3.1輸出密碼錯信號, P3.2輸出報警控制信號去驅(qū)動報警器。1腳為復位端,4腳、5腳接晶振,各元器件參數(shù)如圖所示。該電路鍵盤由16個按鍵組成,15個“數(shù)字”鍵, 1個“輸入”鍵; 密碼由8位數(shù)字組成(可由用戶對程序稍加修改設(shè)置為任意位數(shù)的密碼),每位數(shù)字均可為15個數(shù)字中的任意一個數(shù),這樣組成的密碼不可破譯,特別是當別人不知密碼位數(shù)時更不可破譯。
圖一
二、工作原理
通電復位,電路進入就緒狀態(tài),等待用戶輸入密碼。當用戶輸入密碼并按下“輸入”鍵后,如輸入密碼正確則由P3.0輸出開鎖控制信號且綠燈亮,如輸入密碼錯誤則由P3.1輸出密碼錯誤指示信號紅燈亮,如連續(xù)三次輸入密碼錯誤則由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? 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
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
?LOOP: MOV A,B
?????? MOVC A,@A+DPTR
?????? CLR C
?????? SUBB A,@R1
?????? JNZ ERROR
?????? INC R1
?????? INC B
?????? DJNZ R3,LOOP
?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
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
?LOOP: MOV A,B
?????? MOVC A,@A+DPTR
?????? CLR C
?????? SUBB A,@R1
?????? JNZ ERROR
?????? INC R1
?????? INC B
?????? DJNZ R3,LOOP
?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