第1个回答 2011-03-05
选 。共阳数码管 16M晶振。
STRT EQU P2.5
STP EQU P2.6
CLRR EQU P2.7
ORG 00H
AJMP MAIN
ORG 0BH
AJMP T0INT
ORG 30H
MAIN: MOV R0,#20
MOV TMOD,#01H
MOV TH0,#3CH
MOV TL0,#0B0H
MOV DPTR,#TABLE
SETB EA
SETB ET0
k1: LCALL DISP
JB STRT,K2
LCALL DISP
JNB STRT,$-3
AJMP START
k2: JB STP,K3
LCALL DISP
JNB STP,STOP
K3: JB CLRR,K1
LCALL DISP
JNB CLRR,CLEAR
AJMP K3
START: SETB TR0
AJMP K1
STOP: CLR TR0
AJMP K2
CLEAR: CLR TR0
MOV 40H,#0
AJMP K1
T0INT: MOV TH0,#3CH
MOV TL0,#0B0H
DJNZ R0,RTI
MOV R0,#20
MOV A,40H
CJNE A,#99,ADD1
MOV 40H,#00H
CLR TR0
AJMP RTI
ADD1: ADD A,#01H
MOV 40H,A
RTI: RETI
DISP: MOV A,40H
MOV B,#10
DIV AB ;//当前值除以10
MOV 20H,A ;//得出的商送给十位
MOV 21H,B ;//得出的余数送给个位
CLR P2.0
SETB P2.1
MOV A,20H ;//十位显示
MOVC A,@A+DPTR
MOV P0,A
LCALL DELAY
CLR P2.1
SETB P2.0
MOV A,21H ; //个位显示
MOVC A,@A+DPTR
MOV P0,A
RET
DELAY: ;误差 0us
MOV R6,#01H
DL0:
MOV R5,#61H
DJNZ R5,$
DJNZ R6,DL0
RET
TABLE: DB 0C0H,0F9H,0A4H,0B0H,99H ;//共阳极0-9显示代码
DB 92H,82H,0F8H,80H,90H
END