https://static.assets-stash.eet-china.com/album/old-resources/2009/5/14/60b08cd0-661e-4ac3-b855-6523e6bf374d.rarVALUEH EQU 20H
VALUEL EQU 21H
DVALUE0 EQU 22H
DVALUE1 EQU 23H
DVALUE2 EQU 24H
DVALUE3 EQU 25H
DVALUE4 EQU 26H
CNT EQU 30H
KEY EQU P3.7
ORG 00H
SJMP START
ORG 0BH
LJMP INT_T0
START: MOV DPTR,#TABLE
MOV 20H,#00H
MOV 21H,#00H
MOV 22H,#00H
MOV 23H,#00H
MOV 24H,#00H
MOV 25H,#00H
MOV 26H,#00H
MOV 30H,#00H
MOV TMOD,#51H
MOV TH0,#3CH
MOV TL0,#0B0H
MOV TH1,#00H
MOV TL1,#00H
MOV IE,#8AH
WAIT: JB KEY,$
LCALL DELAY
JB KEY,$
SETB TR0
SETB TR1
W1: LCALL DISP
JNB KEY,W1
LJMP START
INT_T0:
MOV TH0,#3CH
MOV TL0,#0B0H
INC CNT
MOV A,CNT
CJNE A,#20,RETUNE
MOV CNT,#00H
CLR TR0
CLR TR1
MOV VALUEL,TL1
MOV VALUEH,TH1
LCALL HTOD
RETUNE: RETI
HTOD:
MOV R2,VALUEH
MOV R3,VALUEL
CLR A
MOV R4,A ;清零
MOV R5,A
MOV R6,A
MOV R7,#10H ;转换双字节十六进制整数
H_B:
CLR C
MOV A,R3 ;从高端移出待转换数的一位到CY中
RLC A
MOV R3,A
MOV A,R2 ;BCD码带进位自身相加,相当于乘2
RLC A
MOV R2,A
MOV A,R6
ADDC A,R6
DA A ;十进制调整
MOV R6,A
MOV A,R5
ADDC A,R5
DA A
MOV R5,A
MOV A,R4
ADDC A,R4
DA A
MOV R4,A ;双字节十六进制数的万位数不超过6,不用调整
DJNZ R7,H_B ;处理完16bit
;-----------------------------------------------------------
;码型变换,将待转换的数据分成不同的数位,并转换成单位BCD码
;-----------------------------------------------------------
CZ: MOV R0,#DVALUE4 ;获得首地址
MOV A,R6 ;获得待转化的低位
ANL A,#0FH
MOV @R0,A
DEC R0
MOV A,R6
SWAP A
ANL A,#0FH
MOV @R0,A
DEC R0
MOV A,R5
ANL A,#0FH
MOV @R0,A
DEC R0
MOV A,R5
SWAP A
ANL A,#0FH
MOV @R0,A
DEC R0
MOV A,R4
ANL A,#0FH
MOV @R0,A
RET
DISP: MOV P2,00H
SETB P2.0
MOV A,DVALUE0
MOVC A,@A+DPTR
MOV P0,A
LCALL DELAY
CLR P2.0
SETB P2.1
MOV A,DVALUE1
MOVC A,@A+DPTR
MOV P0,A
LCALL DELAY
CLR P2.1
SETB P2.2
MOV A,DVALUE2
MOVC A,@A+DPTR
MOV P0,A
LCALL DELAY
CLR P2.2
SETB P2.3
MOV A,DVALUE3
MOVC A,@A+DPTR
MOV P0,A
LCALL DELAY
CLR P2.3
SETB P2.4
MOV A,DVALUE4
MOVC A,@A+DPTR
MOV P0,A
LCALL DELAY
CLR P2.4
RET
DELAY: MOV R6,#10
D1: MOV R7,#248
DJNZ R7,$
DJNZ R6,D1
RET
TABLE: DB 0C0H,0F9H,0A4H,0B0H,99H
DB 92H,82H,0F8H,80H,90H
END
文章评论(0条评论)
登录后参与讨论