KEYOUT EQU 0F000H KEYIN EQU 0E000H BUFF0 EQU 7EH BUFF1 EQU 7FH P0RTW1 EQU 0A000H PORTW2 EQU 0B000H PORTD EQU 9000H ORG 0000H AJMP START ORG 0100H START: MOV SP, #60H MOV DPTR, #0C000H MOV A, #0 MOVX @DPTR, A MOV BUFF0, #11H MOV BUFF1, #12H L0: LCALL KEY1 MOV BUFF0, A MOV BUFF1, A LCALL DIR AJMP L0 ;/*.................................*/ KS1: MOV DPTR, #KEYOUT MOV A, #00H MOVX @DPTR, A MOV DPTR, #KEYIN MOVX A, @DPTR CPL A ANL A, #0FH RET ;/*.........................*/ KEY1: ACALL KS1 JNZ LK2 ACALL DIR AJMP KEY1
LK2: MOV R2, #0FEH MOV R4, #0 LK4: MOV DPTR, #KEYOUT MOV A, R2 MOVX @DPTR, A MOV DPTR, #KEYIN MOVX A, @DPTR JB ACC.0, LONE MOV A, #0 AJMP LKP LONE: JB ACC.1, LTWO MOV A, #1 AJMP LKP LTWO: JB ACC.2, LTHREE MOV A, #2 AJMP LKP LTHREE: JB ACC.3, NEXT MOV A, #3 LKP: ADD A, R4 PUSH ACC LK3: ACALL DIR ACALL KS1 JNZ LK3 POP ACC RET NEXT: INC R4 INC R4 INC R4 INC R4 MOV A, R2 JNB ACC.3, KEND RL A MOV R2 , A AJMP LK4 KEND: AJMP KEY1 ;/*...........数码管显示程序.....................*/ DIR: MOV R0, #BUFF0 MOV A, @R0 MOV DPTR, #DAT MOVC A, @A+DPTR MOV DPTR, #PORTD MOVX @DPTR, A MOV A, #0 MOV DPTR, #P0RTW1 MOVX @DPTR, A ACALL DL2MS MOV A, #1 MOV DPTR, #P0RTW1 MOVX @DPTR, A MOV R1, #BUFF1 MOV A, @R1 MOV DPTR, #DAT MOVC A, @A+DPTR
MOV DPTR, #PORTD MOVX @DPTR, A
MOV A, #0 MOV DPTR, #PORTW2 MOVX @DPTR, A ACALL DL2MS MOV A, #1 MOV DPTR, #PORTW2 MOVX @DPTR, A RET
DL1MS: MOV R6, #230 DL: NOP NOP DJNZ R6, DL DJNZ R5, DL1MS RET
DL2MS: MOV R5, #30 ACALL DL1MS RET
DAT: DB 0C0H, 0F9H ,0A4H ,0B0H ,99H ,92H ,82H ,0F8H ,80H ,90H DB 88H, 83H ,0C6H ,0A1H ,86H,8EH DB 7EH,89H ,0CH //数码管显示取数 END
此程序中的接口和楼主的不同,思路可供参考! |