8++¦
来自「PIC子程序集,包括加减乘除等运算,运用该子程序包,可以方便的编出程序」· 代码 · 共 55 行
TXT
55 行
; 8位BIN数转化为2位BCD数
;********************************************************************
; Binary To BCD Conversion Routine
;
; This routine converts the 8 bit binary number in the W Register
; to a 2 digit BCD number.
; The least significant digit is returned in location LSD and
; the most significant digit is returned in location MSD.
;
; Performance :
; Program Memory : 10
; Clock Cycles : 81 (worst case when W = 63 Hex )
; ( i.e max Decimal number 99 )
;*******************************************************************
;
LSD equ 10
MSD equ 11
;
;其它的寄存器自己定义
;
BinBCD
clrf MSD
movwf LSD
gtenth
movlw D'10'
subwf LSD,W
BTFSS STATUS,C
goto over
movwf LSD
incf MSD
goto gtenth
over
retlw 0
;**********************************
;测试程序(注意用法,BIN数放在W里,结果放在MSD,LSD里)
;----------------------------------
main
movlw 63 ; W reg = 63 Hex
call BinBCD ; after conversion, MSD = 9 & LSD = 9
; ( 63 Hex = 99 Decimal )
self goto self ; 如不是测试程序,本句无用
;
org 1FF
goto main
;
END
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?