📄 bcdtob16.txt
字号:
;MAX=65535
;************************************************************************
; BCD To Binary Conversion
;
; This routine converts a 5 digit BCD number to a 16 bit binary
; number.
; The input 5 digit BCD numbers are asumed to be in locations
; R0, R1 & R2 with R0 containing the MSD in its right most nibble.
;
; The 16 bit binary number is output in registers H_byte & L_byte
; ( high byte & low byte repectively ).
;
; The method used for conversion is :
; input number X = abcde ( the 5 digit BCD number )
; X = abcde = 10[10[10[10a+b]+c]+d]+e
;
; Performance :
; Program Memory : 30
; Clock Cycles : 121
;
;*******************************************************************;
;
CARRY EQU 00H
H_byte equ 20H
L_byte equ 21H
R0 equ 22H ; RAM Assignments
R1 equ 23H
R2 equ 24H
;
H_temp equ 25H ; temporary register
L_temp equ 26H ; temporary register
;
;
INCLUDE p16f877.inc
;
;
org 00H
goto main
mpy10b andlw 0FH
addwf L_byte
btfsc STATUS,CARRY
incf H_byte
mpy10a bcf STATUS,CARRY ; multiply by 2
rlf L_byte,w
movwf L_temp
rlf H_byte,w ; (H_temp,L_temp) = 2*N
movwf H_temp
;
bcf STATUS,CARRY ; multiply by 2
rlf L_byte
rlf H_byte
bcf STATUS,CARRY ; multiply by 2
rlf L_byte
rlf H_byte
bcf STATUS,CARRY ; multiply by 2
rlf L_byte
rlf H_byte ; (H_byte,L_byte) = 8*N
;
movf L_temp,w
addwf L_byte
btfsc STATUS,CARRY
incf H_byte
movf H_temp,w
addwf H_byte
retlw 0 ; (H_byte,L_byte) = 10*N
;
;
BCDtoB clrf H_byte
movf R0,w
andlw 0F
movwf L_byte
call mpy10a ; result = 10a+b
;
swapf R1,w
call mpy10b ; result = 10[10a+b]
;
movf R1,w
call mpy10b ; result = 10[10[10a+b]+c]
;
swapf R2,w
call mpy10b ; result = 10[10[10[10a+b]+c]+d]
;
movf R2,w
andlw 0F
addwf L_byte
btfsc STATUS,CARRY
incf H_byte ; result = 10[10[10[10a+b]+c]+d]+e
retlw 0 ; BCD to binary conversion done
;
;
;********************************************************************
; Test Program
;*********************************************************************
main movlw 06
movwf R0 ; Set R0 = 06
movlw 55
movwf R1 ; Set R1 = 55
movlw 35
movwf R2 ; Set R2 = 35 ( R0, R1, R2 = 6,55,35 )
;
call BCDtoB ; After conversion H_Byte = FF & L_Byte = FF
;
self goto self
;
;
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -