自己编的,看看就行
<code class="lang-">
ORG 00H
AJMP MAIN
ORG 0BH
AJMP T0INT
ORG 30H
MAIN:LCALL INIT ;初始化
START:LCALL DISP ;开始
JB P1.4,PAUSE
SETB TR0
AJMP START
PAUSE: LCALL DISP //暂停
JB P1.5,CLEAR
CLR TR0
AJMP PAUSE
CLEAR: LCALL DISP //清零
JB P1.6,START
CLR TR0
MOV R4,#0
MOV R0,#0
AJMP CLEAR
DISP: //显示
MOV A,R4
MOV B,#10
DIV AB
MOV DPTR,#TAB //不带小数点显示
MOVC A,@A+DPTR
MOV P0,A
CLR P1.0
CLR P1.2
CLR P1.3
ACALL D1MS
SETB P1.0
SETB P1.2
SETB P1.3
MOV A,B
MOVC A,@A+DPTR
MOV P0,A
CLR P1.1
CLR P1.2
CLR P1.3
ACALL D1MS
SETB P1.1
SETB P1.2
SETB P1.3
ACALL D1MS
MOV A,R0
MOV B,#10
DIV AB
MOV DPTR,#TAB
MOVC A,@A+DPTR
MOV P0,A
CLR P1.2
CLR P1.0
CLR P1.1
ACALL D1MS
SETB P1.2
SETB P1.0
SETB P1.1
MOV A,B
MOV DPTR,#TABEL ;带小数点显示
MOVC A,@A+DPTR
MOV P0,A
CLR P1.3
CLR P1.0
CLR P1.1
ACALL D1MS
SETB P1.3
SETB P1.0
SETB P1.1
RET
INIT:MOV SP,#60H
MOV R4,#0
MOV DPTR,#TAB
MOV TMOD,#01H
MOV TH0,#0D8H ; 10MS
MOV TL0,#0F0H
SETB ET0
SETB EA
RET
T0INT:
MOV TH0,#0D8H
MOV TL0,#0F0H
INC R4
CJNE R4,#100,RTI ;10MS X 100 = 1S
MOV R4,#0
INC R0
CJNE R0,#100,RTI
MOV R0,#0
RTI:
RETI
D1MS:
MOV R7,#01H
DL1:
MOV R6,#8EH
DL0:
MOV R5,#02H
DJNZ R5,$
DJNZ R6,DL0
DJNZ R7,DL1
RET
TAB:
DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH 不带小数点显示
TABEL:
DB 0BFH,86H,0DBH,0CFH,0E6H,0EDH,0FDH,0F7H,0FFH,0EFH 带小数点显示
END
</code>