新闻中心
/*****************************************************
007.ASM
接线:P0口接数码管
P2接矩阵键盘
用定时中断,若一段时间无操作,数码管进入自到循环显示
*******************************************************/
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP INT_T0
ORG 0020H
MAIN: ;主程序
MOV SP,#50H
MOV DPTR,#LED_DATA ;取表首地址
MOV TMOD,#01H ;设置定时器T0工作模式
MOV TH0,#15H ;写计时初值
MOV TL0,#9FH
MOV P2,#0FFH ;P2口赋初值
MOV R4,#00H ;赋定时计数初值
SETB 00H ;00H为键值改变标志位
SETB TR0 ;启动定时器T0
MOV IE,#82H ;开中断
LCALL SHOW ;数码管初始化
loop: ;主循环
LCALL KEY_READ ;读键盘
JBC 00H,LOOP0 ;判断是否有键被按下,有则转去刷新输出并清零定时计数
CJNE R4,#0C8H,LOOP ;没有键被按下,则判断定时时间是否达到,到,则进入数码管循环输出
LCALL SHOW1 ;没到,则回到主循环,重新扫描键盘
SJMP LOOP
LOOP0:
LCALL SHOW
MOV R4,#00H
SJMP LOOP ;输出刷新完毕,回到主循环,重新扫描键盘
/*键盘扫描程序*/
KEY_READ:
CLR P2.6 ;P2.6输出低
JB P2.0,N0_0
MOV R0,#01H
LCALL DELAY
JB P2.0,N0_0
JNB P2.0,$
MOV R5,#04H
SETB 00H
SETB P2.6
LJMP NEAT
N0_0:
JB P2.1,N0_1
MOV R0,#01H
LCALL DELAY
JB P2.1,N0_1
MOV R5,#03H
JNB P2.1,$
SETB 00H
SETB P2.6
LJMP NEAT
N0_1:
JB P2.2,N0_2
MOV R0,#01H
LCALL DELAY
JB P2.2,N0_2
JNB P2.2,$
MOV R5,#02H
SETB 00H
SETB P2.6
LJMP NEAT
N0_2:
JB P2.3,N1_0
MOV R0,#01H
LCALL DELAY
JB P2.3,N1_0
JNB P2.3,$
MOV R5,#01H
SETB 00H
SETB P2.6
LJMP NEAT
N1_0:
SETB P2.6
CLR P2.5
JB P2.0,N1_1
MOV R0,#01H
LCALL DELAY
JB P2.0,N1_1
JNB P2.0,$
MOV R5,#08H
SETB 00H
SETB P2.5
LJMP NEAT
N1_1:
JB P2.1,N1_2
MOV R0,#01H
LCALL DELAY
JB P2.1,N1_2
JNB P2.1,$
MOV R5,#07H
SETB 00H
SETB P2.5
LJMP NEAT
N1_2:
JB P2.2,N1_3
MOV R0,#01H
LCALL DELAY
JB P2.2,N1_3
JNB P2.2,$
MOV R5,#06H
SETB 00H
SETB P2.5
LJMP NEAT
N1_3:
JB P2.3,N2_0
MOV R0,#01H
LCALL DELAY
JB P2.3,N2_0
JNB P2.3,$
MOV R5,#05H
SETB 00H
SETB P2.5
LJMP NEAT
N2_0:
SETB P2.5
CLR P2.4
JB P2.0,N2_1
MOV R0,#01H
LCALL DELAY
JB P2.0,N2_1
JNB P2.0,$
MOV R5,#0CH
SETB 00H
SETB P2.4
LJMP NEAT
N2_1:
JB P2.1,N2_2
MOV R0,#01H
LCALL DELAY
JB P2.1,N2_2
JNB P2.1,$
MOV R5,#0BH
SETB 00H
SETB P2.4
LJMP NEAT
N2_2:
JB P2.2,N2_3
MOV R0,#01H
LCALL DELAY
JB P2.2,N2_3
JNB P2.2,$
MOV R5,#0AH
SETB 00H
SETB P2.4
LJMP NEAT
N2_3:
JB P2.3,NEAT
MOV R0,#01H
LCALL DELAY
JB P2.3,NEAT
JNB P2.3,$
MOV R5,#09H
SETB 00H
SETB P2.4
LJMP NEAT
NEAT:
SETB P2.4
RET
/*显示子程序*/
SHOW:
MOV A,R5
MOVC A,@A+DPTR
MOV P0,A
RET
/*循环显示子程序*/
SHOW1: ;
MOV R3,#00H
LOOP1:
MOV A,R3
MOVC A,@A+DPTR
MOV P0,A
MOV R0,#35H
LCALL DELAY
INC R3
LCALL KEY_READ
JB 00H,RETUN1
CJNE R3,#10H,LOOP1
MOV R3,#00H
SJMP LOOP1
RETUN1:
RET
/*延时子程序*/
DELAY:
D0: MOV R2,#0FH
D1: MOV R1,#0BFH
D2: DJNZ R1,D2
DJNZ R2,D1
DJNZ R0,D0
RET
/*定时中断T0处理子程序*/
INT_T0:
CLR EA
PUSH ACC
INC R4
MOV TH0,#15H
MOV TL0,#9FH
POP ACC
SETB EA
RETI
/*数码管显示代码,0~F*/
LED_DATA:
DB 03H,9FH,25H,0DH,99H,49H,41H,1FH
DB 01H,09H,11H,0C1H,63H,85H,61H,71H
END