捕获.PNG
(44.71 KB)
这是我的课程设计要求(** 密码锁控制器的设计)
(1)密码数据输入:每按一个数字键,在显示器上显示一个“-”最多可设置6位密码。
(2)密码设置:每按一个数字键,就输入一个数值,并在显示器上的最右方显示出该数值,并将先前已经输入的数据依序左移一个数字位置。注意:密码设置必须是在开锁状态下设置。
(3)数码清除:按下此键可清除前面所有的输入值,清除成为“000000”。
(4)密码更改:按下此键时将目前的数字设定成新的密码。
(5)激活电锁:按下此键可将密码锁上锁。
(6)解除电锁:按下此键会检查输入的密码是否正确,密码正确即开锁。
(7)密码错误:声光报警
以下是我的程序和电路图,仿真时按下键盘第四列不能显示—,其他按键正常,另外使用24C02掉电存储时是否需要程序中写入存入指令,请高手指点,谢谢
LED_BIT_1 EQU 30H
LED_BIT_2 EQU 31H
LED_BIT_3 EQU 32H
LED_BIT_4 EQU 33H
LED_BIT_5 EQU 34H
LED_BIT_6 EQU 35H
LED_BIT_7 EQU 36H
LED_BIT_8 EQU 37H
;以下6个字节存放初始密码
WORD_1 EQU 38H
WORD_2 EQU 39H
WORD_3 EQU 3AH
WORD_4 EQU 3BH
WORD_5 EQU 3CH
WORD_6 EQU 3DH
;以下6个字节存放用户输入的6位密码
KEY_1 EQU 3EH
KEY_2 EQU 3FH
KEY_3 EQU 40H
KEY_4 EQU 41H
KEY_5 EQU 42H
KEY_6 EQU 43H
CNT_A EQU 44H
CNT_B EQU 45H
CNT_C EQU 50H
CNT_D EQU 51H
KEY_CNT EQU 46H ;已输出的密码位数
LINE EQU 47H ;按键行号
ROW EQU 48H ;按键列号
VAL EQU 49H ;键值
;以下为初始化程序,包括数据存储空间初始化,设置初始密码
ORG 00H
SJMP START
ORG 0BH
LJMP INT_T0
START: MOV CNT_A,#00H ;程序初始化
MOV CNT_B,#00H
MOV KEY_CNT,#00H
MOV LINE,#00H
MOV ROW,#00H
MOV VAL,#00H
SETB P1.0
MOV LED_BIT_1,#40H ;段码存储区清0
MOV LED_BIT_2,#40H
MOV LED_BIT_3,#40H
MOV LED_BIT_4,#40H
MOV LED_BIT_5,#40H
MOV LED_BIT_6,#40H
MOV LED_BIT_7,#40H
MOV LED_BIT_8,#40H
MOV KEY_1,#00H ;输入密码存储区清0
MOV KEY_2,#00H
MOV KEY_3,#00H
MOV KEY_4,#00H
MOV KEY_5,#00H
MOV KEY_6,#00H
MOV WORD_1,#6 ;设置初始密码为"123456"
MOV WORD_2,#5
MOV WORD_3,#4
MOV WORD_4,#3
MOV WORD_5,#2
MOV WORD_6,#1
MOV TMOD,#01H
MOV TH0,#(65536-700)/256
MOV TL0,#(65536-700)MOD 256
MOV IE,#82H
A0:LCALL DISP
;以下为键盘扫描程序,计算键值并存入VAL
LSCAN: MOV P3,#0F0H ;扫描行码
L1: JNB P3.0,L2
LCALL DLY_S
JNB P3.0,L2
MOV LINE,#00H
LJMP RSCAN
L2: JNB P3.1,L3
LCALL DLY_S
JNB P3.1,L3
MOV LINE,#01H
LJMP RSCAN
L3: JNB P3.2,L4
LCALL DLY_S
JNB P3.2,L4
MOV LINE,#02H
LJMP RSCAN
L4: JNB P3.3,L1
LCALL DLY_S
JNB P3.3,L1
MOV LINE,#03H
RSCAN:MOV P3,#0FH ;扫描列码
C1: JNB P3.4,C2
MOV ROW,#00H
LJMP CALCU
C2: JNB P3.5,C3
MOV ROW,#01H
LJMP CALCU
C3: JNB P3.6,C4
MOV ROW,#02H
LJMP CALCU
C4: JNB P3.7, C1
MOV ROW,#03H
CALCU: MOV A,LINE ;计算键值
MOV B,#04H
MUL AB
ADD A,ROW
MOV VAL,A ;以下为按键处理程序,对不同的按键作出响应
CJNE A,#0AH,J1 ;是否为"CLR"键
MOV R1,KEY_CNT
CJNE R1,#00H,J2
LCALL ALARM_1
LJMP START
J2: LCALL SHIFTR
DEC KEY_CNT
W00:LCALL DISP ;等待按键抬起
MOV A,P3
CJNE A,#0FH,W01
LJMP A0
W01:MOV A,P3
CJNE A,#0F0H,W02
LJMP A0
W02:SJMP W00
J1: MOV A,VAL
CJNE A,#0BH,J3 ;判断是否为“ENTER”键
MOV R1,KEY_CNT
CJNE R1,#06H,J4
MOV A,WORD_1 ;比较密码
CJNE A,3EH,J5
MOV A,WORD_2
CJNE A,3FH,J5
MOV A,WORD_3
CJNE A,40H,J5
MOV A,WORD_4
CJNE A,41H,J5
MOV A,WORD_5
CJNE A,42H,J5
MOV A,WORD_6
CJNE A,43H,J5
CLR P1.0
LCALL DLY_L
LJMP FINI
J4: LCALL ALARM_1
LJMP START
J5: LCALL ALARM_2
LJMP START
W10:LCALL DISP ;等待按键抬起
MOV A,P3
CJNE A,#0FH,W11
LJMP A0
W11:MOV A,P3
CJNE A,#0F0H,W12
LJMP A0
W12:SJMP W10
LJMP A0
J3: MOV A,VAL ;判断是否为“上锁键”
CJNE A,#0CH,J6
SETB P1.0
MOV R2,#6
MOV CNT_A,#0FFH
MOV CNT_B,#0FFH
MOV CNT_C,#0FFH
MOV CNT_D,#0FFH
MOV KEY_1,#0FFH
MOV KEY_2,#0FFH
MOV KEY_3,#0FFH
MOV KEY_4,#0FFH
MOV KEY_5,#0FFH
MOV KEY_6,#0FFH
W30:LCALL DISP ;等待按键抬起
MOV A,P3
CJNE A,#0FH,W31
LJMP A0
W31:MOV A,P3
CJNE A,#0F0H,W32
LJMP A0
W32:SJMP W30
LJMP A0
LC: MOV R1,#VAL
MOV @R1,#0FFH
DJNZ R2,LC
CALL DLY_S
J6: MOV A,VAL
CJNE A,#0DH,J7 ;判断是否为"NEW"键
JNB P1.0,J4
MOV A,KEY_1
MOV WORD_1,A
MOV A,KEY_2
MOV WORD_2,A
MOV A,KEY_3
MOV WORD_3,A
MOV A,KEY_4
MOV WORD_4,A
MOV A,KEY_5
MOV WORD_5,A
MOV A,KEY_6
MOV WORD_6,A
ACALL DLY_S
J7: INC KEY_CNT ;按下数字键
MOV A,KEY_CNT
CJNE A,#07H,K1
LCALL ALARM_1
LJMP START
W40:LCALL DISP ;等待按键抬起
MOV A,P3
CJNE A,#0FH,W41
LJMP START
W41:MOV A,P3
CJNE A,#0F0H,W42
LJMP START
W42:SJMP W40
LJMP START
LJMP START
K1:LCALL SHIFTL
W50:LCALL DISP ;等待按键抬起
MOV A,P3
CJNE A,#0FH,W51
LJMP A0
W51:MOV A,P3
CJNE A,#0F0H,W52
LJMP A0
W52:SJMP W50
LJMP A0
ALARM_1:SETB TR0 ;操作错误报警
JB TR0,$
RET
ALARM_2:SETB TR0 ;密码错误报警
JB TR0,$
LCALL DLY_L
RET
;定时器中断服务程序,用于声音报警
INT_T0:
CPL P1.7
MOV TH0,#(65536-700)/256
MOV TL0,#(65536-700)MOD 256
INC CNT_A
MOV R1,CNT_A
CJNE R1,#30,RETUNE
MOV CNT_A,#00H
INC CNT_B
MOV R1,CNT_B
CJNE R1,#20,RETUNE
MOV CNT_A,#00H
MOV CNT_B,#00H
INC CNT_C
MOV R1,CNT_C
CJNE R1,#30,RETUNE
MOV CNT_A,#00H
MOV CNT_B,#00H
MOV CNT_C,#00H
INC CNT_D
MOV R1,CNT_D
CJNE R1,#30,RETUNE
MOV CNT_A,#00H
MOV CNT_B,#00H
MOV CNT_C,#00H
MOV CNT_D,#00H
CLR TR0
RETUNE: RETI
;段码,输入密码左移子程序
SHIFTL: MOV LED_BIT_6,LED_BIT_5
MOV LED_BIT_5,LED_BIT_4
MOV LED_BIT_4,LED_BIT_3
MOV LED_BIT_3,LED_BIT_2
MOV LED_BIT_2,LED_BIT_1
MOV LED_BIT_1,#40H
MOV KEY_6,KEY_5
MOV KEY_5,KEY_4
MOV KEY_4,KEY_3
MOV KEY_3,KEY_2
MOV KEY_2,KEY_1
MOV KEY_1,VAL
RET
;段码,输入密码右移子程序
SHIFTR:MOV LED_BIT_1,LED_BIT_2
MOV LED_BIT_2,LED_BIT_3
MOV LED_BIT_3,LED_BIT_4
MOV LED_BIT_4,LED_BIT_5
MOV LED_BIT_5,LED_BIT_6
MOV LED_BIT_6,#00H
MOV KEY_1,KEY_2
MOV KEY_2,KEY_3
MOV KEY_3,KEY_4
MOV KEY_4,KEY_5
MOV KEY_5,KEY_6
MOV KEY_6,#00H
RET
;以下为数码显示子程序
DISP: CLR P2.7
MOV P0,LED_BIT_8
LCALL DLY_S
SETB P2.7
CLR P2.6
MOV P0,LED_BIT_7
LCALL DLY_S
SETB P2.6
CLR P2.5
MOV P0,LED_BIT_6
LCALL DLY_S
SETB P2.5
CLR P2.4
MOV P0,LED_BIT_5
LCALL DLY_S
SETB P2.4
CLR P2.3
MOV P0,LED_BIT_4
LCALL DLY_S
SETB P2.3
CLR P2.2
MOV P0,LED_BIT_3
LCALL DLY_S
SETB P2.2
CLR P2.1
MOV P0,LED_BIT_2
LCALL DLY_S
SETB P2.1
CLR P2.0
MOV P0,LED_BIT_1
LCALL DLY_S
SETB P2.0
RET
DLY_S:MOV R6,#10
D1:MOV R7,#250
DJNZ R7,$
DJNZ R6,D1
RET
DLY_L:MOV R5,#100
D2:MOV R6,#100
D3:MOV R7,#248
DJNZ R7,$
DJNZ R6,D3
DJNZ R5,D2
RET
FINI: NOP
END |