项目:电子密码锁
可以设置6位密码,密码通过键盘输入,若密码正确,则开锁。要求密码可以由用户自己设定,锁打开后可以修改密码。修改之前必须再次输入密码,输入新密码的时候确认两次。如果密码输入错误,报警。
我按照教材上做的proteus仿真如图:(详情见附件中的图片)
但是仿真开始后电子显示屏并没有显示数字,按按键后也没有反应,不知道是啥问题。程序和仿真图都是按照教材画的,教材是《单片机实践教程》(孙明)。谢谢!
程序和仿真也放在附件里了。比较着急,求解答,谢谢。
单片机程序如下:(其实好多内容都是重复的)
- ;八位数码管的段码
- 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位密码
- 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
- 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,#00H
- MOV LED_BIT_2,#00H
- MOV LED_BIT_3,#00H
- MOV LED_BIT_4,#00H
- MOV LED_BIT_5,#00H
- MOV LED_BIT_6,#00H
- MOV LED_BIT_7,#79H
- MOV LED_BIT_8,#73H
- MOV KEY_1,#00H
- MOV KEY_2,#00H
- MOV KEY_3,#00H
- MOV KEY_4,#00H
- MOV KEY_5,#00H
- MOV KEY_6,#00H
- MOV WORD_1,#6
- 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
- ;****************************************
- 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,A0
- LCALL DLY_S
- JNB P3.3,A0
- 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,C1
- MOV ROW,#02H
- CALCU: MOV A,LINE
- MOV B,#03H
- MUL AB
- ADD A,ROW
- MOV VAL,A
- ;******************************************
- ;以下为按键处理程序,对不同的按键做出响应
- CJNE A,#0AH,J1
- 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
- J5: LCALL ALARM_2
- LJMP START
- J4: LCALL ALARM_1
- LJMP START
- J3: INC KEY_CNT ;按下数字键
- MOV A,KEY_CNT
- CJNE A,#07H,K1
- LCALL ALARM_1
- W10: LCALL DISP ;等待按键抬起
- MOV A,P3
- CJNE A,#0FH,W11
- LCALL START
- W11: MOV A,P3
- CJNE A,#0F0H,W12
- LCALL START
- W12: SJMP W10
- LJMP START
- LJMP START
- K1: LCALL SHIFTL
- W20: LCALL DISP
- MOV A,P3
- CJNE A,#0FH,W21
- LJMP A0
- W21: MOV A,P3
- CJNE A,#0F0H,W22
- LJMP A0
- W22: SJMP W20
- 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
- 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
复制代码
|