单片机汇编键盘扫描程序(4页).doc
-单片机汇编键盘扫描程序-第 4 页单片机汇编键盘扫描程序键盘接口如图:显示 P0口数码管选择 P2口LED EQU P0KEY EQU P1DUAN EQU P2QIAN EQU 30HHOU EQU 40HXS EQU 50H ORG 00HLJMP START ORG 30HSTART: MOV R0,#50HL1:CLR AMOV R0,AINC R0CJNE R0,#58H,L1MOV DPTR,#SJL2:MOV R0,#50HMOV R2,#00HL3:MOV A,R0MOV LED,AMOV DUAN,R2LCALL DELAYINC R0INC R2 MOV KEY,#0FHJNB P1.0,S1JNB P1.1,S1JNB P1.2,S1JNB P1.3,S1CJNE R2,#08H,L3LJMP L2S1: MOV R5,#10 ;延时20ms去抖DELAY2:LCALL DELAYDJNZ R5,DELAY2MOV B,#00H MOV KEY,#0FHJNB P1.0,S0INC BJNB P1.1,S0INC BJNB P1.2,S0INC BJNB P1.3,S0LJMP L2S0: LCALL SAOLJMP L2SAO: ;键盘输入子程序CLR AMOV KEY,#0F0HJNB P1.4,FZ0INC AJNB P1.5,FZ0INC AJNB P1.6,FZ0INC AJNB P1.7,FZ0RETFZ0: PUSH ACCFZ1:MOV KEY,#0FH MOV A,KEYNOPCJNE A,#0FH,FZ1POP ACC RL A RL A ADD A,BMOVC A,A+DPTRMOV 58H,AMOV R0,#50HMOV R1,#51HLOOP0:MOV A,R1MOV R0,AINC R0INC R1CJNE R0,#58H,LOOP0RETDELAY:;延时2ms子程序 MOV R7,#10DELAY1: MOV R6,#100DJNZ R6,$DJNZ R7,DELAY1RETSJ: DB 06H,5BH,4FH,77H,66H,6DH,7DH,7CH,07H,7FH,6FH,39H,79H,3FH,71H,5EHEND