;-------16位BIN转换为5位BCD码宏定义-----------------------
;入口
; BINH BCD码原码高4位
; BINL BCD码原码低8位
;出口
; BCDX BCD码高高4位
; BCDH BCD码高8位
; BCDL BCD码低8位
;------------------------------------------------------
Macro_WordBinToBcd MACRO BINL,BINH,BCDL,BCDH,BCDX,TEMP,COUNT
LOCAL BIN2BCDFWLOOP,BIN2BCDFWNEXT,BIN2BCDFWEXIT
MOVLW 0x10;16
MOVWF COUNT
CLRF BCDX
CLRF BCDH
CLRF BCDL
BCF STATUS,C
BIN2BCDFWLOOP
RLF BINL,F
RLF BINH,F
RLF BCDL,F
RLF BCDH,F
RLF BCDX,F
DECFSZ COUNT,F
GOTO BIN2BCDFWNEXT;BCD调整
GOTO BIN2BCDFWEXIT;结束
BIN2BCDFWNEXT
;---------------------------------
MOVLW 0X03
ADDWF BCDL,W
MOVWF TEMP
BTFSC TEMP,BIT3
MOVWF BCDL
MOVLW 0X30
ADDWF BCDL,W
MOVWF TEMP
BTFSC TEMP,BIT7
MOVWF BCDL
;---------------------------------
MOVLW 0X03
ADDWF BCDH,W
MOVWF TEMP
BTFSC TEMP,BIT3
MOVWF BCDH
MOVLW 0X30
ADDWF BCDH,W
MOVWF TEMP
BTFSC TEMP,BIT7
MOVWF BCDH
;---------------------------------
MOVLW 0X03
ADDWF BCDX,W
MOVWF TEMP
BTFSC TEMP,BIT3
MOVWF BCDX
;------------------------
MOVLW 0X30
ADDWF BCDX,W
MOVWF TEMP
BTFSC TEMP,BIT7
MOVWF BCDX
GOTO BIN2BCDFWLOOP
BIN2BCDFWEXIT
ENDM
;-------5位BCD转换为16位BIN码宏定义-----------------------
;入口
; TEMPH 暂存器高8位
; TEMPL 暂存器低8位
; BCDX BCD码原码高高4位
; BCDH BCD码原码高8位
; BCDL BCD码原码低8位
;出口
; BINH BCD码高4位
; BINL BCD码低8位
Macro_BcdToBinWord MACRO BCDL,BCDH,BCDX,BINL,BINH,TEMPL,TEMPH
LOCAL BCD2BINFWEXIT,BCD2BINFWSUB1,BCD2BINFWSUB2
CLRF BINH
MOVFW BCDX
ANDLW 0X0F
MOVWF BINL
CALL BCD2BINFWSUB2
SWAPF BCDH,W
CALL BCD2BINFWSUB1
MOVFW BCDH
CALL BCD2BINFWSUB1
SWAPF BCDL,W
CALL BCD2BINFWSUB1
MOVFW BCDL
ANDLW 0X0F
ADDWF BINL,F
BTFSC STATUS,C
INCF BINH,F
GOTO BCD2BINFWEXIT
BCD2BINFWSUB1
ANDLW 0X0F
ADDWF BINL,F
BTFSC STATUS,C
INCF BINH,F
BCD2BINFWSUB2
BCF STATUS,C
RLF BINL,W
MOVWF TEMPL
RLF BINH,W
MOVWF TEMPH
BCF STATUS,C
RLF BINL,F
RLF BINH,F
BCF STATUS,C
RLF BINL,F
RLF BINH,F
BCF STATUS,C
RLF BINL,F
RLF BINH,F
MOVFW TEMPL
ADDWF BINL,F
BTFSC STATUS,C
INCF BINH,F
MOVFW TEMPH
ADDWF BINH,F
RETLW 0
BCD2BINFWEXIT
ENDM
文章评论(0条评论)
登录后参与讨论