人狗畜禽COMPANY LIMITED|全是肉的高H文〈男男〉|全篇肉高H秘书被C办公室四爱|全黄H全肉共妻|全黄H全肉短篇禁乱NP慕浅浅|全黄H全肉短篇N男男

技術(shù)熱線: 4007-888-234
設(shè)計(jì)開發(fā)

專注差異化嵌入式產(chǎn)品解決方案 給智能產(chǎn)品定制注入靈魂給予生命

開發(fā)工具

提供開發(fā)工具、應(yīng)用測試 完善的開發(fā)代碼案例庫分享

技術(shù)支持

從全面的產(chǎn)品導(dǎo)入到強(qiáng)大技術(shù)支援服務(wù) 全程貼心伴隨服務(wù),創(chuàng)造無限潛能!

新品推廣

提供新的芯片及解決方案,提升客戶產(chǎn)品競爭力

新聞中心

提供最新的單片機(jī)資訊,行業(yè)消息以及公司新聞動(dòng)態(tài)

PIC單片機(jī)實(shí)現(xiàn)CRC的小程序

更新時(shí)間: 2019-03-22
閱讀量:1887

單片機(jī)開發(fā)商深圳英銳恩分享PIC單片機(jī)實(shí)現(xiàn)CRC的小程序。PIC單片機(jī)實(shí)現(xiàn)Dallas的iButton通訊時(shí),編了段產(chǎn)生和校驗(yàn)CRC的子程序。
    #include 

;-------------------------------
    cblock    0x20
datBuff:8            ;assign 8 byte data buffer
bit_cnt                ;bit counting 
CRC_COUNT            ;number of bytes for CRC
CRC_RESULT            ;CRC resulr
crc_temp            ;temporary data buffer during CRC
    endc

;-------------------------------
#define    skp0    btfsc
#define    skp1    btfss


;===============================
    org    0x000

    movlw    .7
    movwf    CRC_COUNT
    movlw    datBuff
    movwf    FSR        ;FSR point to data buffer
    call    CRC_CHECK
    movwf    datBuff+7
    goto    $

;===============================
;CHECK THE CRC FOR ? BYTES DATA
;For the polynomial of X^8 + X^5 + X^4 + 1
;Derived from Dallas's iButton standard
;Before calling, FSR       = data buffer
;                CRC_COUNT = number of bytes for CRC
CRC_CHECK    ;~~~~~~~~~~~~~~~
    clrf    CRC_RESULT    ;initialize the CRC buffer
_crc_00
    movlw    .8        ;number of bits for one byte
    movwf    bit_cnt        ;set bit counter
    movf    INDF,w        ;get one data byte
    movwf    crc_temp    ;copy to temporary location

_crc_01
    rrf    crc_temp,f    ;get LSB in C
    skpc            ;is this LSB=1?
    goto    _crc_02        ;go if LSB=0
    movlw    0x01        ;do if LSB=1
    xorwf    CRC_RESULT,f
_crc_02
    rrf    CRC_RESULT,w    ;get LSB of CRC
    skpc            ;test LSB
    goto    _crc_03        ;go if LSB=0
    movlw    0x18        ;do if LSB=1
    xorwf    CRC_RESULT,f    ;polynomial implementation
_crc_03
    rrf    CRC_RESULT,w    ;whole byte right rotate
    rrf    CRC_RESULT,f
    decfsz    bit_cnt,f    ;bit counting
    goto    _crc_01        ;go on until aa 8 bits done
    incf    FSR,f        ;pointer update to next byte
    decfsz    CRC_COUNT,f    ;byte counting
    goto    _crc_00        ;go on until all byte done
    movf    CRC_RESULT,w    ;get CRC, Z set if CRC=0
    return            ;return with CRC in W

 END

邵东县| 象山县| 来凤县| 鲁山县| 赣州市| 翁牛特旗| 绥芬河市| 嘉义市| 沭阳县| 金湖县| 安图县| 门头沟区| 杨浦区| 济宁市| 阳泉市| 双城市| 定结县| 陇川县| 西平县| 江孜县| 房产| 喀什市| 葫芦岛市| 灵武市| 迁西县| 梨树县| 老河口市| 治多县| 营口市| 海阳市| 色达县| 德昌县| 拉孜县| 凤山市| 遂宁市| 车险| 康定县| 霍州市| 镇原县| 锡林郭勒盟| 安溪县|