⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bcdtobinary.asm

📁 Alarm clock with PIC microcontroller
💻 ASM
字号:
;==============================================================================
; BCD To Binary Conversion
;------------------------------------------------------------------------------

;==============================================================================
; Revision History:
;
; 2005-01-12    Initial version
;------------------------------------------------------------------------------

                include ../pic.inc

                global  BcdToBinary

                if      HAS_12_BIT_CORE
                extern  RESULT
                endif

;==============================================================================

                udata_ovr
BCD             res     1
                if      HAS_12_BIT_CORE
BIN             res     1               ;12 bit version needs an extra register
                endif

;==============================================================================

                code

; BcdToBinary converts a BCD value in the range h'00' to h'99' held in W to its
; equivalent binary value. The same time is taken for all conversions.
;
; This routine is not re-enterable.

BcdToBinary:

; 12-Bit:
;
; The 12-bit core does not have an ADDLW instruction so the algorithm needs an
; extra file (BIN) in the same bank as BCD to operate. The final result is
; passed back to the caller in RESULT as there is no RETURN instruction either
; in this core.
;
; If the device supports banked files then the bank containing RESULT will be
; selected when the routine returns.
;
; Words: 17/19  Cycles: 17/19

                if      HAS_12_BIT_CORE
                banksel BCD
                movwf   BCD
                andlw   h'0f'
                movwf   BIN
                movlw   .80
                btfsc   BCD,7
                addwf   BIN,F
                movlw   .40
                btfsc   BCD,6
                addwf   BIN,F
                movlw   .20
                btfsc   BCD,5
                addwf   BIN,F
                movlw   .10
                btfsc   BCD,4
                addwf   BIN,W
                banksel RESULT
                movwf   RESULT
                retlw   0
                endif

; 14-Bit:
;
; The converted value is returned in W. If the device has file banks then on
; return the bank containing BCD is selected.
;
; Words: 11-13  Cycles: 11-13 (depending on banking)

                if      HAS_14_BIT_CORE
                banksel BCD
                movwf   BCD
                andlw   h'0f'
                btfsc   BCD,7
                addlw   .80
                btfsc   BCD,6
                addlw   .40
                btfsc   BCD,5
                addlw   .20
                btfsc   BCD,4
                addlw   .10
                return
                endif

; 16-Bit
                if      HAS_16_BIT_CORE
                endif

                end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -