天堂草原最受欢迎的角色,天堂动漫,天堂在线,色天堂下载,天堂中文在线资源,亚洲男人天堂

技術(shù)熱線: 4007-888-234

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

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

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

技術(shù)支持

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

更新時(shí)間: 2019-03-22

單片機(jī)開(kāi)發(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

404
返回首頁(yè) |  返回上一頁(yè)
联系我们: 凉城县| 岳普湖县| 辽宁省| 仁化县| 昌平区| 阿拉尔市| 曲水县| 株洲市| 喀喇沁旗| 卢湾区| 晋江市| 遂昌县| 常山县| 正镶白旗| 修水县| 治县。| 滦南县| 包头市| 博白县| 凤凰县| 丰县| 陇南市| 筠连县| 连州市| 响水县| 本溪| 微山县| 仙游县| 嘉定区| 泾川县| 乌什县| 平昌县| 永寿县| 清新县| 垦利县| 许昌市| 屏东市| 华坪县| 贺兰县| 溧阳市| 沂南县|