我把图贴上来了,希望各位指点一下! 下面是我写的程序,不知道哪里出了问题,请指点迷津: ORG 0000H AJMP MAIN ORG 0030H MAIN: ACALL KEY1 ACALL DISPLAY AJMP MAIN KEY: MOV P1,#0FH //置行为0,列为1 MOV A,P1 //读P1口 CJNE A,#0FH,KEY1 AJMP KEY KEY1: ACALL DELAY //延时消抖 MOV P1,#0FH //再读 MOV A,P1 CJNE A,#0FH,KEY2 AJMP KEY KEY2: MOV B,A //存列值 MOV P1,#0EFH //判断行值 MOV A,P1 CJNE A,#0EFH,KEY3 MOV P1,#0DFH MOV A,P1 CJNE A,#0DFH,KEY3 MOV P1,#0BFH MOV A,P1 CJNE A,#0BFH,KEY3 MOV P1,#7FH MOV A,P1 CJNE A,#7FH,KEY3 AJMP KEY KEY3: ANL A,#0FH //存行值 ORL A,B //计算键值 MOV B,A //暂存键值 MOV R1,#16 //比较的次数 MOV R2,#0 //等效键值初值 MOV DPTR,#KEYTAB KEY4: MOVC A,@A+DPTR CJNE A,B,KEY6 //键值与键码表值比较 MOV P1,#0FH //相等则等待按键释放 KEY5: MOV A,P1 CJNE A,#0FH,KEY5 ACALL DELAY MOV A,R2 //存等效键值 ,即最终显示的值 RET KEY6: INC R2 //不相等则继续查表比较 DJNZ R1,KEY4 AJMP KEY KEYTAB: DB 0EEH,0DEH,0BEH,7EH DB 0EDH,0DDH,0BDH,7DH DB 0EBH,0DBH,0BBH,7BH DB 0E7H,0D7H,0B7H,77H DISPLAY: //取等效键值查表显示 MOV DPTR,#SEGTAB MOVC A,@A+DPTR MOV P0,A RET SEGTAB: DB 0C0H,0F9H,0A4H,0B0H//共阴LED,0,1,2,3 DB 99H,92H,82H,0F8H //4,5,6,7 DB 80H,90H,88H,03H //8,9,A,B DB 0A7H,0A1H,04H,8EH //C,D,E,F DELAY: MOV R6,#0 LOOP1: MOV R7,#0 LOOP2: DJNZ R7,LOOP2 DJNZ R6,LOOP1 RET END |