START ;初始化
MOV SP.#70H
SETB P3.0
SETB P3.1
SETB P3.2
SETB P3.3
MOV TMOD,#01H
MOV TL0,#00H
MOV TH0,#00H
SETB TR0
SETB ET0
SETB EA
MOV R2,#0FFH
MOV 3AH,#03H
MOV R3,#06H
PASSWORD:MOV R4,#08H ;设置初始密码
MOV R0,#40H
MOV A,#07H
MOV @R0,A
INC R0
INC A
DJNZ R4,PASSWORD
DETPW: MOV R4,#08H ;输入密码
MOV R0,#30H
AGAIN: ACALL INPUT
MOV A,R7
CJ R7,#08H,IN
ACALL CHPSW ;修改密码子程序
JMP GETPW
IN: MOV @R0,A
CLR P3.3 ;按键有效显示
ACALL DELAY
SETB P3.3
COMP: MOV R4,#08H ;比较密码
MOV R0,#30H
AGAI: MOV 50H,@R0
ADD R0,#010H
MOV A,@R0
SUB R0,#010H
CJNE A,50H,ONCEMORE
INC R0
DJNZ R4,AGA1
CLR P3.0
HERE: AJMP HERE
ONCEMORE:CLR P3.4 ;错误输入警告
ACALL DELAY
SETB P3.4
DJNZ R3,GETPW
CLR P3.1 ;6次错误输入报警
THERE: AJMP THERE
2.延时子程序
DELAY: MOV R5,#30H
DELAY1: MOV A,#0FFH
LOOOP: DEC A
JNZ LOOP
DJNZ R5,DELAY1
RET
3.修改密码子程序
CHPSW: MOV R0,#40H
ANOTHER: ACALL INPUT
MOV A,R7
MOV @R0,A
INC R0
CLR P3.3 ;按键有效提示
ACALL DELAY
SETB P3.3
DJNZ R4,ANOTHER
RET
4.扫描键盘输入子程序
INPUT: MOV R6,#02H
MOV R1,#40H
LOP: ACALL DELAY
MOV P1,#0FFH ;扫描码
CLR P1.6
MOV A,P1
ANL A,#0FH ;检验有否按键
CJNE A,#0FH,INKEY
MOV P1,#0FFH
CLR P1.5
MOV A,P1
ANL A,#0FH
CJNE AA,#0FH,INKEY
MOV P1,#0FFH
CLR P1,4
MOV A,P1
ANL A,#0FH
CJNE A,#0FH,INKEY
SJMP LOP
INKEY: MOV @R1,P1
INC R1
DJNZ R6,LOP
DEC R1
MOV A,@R1
DEC R1
CJNE A,40H,INPUT
RET
5.时钟中断子程序
INT: PUSH ACC
MOV TMOD,#01H
MOV TL0,#00H
MOV TH0,#00H
SETB TR0
SETB ET0
SETB EA
DJNZ R2,CONT
CONTINUE
DJNA 3AH,CONT
CLR P3.2 ;时钟中断控制
STOP: AJMP STOP
CONT: POP ACC
RET1