在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 51單片機的MODBUS C語言程序(從機)

            51單片機的MODBUS C語言程序(從機)

            作者: 時間:2016-11-28 來源:網(wǎng)絡(luò) 收藏

            //檢查uart0數(shù)據(jù)
            void checkComm0Modbus(void)
            {
            uint16 crcData;
            uint16 tempData;
            if(receCount > 4)
            {
            switch(receBuf[1])
            {
            case 1://讀取線圈狀態(tài)(讀取點 16位以內(nèi))
            case 3://讀取保持寄存器(一個或多個)
            case 5://強制單個線圈
            case 6://設(shè)置單個寄存器
            if(receCount >= 8)
            {//接收完成一組數(shù)據(jù)
            //應(yīng)該關(guān)閉接收中斷
            if(receBuf[0]==localAddr && checkoutError==0)
            {
            crcData = crc16(receBuf,6);
            if(crcData == receBuf[7]+(receBuf[6]<<8))
            {//校驗正確
            if(receBuf[1] == 1)
            {//讀取線圈狀態(tài)(讀取點 16位以內(nèi))
            readCoil();
            }
            else if(receBuf[1] == 3)
            {//讀取保持寄存器(一個或多個)
            readRegisters();
            }
            else if(receBuf[1] == 5)
            {//強制單個線圈
            forceSingleCoil();
            }
            else if(receBuf[1] == 6)
            {
            //presetSingleRegister();
            }
            }
            }
            receCount = 0;
            checkoutError = 0;
            }
            break;
            case 15://設(shè)置多個線圈
            tempData = receBuf[6];
            tempData += 9; //數(shù)據(jù)個數(shù)
            if(receCount >= tempData)
            {
            if(receBuf[0]==localAddr && checkoutError==0)
            {
            crcData = crc16(receBuf,tempData-2);
            if(crcData == (receBuf[tempData-2]<<8)+ receBuf[tempData-1])
            {
            //forceMultipleCoils();
            }
            }
            receCount = 0;
            checkoutError = 0;
            }
            break;
            case 16://設(shè)置多個寄存器
            tempData = (receBuf[4]<<8) + receBuf[5];
            tempData = tempData // 2; //數(shù)據(jù)個數(shù)
            tempData += 9;
            if(receCount >= tempData)
            {
            if(receBuf[0]==localAddr && checkoutError==0)
            {
            crcData = crc16(receBuf,tempData-2);
            if(crcData == (receBuf[tempData-2]<<8)+ receBuf[tempData-1])
            {
            presetMultipleRegisters();
            }
            }
            receCount = 0;
            checkoutError = 0;
            }
            break;
            default:
            break;
            }
            }
            }//void checkComm0(void)
            //取線圈狀態(tài) 返回0表示成功
            uint16 getCoilVal(uint16 addr,uint16 //tempData)
            {
            uint16 result = 0;
            uint16 tempAddr;
            tempAddr = addr & 0xfff;
            //只取低8位地址
            switch(tempAddr & 0xff)
            {
            case 0:
            break;
            case 1:
            //tempData = testCoil;
            break;
            case 2:
            break;
            case 3:
            break;
            case 4:
            break;
            case 5:
            break;
            case 6:
            break;
            case 7:
            break;
            case 8:
            break;
            case 9:
            break;
            case 10:
            break;
            case 11:
            break;
            case 12:
            break;
            case 13:
            break;
            case 14:
            break;
            case 15:
            break;
            case 16:
            break;
            default:
            break;
            }
            return result;
            }//uint16 getCoilVal(uint16 addr,uint16 //data)
            //設(shè)定線圈狀態(tài) 返回0表示成功
            uint16 setCoilVal(uint16 addr,uint16 tempData)
            {
            uint16 result = 0;
            uint16 tempAddr;
            tempAddr = addr & 0xfff;
            switch(tempAddr & 0xff)
            {
            case 0:
            break;
            case 1:
            testCoil = tempData;
            break;
            case 2:
            break;
            case 3:
            break;
            case 4:
            break;
            case 5:
            break;
            case 6:
            break;
            case 7:
            break;
            case 8:
            break;
            case 9:
            break;
            case 10:
            break;
            case 11:
            break;
            case 12:
            break;
            case 13:
            break;
            case 14:
            break;
            case 15:
            break;
            case 16:
            break;
            default:
            break;
            }
            return result;
            }//uint16 setCoilVal(uint16 addr,uint16 data)
            //取寄存器值 返回0表示成功
            uint16 getRegisterVal(uint16 addr,uint16 //tempData)
            {
            uint16 result = 0;
            uint16 tempAddr;
            tempAddr = addr & 0xfff;
            switch(tempAddr & 0xff)
            {
            case 0:
            break;
            case 1:
            break;
            case 2:
            break;
            case 3:
            break;
            case 4:
            break;
            case 5:
            break;
            case 6:
            break;
            case 7:
            break;
            case 8:
            break;
            case 9:
            break;
            case 10:
            break;
            case 11:
            break;
            case 12:
            break;
            case 13:
            break;
            case 14:
            break;
            case 15:
            break;
            case 16:
            //tempData = testRegister;
            break;
            default:
            break;
            }
            return result;
            }//uint16 getRegisterVal(uint16 addr,uint16 &data)
            //設(shè)置寄存器值 返回0表示成功
            uint16 setRegisterVal(uint16 addr,uint16 tempData)
            {
            uint16 result = 0;
            uint16 tempAddr;
            tempAddr = addr & 0xfff;
            switch(tempAddr & 0xff)
            {
            case 0:
            break;
            case 1:
            break;
            case 2:
            break;
            case 3:
            break;
            case 4:
            break;
            case 5:
            break;
            case 6:
            break;
            case 7:
            break;
            case 8:
            break;
            case 9:
            break;
            case 10:
            break;
            case 11:
            break;
            case 12:
            break;
            case 13:
            break;
            case 14:
            break;
            case 15:
            break;
            case 16:
            testRegister = tempData;
            break;
            default:
            break;
            }
            return result;
            }

            上一頁 1 2 下一頁

            關(guān)鍵詞: 51單片機MODBUSC語

            評論


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

            關(guān)閉