介绍,用了4位共阴数码管,通过单片机串口到74HC164转换后输出给数码管,上电从0000开始计数,60秒以前都是正常的,60秒后来就
W1 EQU P3.7;四位数码管引脚定议
W2 EQU P3.3
W3 EQU P3.4
W4 EQU P3.2
LO EQU 0B0H;定时50mms
HI EQU 3CH
;-----------------------------------
;中断计时处理程序
T0_INT:
MOV TH0,#HI ;加载高字节
MOV TL0,#LO ;加载低字节
INC DEDA
RETI
;----------------------------------
LOOP:
CALL CONV ;BCD码转换程序,保证数码管显示及时更新数据
CALL SCAN ;扫描显示器
CALL TIMER_COUNTER1;计时数据处理
;-----------------------------------------
JMP LOOP
TIMER_COUNTER1:
MOV A,DEDA
CJNE A,#CU,TT2 ;到0。5S吗?到了LED取反
MOV DEDA,#0
INC SEC
MOV A,SEC
CJNE A,#60,TT2 ;是否到了60秒
MOV SEC,#0
INC MIN
MOV A,MIN
CJNE A,#60,TT2
MOV DEDA,#0
MOV SEC,#0
MOV MIN,#0
TT2:
RET
;---------------------------------
;转换 MM:SS
CONV: ;BCD码转换程序
MOV A,MIN
MOV B,#10
DIV AB
MOV DPTR,#TABLE ;查表转换
MOVC A,@A+DPTR
MOV BUF,A
MOV A,B
MOV DPTR,#TABLE1
MOVC A,@A+DPTR
MOV BUF+1,A
MOV A,SEC
MOV B,#10
DIV AB
MOV DPTR,#TABLE
MOVC A,@A+DPTR
MOV BUF+2,A
MOV A,B
MOV DPTR,#TABLE
MOVC A,@A+DPTR
MOV BUF+3,A
RET
;--------------------------------
;扫描显示器 ;460us
SCAN:
PUSH ACC ;保护现场; 2us
SETB W4 ;1us
MOV R0,#BUF;间接寻址到BUF; 1us
MOV SBUF,@R0 ;送出一位显示1us
ACALL WAIT ;2us+5us
ACALL DELAY1;2us+100us
CLR W4
SETB W3
INC R0 ;1us
MOV SBUF,@R0 ;1us
CALL WAIT ;2us+5us
ACALL DELAY1;2us+100us
CLR W3
SETB W2;显示秒钟十位1us
INC R0 ;1us
MOV SBUF,@R0 ;1us
CALL WAIT ;2us+5us
CALL DELAY1 ;2us+100us
CLR W2;显示秒钟个位1us
SETB W1 ;1us
INC R0 ;1us
MOV SBUF,@R0 ;1us
CALL WAIT ;2+5us
CALL DELAY1;2+100us
CLR W1
CLR W2
CLR W3
CLR W4
POP ACC ;2us
MOV R0,#00H ;1us
RET ;2us
;-------------------------
WAIT:
JNB TI,WAIT;2us串口一位数据是否发送完闭,没完继续等待发完
CLR TI ;1us
RETI ;2us
;-----------------------------------------
;------------------------------------------------
;7-SEGMENT COMMON CATHODE;7段显示器字符数据
TABLE:
DB 0FCH,060H,0DAH,0F2H,066H ;0,1,2,3,4
DB 0B6H,0BEH,0E0H,0FEH,0F6H ;5,6,7,8,9
;-------------------------------------------------
TABLE1:
DB 0FDH,061H,0DBH,0F3H,067H
DB 0B7H,0BFH,0E1H,0FFH,0F7H
;--------------------------------------------------
|