"); //-->
主程序(MAIN),如下:
ORG 0000H
AJMP MAIN
ORG 000BH
AJMP TIME
ORG 0300H
MAIN: MOV 20H,#00H ;计时的0.1秒、秒、时和分单元清0
MOV 21H,#00H
MOV 22H,#00H
MOV 23H,#00H
MOV IP,#02H ;IP,IE初始化
MOV IE,#82H
MOV TMOD,#01H ;定时器的初始化
MOV TL0,#0B0H
MOV TH0,#3CH
SETB TR0 ;启动定时器工作
MOV SP,#40H ;堆栈指针设为40H
NEXT: LCALL DISP ;调用显示子程序
LCALL KEY ;调按键判断子程序
JZ NEXT ;无键按下转NEXT
LCALL ANKEY ;有键按下转按键处理子程序
SJMP NEXT ;按键处理完转NEXT
NOP
NOP
NOP
定时中断处理程序:
TIME: PUSH ACC ;现场保护
PUSH PSW
MOV TL0,#0B4H ;重置初值
MOV TH0,#3CH
INC 20H ;计时处理
MOV A,20H
CJNE A,#0AH,RETI1
MOV 20H,#00H
MOV A,21H
ADD A,#01H
DA A
MOV 21H,A
CJNE A,#60H,RETI1
MOV 21H,#00H
MOV A,22H
ADD A,#01H
DA A
MOV 22H,#00H
MOV A,23H
ADD A,#01H
DA A
MOV 23H,A
CJNE A,#24H,RETI1
MOV 23H,#00H
RETI1: POP PSW ;恢复现场
POP ACC
RETI ;中断返回
NOP
NOP
显示子程序
DISP: ANL 2FH,#10H ;拆字,注意小数点的显示
MOV A,21H
ANL A,#0FH
ORL A,2FH
MOV 2FH,A
MOV A,21H
ANL A,#0F0H
SWAP A
MOV 2EH,A
ANL 2DH,#10H
MOV A,22H
ANL A,#0FH
ORL A,2DH
MOV 2DH,A
MOV A,22H
ANL A,#0F0H
SWAP A
MOV 2CH,A
ANL 2BH,#10H
MOV A,23H
ANL A,#0FH
ORL A,2BH
MOV 2BH,A
MOV A,23H
ANL A,#0F0H
SWAP A
MOV 2AH,A
MOV R0,#2FH
MOV R3,#06H
MOV DPTR,#TABLE
MOV A,#01H
LOOP1: MOV B,A ;送位控制字与段控制字
MOV P2,A
MOV A,@R0
MOVC A,@A+DPTR
MOV P0,A
MOV R2,#80H ;延时
DJNZ R2,$
DEC R0
MOV A,B
RL A
DJNZ R3,LOOP1
RET
TABLE: DB 0C0H,0F9H,0A4H,0B0H,99H,92H ;小数点不亮的代码
DB 82H,0F8H,80H,90H,00,00,00,00,00,00
DB 40H,79H,24H,30H,19H,12H,02H,78H ;小数点亮的显示代码
DB 00H,10H,00,00,00,00,00,00
NOP
NOP
按键判断程序
KEY: MOV P3,#0FFH ;读按键状态
MOV A,P3
CPL A
ANL A,#0FH
JZ RETX ;无键按下返回,有键按下延时去抖动
LCALL DISP
LCALL DISP
MOV A,P3
CPL A
ANL A,#0FH
JZ RETX ;是抖动则返回主程序,否则读按键状态存入R6及A中
MOV R6,A
LOOP2: LCALL DISP ;等待按键的释放
MOV A,P3
CPL A
ANL A,#0FH
JNZ LOOP2
MOV A,R6
RETX: RET
NOP
NOP
按键处理子程序
ANKEY: CLR EA ;关中断
LX: MOV A,R6
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。