程序的具体内容如下:
$MOD52
ORG 0000H
LJMP MAIN
ORG 0003H
LJMP 0100H
ORG 0013H
LJMP 0150H
ORG 0050H
MAIN: CLR A
MOV 30H , A ;初始化缓存区
MOV 31H , A
MOV 32H , A
MOV 33H , A
MOV R6 , A
MOV R7 , A
SETB EA
SETB EX0
SETB EX1
SETB IT0
SETB IT1
SETB PX1
NEXT1: ACALL HEXTOBCDD ;调用数制转换子程序
ACALL DISPLAY ;调用显示子程序
LJMP NEXT1
ORG 0100H ;中断0服务程序
LCALL DELY
mov 70h,#2
djnz 70h,next
JBC F0,NEXT
SETB F0
CLR P0.0
LCALL DELY0
SETB P0.0
MOV A , R7
ADD A , #1
MOV R7, A
MOV A , R6
ADDC A , #0
MOV R6 , A
CJNE R6 , #07H , NEXT
CLR A
MOV R6 , A
MOV R7 , A
NEXT: RETI
ORG 0150H ;中断1服务程序
LCALL DELY
mov 70h,#2
djnz 70h,next2
JBC F0,NEXT2
SETB F0
CLR P0.0
LCALL DELY0
SETB P0.0
CLR C
MOV A , R7
SUBB A , #1
MOV R7, A
MOV A , R6
SUBB A , #0
MOV R6 , A
CJNE R6 , #07H , NEXT2
CLR A
MOV R6 , A
MOV R7 , A
NEXT2: RETI
ORG 0200H
HEXTOBCDD:MOV A , R6 ;由十六进制转化为十进制
PUSH ACC
MOV A , R7
PUSH ACC
MOV A , R2
PUSH ACC
CLR A
MOV R3 , A
MOV R4 , A
MOV R5 , A
MOV R2 , #10H
HB3: MOV A , R7 ;将十六进制中最高位移入进位位中
RLC A
MOV R7 , A
MOV A , R6
RLC A
MOV R6 , A
MOV A , R5 ;每位数加上本身相当于将这个数乘以2
ADDC A , R5
DA A
MOV R5 , A
MOV A , R4
ADDC A , R4
DA A ;十进制调整
MOV R4 , A
MOV A , R3
ADDC A , R3
DJNZ R2 , HB3
POP ACC
MOV R2 , A
POP ACC
MOV R7 , A
POP ACC
MOV R6 , A
RET
ORG 0250H
DISPLAY:
MOV R0 , #30H
MOV A , R5
ANL A , #0FH
MOV @R0 , A
MOV A , R5
SWAP A
ANL A , #0FH
INC R0
MOV @R0 , A
MOV A , R4
ANL A , #0FH
INC R0
MOV @R0 , A
MOV A , R4
SWAP A
ANL A , #0FH
INC R0
MOV @R0 , A
MOV R0 , #30H
MOV R2 , #11111110B
AGAIN: MOV A , R2
MOV P2 , A
MOV A , @R0
MOV DPTR , #TAB
MOVC A , @A+DPTR
MOV P1 , A
ACALL DELAY
INC R0
MOV A , R2
RL A
MOV R2 , A
JB ACC.4 , AGAIN
RET
TAB: DB 03FH , 06H , 5BH , 4FH , 66H , 6DH , 7DH , 07H , 7FH , 6FH ;七段码表
DELY: MOV R1,#80
D1: MOV R2,#100
DJNZ R2,$
DJNZ R1,D1
RET
DELAY: MOV TMOD , #01H ;延时子程序
MOV TL0 , #0FEH
MOV TH0 , #0FEH
SETB TR0
WAIT: JNB TF0 , WAIT
CLR TF0
CLR TR0
RET
DELY0: MOV R1, #200
D3: MOV R2,#250
DJNZ R2,$
DJNZ R1,D3
RET
END
评论
查看更多