基于單片機的 modbus例程 詳細

上傳人:xins****2008 文檔編號:111930335 上傳時間:2022-06-21 格式:DOCX 頁數(shù):12 大小:19.94KB
收藏 版權(quán)申訴 舉報 下載
基于單片機的 modbus例程 詳細_第1頁
第1頁 / 共12頁
基于單片機的 modbus例程 詳細_第2頁
第2頁 / 共12頁
基于單片機的 modbus例程 詳細_第3頁
第3頁 / 共12頁

下載文檔到電腦,查找使用更方便

10 積分

下載資源

還剩頁未讀,繼續(xù)閱讀

資源描述:

《基于單片機的 modbus例程 詳細》由會員分享,可在線閱讀,更多相關(guān)《基于單片機的 modbus例程 詳細(12頁珍藏版)》請在裝配圖網(wǎng)上搜索。

1、#include #define uint8 unsigned char#define uint16 unsigned int#define FOSC 16000000uint16 BAUD=9600;uint16 TEMP_Alert=1000;/字地址 0 - 255 (只取低8位)/位地址 0 - 255 (只取低8位)/* CRC 高位字節(jié)值表 */ const uint8 code auchCRCHi = 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0/*/, 0x80, 0x41, 0x00, 0xC1, 0x8

2、1, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x0

3、1, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x8

4、0, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x0

5、1, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x8

6、1, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 ; /* CRC低位字節(jié)值表*/ const uint8 code auchCRCLo = 0x00,

7、0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06/*/, 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC, 0x14, 0xD4, 0xD

8、5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3, 0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32, 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4, 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A, 0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 0x28, 0xE8, 0xE9, 0x29, 0xE

9、B, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26, 0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, 0x61, 0xA1, 0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F, 0x6

10、E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68, 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, 0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5, 0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0, 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92, 0x9

11、6, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C, 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89, 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C, 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x4

12、3, 0x83, 0x41, 0x81, 0x80, 0x40 ;uint16 TempRegister; /用于測試 字址址16uint8 localAddr = 0x01; /單片機控制板的地址uint8 sendCount; /發(fā)送字節(jié)個數(shù)uint8 receCount; /接收到的字節(jié)個數(shù)/uint8 sendPosi; /發(fā)送位置uint8 xdata receBuf1;uint8 xdata sendBuf1;void checkComm0Modbus(void);uint16 getRegisterVal(uint16 addr,uint16 *tempData);uint16

13、setRegisterVal(uint16 addr,uint16 tempData);void switch_BAUD(uint16 value);/*波特率調(diào)整函數(shù) */函數(shù)功能:調(diào)整串口通信波特率/串口工作在工作方式1,即8位波特率可變模式/*/void switch_BAUD(uint16 value) switch(value) case 0x0001: BAUD=9600;break; case 0x0002: BAUD=14400;break; case 0x0003: BAUD=19200;break; TR1=0; /停止定時器1 ES=0; /關(guān)閉串口中斷 TH1=TL1=

14、-(FOSC/12/32/BAUD); /設(shè)置波特率 TR1=1; /開啟定時器1 ES=1; /使能串口中斷/*end*/*CRC校驗碼生成函數(shù) */函數(shù)功能:生成CRC校驗碼/本代碼中使用查表法,以提高運算速度/*/uint16 crc16(uint8 *puchMsg, uint16 usDataLen) uint8 uchCRCHi = 0xFF ; /* 高CRC字節(jié)初始化 */ uint8 uchCRCLo = 0xFF ; /* 低CRC 字節(jié)初始化 */ uint16 uIndex ; /* CRC循環(huán)中的索引 */ while (usDataLen-) /* 傳輸消息緩沖區(qū)

15、*/ uIndex = uchCRCHi *puchMsg+ ; /* 計算CRC */ uchCRCHi = uchCRCLo auchCRCHiuIndex ; uchCRCLo = auchCRCLouIndex ; return (uchCRCLo 8 | uchCRCHi) ; /uint16 crc16(uint8 *puchMsg, uint16 usDataLen)/*end*/*串口發(fā)送函數(shù) */函數(shù)功能:將數(shù)據(jù)包通過串口發(fā)送至主機/有待修改./*/開始發(fā)送void Begin_send(void) uint16 i=0; while(sendCount-) SBUF = s

16、endBufi+; while(!TI); /*end*/*從機響應(yīng)主機問詢函數(shù),function code : 03,讀取多個寄存器值 */函數(shù)功能:叢機根據(jù)串口接收到的數(shù)據(jù)包receBuf里面的內(nèi)容,根據(jù)被讀取寄存器/的起始地址和讀取的寄存器個數(shù),去讀相應(yīng)的寄存器的值,并將讀取的數(shù)據(jù)以MODBUS/響應(yīng)數(shù)據(jù)的標(biāo)準(zhǔn)格式打包,經(jīng)過串口發(fā)送到主機。數(shù)據(jù)包格式同上。/*/ 詢問數(shù)據(jù)包格式:/ receBuf0 receBuf1 receBuf2 receBuf3 receBuf4 receBuf5 receBuf6 receBuf7 /詢問數(shù)據(jù)格式:receBuf=從站地址, 功能碼, 起始地址高

17、位,起始地址低位,寄存器數(shù)高位, 寄存器數(shù)低位, 校驗碼低位, 校驗碼高位/ 響應(yīng)數(shù)據(jù)包格式:/ sendBuf0 sendBuf1 sendBuf2 sendBuf3 sendBuf4 sendBuf5. receBuf6 receBuf7 /響應(yīng)數(shù)據(jù)格式:receBuf=從站地址, 功能碼, 字節(jié)計數(shù), 數(shù)據(jù)1, 數(shù)據(jù)2, 數(shù)據(jù)3,. 校驗碼低位, 校驗碼高位void readRegisters(void) uint8 addr; uint8 tempAddr; uint16 crcData; uint8 readCount; uint8 byteCount; uint16 i; uint

18、16 tempData = 0; /addr = (receBuf28) + receBuf3; /tempAddr = addr & 0xfff; addr = receBuf3; tempAddr = addr; /readCount = (receBuf48) + receBuf5; /要讀的個數(shù) readCount = receBuf5; byteCount = readCount * 2; /每個寄存器內(nèi)容占高,低兩個字節(jié) for(i=0;i 8; sendBufi+4 = tempData & 0xff; sendBuf0 = localAddr; sendBuf1 = 3; /f

19、unction code : 03 sendBuf2 = byteCount; byteCount += 3; /加上前面的地址,功能碼,地址 共3+byteCount個字節(jié) crcData = crc16(sendBuf,byteCount); sendBufbyteCount = crcData & 0xff; / CRC代碼低位在前 byteCount+; sendBufbyteCount = crcData 8 ; /高位在后 sendCount = byteCount + 1;/例如byteCount=49,則sendBuf中實際上有49+1個元素待發(fā) Begin_send();/v

20、oid readRegisters(void)/*end*/ /*從機響應(yīng)主機問詢函數(shù),function code : 16,設(shè)置多個寄存器值 */函數(shù)功能:叢機根據(jù)串口接收到的數(shù)據(jù)包receBuf里面的內(nèi)容,根據(jù)被強制寄存器/的起始地址,去設(shè)置相應(yīng)寄存器的值,響應(yīng)數(shù)據(jù)包同詢問數(shù)據(jù)包/的內(nèi)容相同,經(jīng)過串口發(fā)送到主機。/*/詢問數(shù)據(jù)包格式:/ receBuf0 receBuf1 receBuf2 receBuf3 receBuf4 receBuf5 receBuf6 receBuf7 receBuf8 . receBuf9 receBuf10 /詢問數(shù)據(jù)格式:receBuf=從站地址, 功能碼,

21、 起始地址高位,起始地址低位,寄存器數(shù)高位,寄存器數(shù)低位, 字節(jié)計數(shù), 數(shù)據(jù)高位, 數(shù)據(jù)低位,. 校驗碼低位, 校驗碼高位/響應(yīng)數(shù)據(jù)包內(nèi)容為除去詢問數(shù)據(jù)包中的字節(jié)計數(shù)和數(shù)據(jù)高低位的其他內(nèi)容void presetMultipleRegisters(void)uint8 addr;uint8 tempAddr;uint8 byteCount;uint8 setCount;uint16 crcData;uint16 tempData;uint8 i;/addr = (receBuf28) + receBuf3;/tempAddr = addr & 0xfff;addr = receBuf3;temp

22、Addr = addr & 0xff;/setCount = (receBuf48) + receBuf5;setCount = receBuf5;byteCount = receBuf6; for(i=0;isetCount;i+,tempAddr+) tempData = (receBufi*2+7 8; /寄存器地址高位sendBuf3 = addr & 0xff;/寄存器地址低位sendBuf4 = setCount 8;/待設(shè)置寄存器數(shù)量高位sendBuf5 = setCount & 0xff;/待設(shè)置寄存器數(shù)量低位crcData = crc16(sendBuf,6);/生成CRC校

23、驗碼sendBuf6 = crcData & 0xff; /CRC代碼低位在前sendBuf7 = crcData 8; /高位在后sendCount = 8;Begin_send(); /void presetMultipleRegisters(void)/*end*/*查詢uart接收的數(shù)據(jù)包內(nèi)容函數(shù) */函數(shù)功能:叢機根據(jù)串口接收到的數(shù)據(jù)包receBuf1里面的內(nèi)容,即function code執(zhí)行/相應(yīng)的命令/*/void checkComm0Modbus(void)uint16 crcData;uint16 tempData;if(receCount 4) switch(receBu

24、f1) case 3:/讀取保持寄存器(一個或多個) if(receCount = 8) /從詢問數(shù)據(jù)包格式可知,receCount應(yīng)該等于8 /接收完成一組數(shù)據(jù) /應(yīng)該關(guān)閉接收中斷 if(receBuf0=localAddr) /核對地址 crcData = crc16(receBuf,6); /核對校驗碼 if(crcData = receBuf7+(receBuf68) if(receBuf1 = 3) /讀取保持寄存器(一個或多個) readRegisters(); receCount = 0; break; case 16:/設(shè)置多個寄存器 tempData = (receBuf4=

25、 tempData) if(receBuf0=localAddr ) crcData = crc16(receBuf,tempData-2); if(crcData = (receBuftempData-28)+ receBuftempData-1) presetMultipleRegisters(); receCount = 0; break; default: break; /void checkComm0(void)/*end*/*讀取寄存器內(nèi)容函數(shù) */函數(shù)功能:根據(jù)寄存器地址讀取相應(yīng)寄存器內(nèi)容/*/取寄存器值 返回0表示成功uint16 getRegisterVal(uint16 a

26、ddr,uint16 *tempData)uint16 result = 0;uint16 tempAddr;tempAddr = addr & 0xfff;switch(tempAddr & 0xff) case 0x00: *tempData = TempRegister; break; /讀取01開關(guān)A溫度 case 0x01: *tempData = TempRegister; break; /讀取01開關(guān)A溫度 case 0x02: *tempData = TempRegister; break; /讀取01開關(guān)A溫度 case 0x03: *tempData = TempRegis

27、ter; break; /讀取01開關(guān)周邊溫度 case 0x04: *tempData = TempRegister; break; /讀取02開關(guān)A溫度 case 0x05: *tempData = TempRegister; break; /讀取02開關(guān)A溫度 case 0x06: *tempData = TempRegister; break; /讀取02開關(guān)A溫度 case 0x07: *tempData = TempRegister; break; /讀取02開關(guān)周邊溫度 case 0x08: *tempData = TempRegister; break; /讀取03開關(guān)A溫度

28、case 0x09: *tempData = TempRegister; break; /讀取03開關(guān)A溫度 case 0x0a: *tempData = TempRegister; break; /讀取03開關(guān)A溫度 case 0x0b: *tempData = TempRegister; break; /讀取03開關(guān)周邊溫度 case 0x0c: *tempData = TempRegister; break; /讀取04開關(guān)A溫度 case 0x0d: *tempData = TempRegister; break; /讀取04開關(guān)A溫度 case 0x0e: *tempData = T

29、empRegister; break; /讀取04開關(guān)A溫度 case 0x0f: *tempData = TempRegister; break; /讀取04開關(guān)周邊溫度 case 0x10: *tempData = TempRegister; break; /讀取05開關(guān)A溫度 case 0x11: *tempData = TempRegister; break; /讀取05開關(guān)A溫度 case 0x12: *tempData = TempRegister; break; /讀取05開關(guān)A溫度 case 0x13: *tempData = TempRegister; break; /讀取0

30、5開關(guān)周邊溫度 case 0x14: *tempData = TempRegister; break; /讀取06開關(guān)A溫度 case 0x15: *tempData = TempRegister; break; /讀取06開關(guān)A溫度 case 0x16: *tempData = TempRegister; break; /讀取06開關(guān)A溫度 case 0x17: *tempData = TempRegister; break; /讀取06開關(guān)周邊溫度 case 0x18: *tempData = TempRegister; break; /讀取07開關(guān)A溫度 case 0x19: *temp

31、Data = TempRegister; break; /讀取07開關(guān)A溫度 case 0x1a: *tempData = TempRegister; break; /讀取07開關(guān)A溫度 case 0x1b: *tempData = TempRegister; break; /讀取07開關(guān)周邊溫度 case 0x1c: *tempData = TempRegister; break; /讀取08開關(guān)A溫度 case 0x1d: *tempData = TempRegister; break; /讀取08開關(guān)A溫度 case 0x1e: *tempData = TempRegister; bre

32、ak; /讀取08開關(guān)A溫度 case 0x1f: *tempData = TempRegister; break; /讀取08開關(guān)周邊溫度 case 0x20: *tempData = TempRegister; break; /讀取09開關(guān)A溫度 case 0x21: *tempData = TempRegister; break; /讀取09開關(guān)A溫度 case 0x22: *tempData = TempRegister; break; /讀取09開關(guān)A溫度 case 0x23: *tempData = TempRegister; break; /讀取09開關(guān)周邊溫度 case 0x2

33、4: *tempData = TempRegister; break; /讀取10開關(guān)A溫度 case 0x25: *tempData = TempRegister; break; /讀取10開關(guān)A溫度 case 0x26: *tempData = TempRegister; break; /讀取10開關(guān)A溫度 case 0x27: *tempData = TempRegister; break; /讀取10開關(guān)周邊溫度 case 0x28: *tempData = TempRegister; break; /讀取11開關(guān)A溫度 case 0x29: *tempData = TempRegis

34、ter; break; /讀取11開關(guān)A溫度 case 0x2a: *tempData = TempRegister; break; /讀取11開關(guān)A溫度 case 0x2b: *tempData = TempRegister; break; /讀取11開關(guān)周邊溫度 case 0x2c: *tempData = TempRegister; break; /讀取12開關(guān)A溫度 case 0x2d: *tempData = TempRegister; break; /讀取12開關(guān)A溫度 case 0x2e: *tempData = TempRegister; break; /讀取12開關(guān)A溫度 c

35、ase 0x2f: *tempData = TempRegister; break; /讀取12開關(guān)周邊溫度 case 0x30: *tempData = TempRegister; break; /讀取13開關(guān)A溫度 case 0x31: *tempData = TempRegister; break; /讀取13開關(guān)A溫度 case 0x32: *tempData = TempRegister; break; /讀取13開關(guān)A溫度 case 0x33: *tempData = TempRegister; break; /讀取13開關(guān)周邊溫度 case 0x34: *tempData = T

36、empRegister; break; /讀取14開關(guān)A溫度 case 0x35: *tempData = TempRegister; break; /讀取14開關(guān)A溫度 case 0x36: *tempData = TempRegister; break; /讀取14開關(guān)A溫度 case 0x37: *tempData = TempRegister; break; /讀取14開關(guān)周邊溫度 case 0x38: *tempData = TempRegister; break; /讀取15開關(guān)A溫度 case 0x39: *tempData = TempRegister; break; /讀取1

37、5開關(guān)A溫度 case 0x3a: *tempData = TempRegister; break; /讀取15開關(guān)A溫度 case 0x3b: *tempData = TempRegister; break; /讀取15開關(guān)周邊溫度 case 0x3c: *tempData = TempRegister; break; /讀取16開關(guān)A溫度 case 0x3d: *tempData = TempRegister; break; /讀取16開關(guān)A溫度 case 0x3e: *tempData = TempRegister; break; /讀取16開關(guān)A溫度 case 0x3f: *tempD

38、ata = TempRegister; break; /讀取16開關(guān)周邊溫度 case 0x40: *tempData = TempRegister; break; /讀取17開關(guān)A溫度 case 0x41: *tempData = TempRegister; break; /讀取17開關(guān)A溫度 case 0x42: *tempData = TempRegister; break; /讀取17開關(guān)A溫度 case 0x43: *tempData = TempRegister; break; /讀取17開關(guān)周邊溫度 case 0x44: *tempData = TempRegister; bre

39、ak; /讀取18開關(guān)A溫度 case 0x45: *tempData = TempRegister; break; /讀取18開關(guān)A溫度 case 0x46: *tempData = TempRegister; break; /讀取18開關(guān)A溫度 case 0x47: *tempData = TempRegister; break; /讀取18開關(guān)周邊溫度 case 0x48: *tempData = TempRegister; break; /讀取19開關(guān)A溫度 case 0x49: *tempData = TempRegister; break; /讀取19開關(guān)A溫度 case 0x4a

40、: *tempData = TempRegister; break; /讀取19開關(guān)A溫度 case 0x4b: *tempData = TempRegister; break; /讀取19開關(guān)周邊溫度 case 0x4c: *tempData = TempRegister; break; /讀取20開關(guān)A溫度 case 0x4d: *tempData = TempRegister; break; /讀取20開關(guān)A溫度 case 0x4e: *tempData = TempRegister; break; /讀取20開關(guān)A溫度 case 0x4f: *tempData = TempRegist

41、er; break; /讀取20開關(guān)周邊溫度 case 0x50: *tempData = TempRegister; break; /讀取21開關(guān)A溫度 case 0x51: *tempData = TempRegister; break; /讀取21開關(guān)A溫度 case 0x52: *tempData = TempRegister; break; /讀取21開關(guān)A溫度 case 0x53: *tempData = TempRegister; break; /讀取21開關(guān)周邊溫度 case 0x54: *tempData = TempRegister; break; /讀取22開關(guān)A溫度 c

42、ase 0x55: *tempData = TempRegister; break; /讀取22開關(guān)A溫度 case 0x56: *tempData = TempRegister; break; /讀取22開關(guān)A溫度 case 0x57: *tempData = TempRegister; break; /讀取22開關(guān)周邊溫度 case 0x58: *tempData = TempRegister; break; /讀取23開關(guān)A溫度 case 0x59: *tempData = TempRegister; break; /讀取23開關(guān)A溫度 case 0x5a: *tempData = Te

43、mpRegister; break; /讀取23開關(guān)A溫度 case 0x5b: *tempData = TempRegister; break; /讀取23開關(guān)周邊溫度 case 0x5c: *tempData = TempRegister; break; /讀取24開關(guān)A溫度 case 0x5d: *tempData = TempRegister; break; /讀取24開關(guān)A溫度 case 0x5e: *tempData = TempRegister; break; /讀取24開關(guān)A溫度 case 0x5f: *tempData = TempRegister; break; /讀取24

44、開關(guān)周邊溫度 case 0x60: *tempData = TempRegister; break; /讀取25開關(guān)A溫度 case 0x61: *tempData = TempRegister; break; /讀取25開關(guān)A溫度 case 0x62: *tempData = TempRegister; break; /讀取25開關(guān)A溫度 case 0x63: *tempData = TempRegister; break; /讀取25開關(guān)周邊溫度 case 0x64: *tempData = TempRegister; break; /讀取26開關(guān)A溫度 case 0x65: *tempD

45、ata = TempRegister; break; /讀取26開關(guān)A溫度 case 0x66: *tempData = TempRegister; break; /讀取26開關(guān)A溫度 case 0x67: *tempData = TempRegister; break; /讀取26開關(guān)周邊溫度 case 0x68: *tempData = TempRegister; break; /讀取27開關(guān)A溫度 case 0x69: *tempData = TempRegister; break; /讀取27開關(guān)A溫度 case 0x6a: *tempData = TempRegister; brea

46、k; /讀取27開關(guān)A溫度 case 0x6b: *tempData = TempRegister; break; /讀取27開關(guān)周邊溫度 case 0x6c: *tempData = TempRegister; break; /讀取28開關(guān)A溫度 case 0x6d: *tempData = TempRegister; break; /讀取28開關(guān)A溫度 case 0x6e: *tempData = TempRegister; break; /讀取28開關(guān)A溫度 case 0x6f: *tempData = TempRegister; break; /讀取28開關(guān)周邊溫度 case 0x70

47、: *tempData = TempRegister; break; /讀取29開關(guān)A溫度 case 0x71: *tempData = TempRegister; break; /讀取29開關(guān)A溫度 case 0x72: *tempData = TempRegister; break; /讀取29開關(guān)A溫度 case 0x73: *tempData = TempRegister; break; /讀取29開關(guān)周邊溫度 case 0x74: *tempData = TempRegister; break; /讀取30開關(guān)A溫度 case 0x75: *tempData = TempRegist

48、er; break; /讀取30開關(guān)A溫度 case 0x76: *tempData = TempRegister; break; /讀取30開關(guān)A溫度 case 0x77: *tempData = TempRegister; break; /讀取30開關(guān)周邊溫度 case 0x78: *tempData = localAddr; break; /讀取設(shè)備地址 case 0x79: *tempData = BAUD; break; /讀取串口通信波特率 case 0x7a: *tempData = TEMP_Alert; break; /讀取報警溫度上限 case 0x7b: *tempDat

49、a = TempRegister; break; /讀取年寄存器 case 0x7c: *tempData = TempRegister; break; /讀取月寄存器 case 0x7d: *tempData = TempRegister; break; /讀取日寄存器 case 0x7e: *tempData = TempRegister; break; /讀取時寄存器 case 0x7f: *tempData = TempRegister; break; /讀取分寄存器 case 0x80: *tempData = TempRegister; break; /讀取秒寄存器 default

50、: break; return result;/uint16 getRegisterVal(uint16 addr,uint16 &data)/*end*/*設(shè)置寄存器內(nèi)容函數(shù) */函數(shù)功能:根據(jù)寄存器地址設(shè)置相應(yīng)寄存器內(nèi)容/*/設(shè)置寄存器值 返回0表示成功uint16 setRegisterVal(uint16 addr,uint16 tempData)uint16 result = 0;uint16 tempAddr;tempAddr = addr & 0xfff;switch(tempAddr & 0xff) case 0x78: localAddr = tempData; break;

51、/設(shè)置設(shè)備地址,設(shè)備地址初始值為0x01 case 0x79: BAUD = tempData; switch_BAUD(BAUD); break;/設(shè)置串口通信波特率,串口通信波特率寄存器值為 1:9600 , 2:14400 , 3:19200 ,初始值為1 case 0x7a: TEMP_Alert = tempData; break;/設(shè)置報警溫度上限,報警溫度值存儲方式:精確到0.1C,以擴大10倍的數(shù)值放在寄存器里面,例如溫度值為100.1,則讀寫值為1001 case 0x7b: TempRegister = tempData; break;/設(shè)置年寄存器 case 0x7c: TempRegister = tempData; break;/設(shè)置月寄存器 case 0x7d: TempRegister = tempData; break;/設(shè)置日寄存器 case 0x7e: TempRegister = tempData; break;/設(shè)置時寄存器 case 0x7f: TempRegister = tempData; break;/設(shè)置分寄存器 case 0x80: TempRegister = tempData; break;/設(shè)置

展開閱讀全文
溫馨提示:
1: 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
2: 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
3.本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
5. 裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

相關(guān)資源

更多
正為您匹配相似的精品文檔
關(guān)于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

copyright@ 2023-2025  zhuangpeitu.com 裝配圖網(wǎng)版權(quán)所有   聯(lián)系電話:18123376007

備案號:ICP2024067431-1 川公網(wǎng)安備51140202000466號


本站為文檔C2C交易模式,即用戶上傳的文檔直接被用戶下載,本站只是中間服務(wù)平臺,本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對上載內(nèi)容本身不做任何修改或編輯。若文檔所含內(nèi)容侵犯了您的版權(quán)或隱私,請立即通知裝配圖網(wǎng),我們立即給予刪除!