/*查询方式扫描*/
/*键盘输入0~9 , P1口显示输入数字,P0,P2显示输入数的平方,分别为十,个位*/
ORG 0000H
AJMP MAIN
ORG 0030H
MAIN: LCALL SCAN_KEY /* 主程序:扫描键盘 */
JZ MAIN /*累加器判零,为零就跳*/
LCALL DEL10MS /*延时10毫秒去抖*/
LCALL SCAN_KEY
JZ MAIN
MOV P3 ,#7FH /* 列扫描P3口高四位,扫描P3.7 */
JNB P3.0 ,L3
JNB P3.1 ,L6
JNB P3.2 ,L9
MOV P3 ,#0BFH /* 扫描P3.6 */
JNB P3.0 ,L2
JNB P3.1 ,L5
JNB P3.2 ,L8
JNB P3.3 ,L0
MOV P3 ,#0DFH /*扫描P3.5*/
JNB P3.0 ,L1
JNB P3.1 ,L4
JNB P3.2 ,L7
AJMP MAIN /*无键按下返回主程序循环*/
L0: MOV A ,#00H
AJMP GOON
L1: MOV A ,#01H
AJMP GOON
L2: MOV A ,#02H
AJMP GOON
L3: MOV A ,#03H
AJMP GOON
L4: MOV A ,#04H
AJMP GOON
L5: MOV A ,#05H
AJMP GOON
L6: MOV A ,#06H
AJMP GOON
L7: MOV A ,#07H
AJMP GOON
L8: MOV A ,#08H
AJMP GOON
L9: MOV A ,#09H
AJMP GOON
GOON: MOV 30H ,A
MOV DPTR ,#DIS_TAB
MOVC A ,@A+DPTR
MOV P1 ,A
MOV A ,30H
MOV DPTR ,#TAB
MOVC A ,@A+DPTR
MOV DPTR ,#DIS_TAB
PUSH ACC /*将A中内容压栈*/
ANL A ,#0FH
MOVC A ,@A+DPTR
MOV P2 ,A
POP ACC /*释放栈中内容到A中*/
SWAP A
ANL A ,#0FH
MOVC A ,@A+DPTR
MOV P0 ,A
LCALL DEL10MS
LJMP MAIN
ORG 0200H /*累加器为零
SCAN_KEY: MOV P3 ,#0FH
MOV A ,P3
ORL A ,#0F0H
CPL A
RET
ORG 0250H
DEL10MS: MOV R5 ,#0BH /*10毫秒延时*/
D1: MOV R6 ,#02H
D2: MOV R7 ,#0FFH
D3: DJNZ R7 ,D3
DJNZ R6 ,D2
DJNZ R5 ,D1
RET
ORG 0300H
TAB: DB 00H,01H,04H,09H,16H,25H,36H,49H,64H,81H
ORG 0350H
DIS_TAB:DB 0C0H,0F9H,0A4H,0B0H,099H,092H,082H,0F8H /*数据表显示:0,1,2,3,4,5,6,7 */
DB 080H,090H,088H,083H,0C6H,0A1H,086H,08EH /* 8,9, */
.
END
文章评论(0条评论)
登录后参与讨论