在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
芯片精品文章合集(500篇!) 创芯人才网--重磅上线啦!
查看: 2247|回复: 0

PIC模拟异步串行通讯UART

[复制链接]
发表于 2005-10-29 11:00:34 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
pic乘除运算子程序
#define    STATUS    3
#define    skpb    skpnc    ;skip if borrowed
#define    skpnb    skpc    ;skip if no borrow
    cblock    0x10
PROD:2            ;2 bytes for production
QUOT:2            ;2 bytes for quotient
PAVRA            ;divider/multiplier
PAVRB            ;reminder / multiplier
PAVRC            ;additional byte space
mcount            ;loop counter
    endc
    org    000h
    ;movlw    0x20;
    ;movwf    PAVRA
    ;movlw    0x30
    ;movwf    PAVRB
    call    BBYTE_DIV
    goto    $-1
;====================================
ROD:2 = PAVRA * PAVRB
;====================================
BYTE_MUL
    clrf    PROD
    clrf    PROD+1
    movlw    .8
    movwf    mcount
_mul1
    rlf    PROD,f        ;left shift 16-bit with LSB=0
    bcf    PROD,0
    rlf    PROD+1,f   
    rlf    PAVRA,w        ;make left-rotate shift
    rlf    PAVRA,f        ;and check MSB
    skpc            ;skip if MSB=1
    goto    _mul2        ;MSB=0
    ;do when MSB=1
    movf    PAVRB,w
    addwf    PROD,f
    skpnc
    incf    PROD+1,f
_mul2   
    decfsz    mcount,f
    goto    _mul1   
    retlw    0

;====================================
;WORD divided by BYTE               =
ROD:2 / PAVRA                     =
;QUOT:2 = Quotient                  =
AVRB  = Reminder                  =
;====================================
WBYTE_DIV
    movf    PAVRA,f
    skpnz
    retlw    1        ;return if divider=0
    clrf    PAVRB
    clrf    PAVRC
    clrf    QUOT
    clrf    QUOT+1
    movlw    .16
    movwf    mcount
_wdiv1
    rlf    QUOT,f        ;adjust Quotient
    rlf    QUOT+1,f
    bcf    QUOT,0
    ;
    rlf    PROD+1,w
    rlf    PROD,f
    rlf    PROD+1,f
    ;
    rlf    PAVRB,f
    rlf    PAVRC,f
    ;
    movf    PAVRA,w
    subwf    PAVRB,f
    skpb            ;skip if borrow
    goto    _wdiv2
    ;if borrow
    btfsc    PAVRC,0
    goto    _wdiv2
    addwf    PAVRB,f
    bcf    PAVRC,0
    goto    _wdiv3
_wdiv2    ;if no borrow
    bcf    PAVRC,0
    bsf    QUOT,0   
_wdiv3
    decfsz    mcount,f
    goto    _wdiv1   
    retlw    0
;====================================
;BYTE divided by BYTE               =
;PROD[0] / PAVRA                    =
;QUOT[0] = Quotient                 =
;PAVRB   = Reminder                 =
;====================================
BBYTE_DIV
    movf    PAVRA,f
    skpnz
    retlw    1        ;return if divider=0
    clrf    PAVRB        ;clear reminder
    clrf    QUOT        ;clear quotient
    movlw    .8
    movwf    mcount        ;for 8 times shift
_bdiv1
    rlf    QUOT,f        ;adjust Quotient
    bcf    QUOT,0        ;left shift i bit
    ;
    rlf    PROD,w        ;get 1 bit, MSB first
    rlf    PROD,f        ;do rotate shift
    ;
    rlf    PAVRB,f        ;set to LSB of reminder
    ;
    movf    PAVRA,w        ;reminder - divider
    subwf    PAVRB,f
    skpb            ;skip if borrow
    goto    _bdiv2
    ;do if borrowed
    addwf    PAVRB,f        ;cancel subtraction
    goto    _bdiv3        ;go for next
_bdiv2    ;do if no borrow
    bsf    QUOT,0        ;reminder > divider
                ;update quotient
_bdiv3
    decfsz    mcount,f    ;loop test
    goto    _bdiv1        ;do 8 times
    retlw    0        ;completed
    END

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条

小黑屋| 手机版| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-9-28 12:19 , Processed in 0.015785 second(s), 9 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表