ORG 0000H AJMP START ORG OO3OH START:ACALL PB MOV RO,#31H MOV R2,#8 SET:MOV P1,#0FFH MOV A,P1 CJNE A,#0FFH,L8 ;当A≠0FFH时,转移(判断有无按键按下) AJMP SET L8: ACALL DELAY ;调用延时 CJNE A,#0FFH,SAVE AJMP SET ;设置8位密码 SAVE: ACALL BP MOV @R0A ;把A送给R0中内容所指向地址 INC R0 DJNZ R2,SET ;R2-1≠0,转移(判断输入密码够8位否) MOV R5,#16 D2S: ACALL BP ;延时 DJNZ R5,D2S MOV R0,#31H MOV R3,#3 AA1: MOV R2,#8 AA2: MOV P1,#0FFH MOV A,P1 CJNZ A,#0FFH, L9 AJMP AA2 L9ACALL DELAY CJNE A,#0FFH,AA3 AJMP AA2 ;判断输入密码有错误否 AA3: ACALL BP CLR C ;对进位清零 SUBB A, @R0 ;A-@R0-CY(判断输入密码与设置密码相等否) INC R0 CJNE A,#00H,AA4 ;A≠00H,转移 AJMP AA5 AA4: SETB 00H ;记错误一次,00H单元内容置“1” AA5: DJNZ R2,AA2 ;R2-1≠0,转移到AA2(判断输入密码够8位否) JB 00H AA6 ;00H单元=1,转移 CLR P3.2 ;标志=1否 L3 MOV R5,#8 ACALL BP ;延时 DJNZ R4, L3 MOV R3,#3 SETB P3.2 AJMP AA1 AA6:DKNZ R3,AA7 ;判断3次错误到否 MOV R5,#24 L5: MOV R4,#200 L4: ACALL BP ;错误3次,警告1分钟 DJNZ R4,L4 DJNZ R5,L5 MOV R3,#3 AA7: MOV R5,#40 ACALL BP ;延时 DJNZ R5,AA7 AA8: CLR 00H ;错误标志清零 AJMP AA1 BP:CLR P3.7 ;错误次数清零 MOV R7,#250 L2:MOV R6,#124 L1:DJNZ R6,L1 ;R6-1≠0,转移 CPL P3.7 ;P3.7口取反 DJNZ R7,L2 SETB P3.7 ;P3.7口置“1” RET DELAYMOV R7,#20 L7: MOV R6,#125 ;延时(短音提示) L6: DJNZ R6,L6 DJNZ R7,L7 RET END
|