16进制转10进制函数。
A/D采样后的值是16进制(<0xFFFF),通过什么函数能转为10进制(或什么方法),以便于送到数码管显示。 ;16位二进制数换算位DCD码==========;============================================
;16位二进制数换算位DCD码==========
;********************************************************************
; Binary To BCD Conversion Routine
; This routine converts a 16 Bit binary Number to a 5 Digit
; BCD Number. This routine is useful since PIC16C55 & PIC16C57
; havetwo 8 bit ports and one 4 bit port ( total of 5 BCD digits)
;
; The 16 bit binary number is input in locations ACCBHI and
; ACCBLO with the high byte in ACCBHI.
; The 5 digit BCD number is returned in R0, R1 and R2 with R0
; containing the MSD in its right most nibble.
;
; Performance :
; Program Memory: 35
; Clock Cycles : 885
;
;********************************************************************
; Test Program
;*********************************************************************
;main movlw 0FF
; movwf ACCBHI
; movwf ACCBLO ; The 16 bit binary number = FFFF
; call B2_BCD ; After conversion the Decimal Number
; ; in R0,R1,R2 = 06,55,35
;*******************************************************************;
B2_BCDbcf STATUS,0 ; clear the carry bit
movlw .16
movwf count
clrf R0
clrf R1
clrf R2
loop16rlf ACCBLO,1
rlf ACCBHI,1
rlf R2,1
rlf R1,1
rlf R0,1
;
decfszcount,1
goto adjDEC
RETLW 0
;
adjDECmovlw R2
movwf FSR
call adjBCD
;
movlw R1
movwf FSR
call adjBCD
;
movlw R0
movwf FSR
call adjBCD
;
goto loop16
;
adjBCDmovlw 3
addwf 0,W
movwf TEMP
btfsc TEMP,3 ; test if result > 7
movwf 0
movlw 30
addwf 0,W
movwf TEMP
btfsc TEMP,7 ; test if result > 7
movwf 0 ; save as MSD
RETLW 0
; X为要显示的16进制数
万位=X/10000
千位=(X%10000)/1000
百位=(X%1000)/100
十位=(X%100)/10
个位=X%10
页:
[1]