新聞中心

        EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > PIC單片機(jī)實(shí)現(xiàn)CRC算法的小程序

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

        作者: 時(shí)間:2014-01-09 來(lái)源:網(wǎng)絡(luò) 收藏
        實(shí)現(xiàn)CRC的小程序

        實(shí)現(xiàn)Dallas的通訊時(shí),編了段產(chǎn)生和校驗(yàn)CRC的子程序。

        #includeP16CE625.INC>

        ;-------------------------------
        cblock0x20
        datBuff:8;assign8bytedatabuffer
        bit_cnt;bitcounting
        CRC_COUNT;numberofbytesforCRC
        CRC_RESULT;CRCresulr
        crc_temp;temporarydatabufferduringCRC
        endc

        ;-------------------------------
        #defineskp0btfsc
        #defineskp1btfss


        ;===============================
        org0x000

        movlw.7
        movwfCRC_COUNT
        movlwdatBuff
        movwfFSR;FSRpointtodatabuffer
        callCRC_CHECK
        movwfdatBuff+7
        goto$

        ;===============================
        ;CHECKTHECRCFOR?BYTESDATA
        ;ForthepolynomialofX^8+X^5+X^4+1
        ;DerivedfromDallas'sstandard
        ;Beforecalling,FSR=databuffer
        ;CRC_COUNT=numberofbytesforCRC
        CRC_CHECK;~~~~~~~~~~~~~~~
        clrfCRC_RESULT;initializetheCRCbuffer
        _crc_00
        movlw.8;numberofbitsforonebyte
        movwfbit_cnt;setbitcounter
        movfINDF,w;getonedatabyte
        movwfcrc_temp;copytotemporarylocation
        _crc_01
        rrfcrc_temp,f;getLSBinC
        skpc;isthisLSB=1?
        goto_crc_02;goifLSB=0
        movlw0x01;doifLSB=1
        xorwfCRC_RESULT,f
        _crc_02
        rrfCRC_RESULT,w;getLSBofCRC
        skpc;testLSB
        goto_crc_03;goifLSB=0
        movlw0x18;doifLSB=1
        xorwfCRC_RESULT,f;polynomialimplementation
        _crc_03
        rrfCRC_RESULT,w;wholebyterightrotate
        rrfCRC_RESULT,f
        decfszbit_cnt,f;bitcounting
        goto_crc_01;goonuntilaa8bitsdone
        incfFSR,f;pointerupdatetonextbyte
        decfszCRC_COUNT,f;bytecounting
        goto_crc_00;goonuntilallbytedone
        movfCRC_RESULT,w;getCRC,ZsetifCRC=0
        return;returnwithCRCinW

        END


        關(guān)鍵詞: PIC單片機(jī) CRC算法 iButton

        評(píng)論


        相關(guān)推薦

        技術(shù)專區(qū)

        關(guān)閉
        主站蜘蛛池模板: 涟源市| 武义县| 政和县| 苗栗市| 永福县| 灵寿县| 信宜市| 玉门市| 辽阳市| 长岭县| 昌宁县| 廊坊市| 双辽市| 苍南县| 秭归县| 沂源县| 池州市| 扎兰屯市| 宜兰市| 西吉县| 华宁县| 台南县| 香格里拉县| 崇文区| 泌阳县| 塔河县| 景洪市| 新民市| 富民县| 桦南县| 康马县| 香港 | 广宁县| 永宁县| 博兴县| 乌苏市| 靖西县| 永仁县| 合水县| 务川| 靖边县|