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

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

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

開發(fā)工具

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

技術(shù)支持

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

新品推廣

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

新聞中心

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

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

更新時間: 2019-03-22
閱讀量:1782

單片機開發(fā)商深圳英銳恩分享PIC單片機實現(xiàn)CRC的小程序。PIC單片機實現(xiàn)Dallas的iButton通訊時,編了段產(chǎ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

乐安县| 湖南省| 黄龙县| 丁青县| 福海县| 临猗县| 芦溪县| 黄冈市| 惠州市| 平江县| 扶沟县| 上思县| 中西区| 蓬安县| 德庆县| 济宁市| 新建县| 大宁县| 日喀则市| 邢台市| 祥云县| 宜阳县| 肃北| 东兰县| 彰武县| 日土县| 左权县| 镶黄旗| 双柏县| 隆化县| 西昌市| 沁源县| 社旗县| 吉木萨尔县| 常州市| 金川县| 米易县| 保亭| 满洲里市| 长丰县| 舟山市|