• <li id="00i08"><input id="00i08"></input></li>
  • <sup id="00i08"><tbody id="00i08"></tbody></sup>
    <abbr id="00i08"></abbr>
  • 新聞中心

    EEPW首頁 > 嵌入式系統 > 設計應用 > PIC單片機實現CRC的小程序

    PIC單片機實現CRC的小程序

    作者: 時間:2011-03-08 來源:網絡 收藏
    PIC實現CRC的小程序

    PIC實現Dallas的iButton通訊時,編了段產生和校驗CRC的子程序。
    ;PIC www.pic16.com
    #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'siButtonstandard
    ;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


    評論


    相關推薦

    技術專區

    關閉
    主站蜘蛛池模板: 柞水县| 阜城县| 寻甸| 三河市| 宣汉县| 泊头市| 花垣县| 花莲市| 西乌珠穆沁旗| 安仁县| 景德镇市| 五大连池市| 那曲县| 哈密市| 虹口区| 日土县| 罗源县| 萨迦县| 吉林市| 丰宁| 昌江| 扎兰屯市| 浠水县| 英山县| 正安县| 平凉市| 三台县| 盐源县| 清新县| 沭阳县| 凤城市| 榆社县| 宜兰县| 京山县| 汕头市| 岳阳市| 玛曲县| 高淳县| 襄汾县| 昭平县| 彭山县|