资源描述:
《51单片机实现Modbus从机程序0》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、自己用单片机做的Modbus从机,可以使用STC89C52。实现了命令码为1、2、3、4、5、6的功能,程序中有些是我们部分其他功能的函数和数据,希望大家参考下编程的思想。uintSwitch=0xbc95;//开关状态ucharbdataCoil1=0xff,Coil2=0xbc;//16位线圈状态sbitCoil1_bit0=Coil1^0;sbitCoil1_bit1=Coil1^1;sbitCoil1_bit2=Coil1^2;sbitCoil1_bit3=Coil1^3;sbitCoil1_bit4=Coil1^4;sbitCoil1_bit5=Coil1^5;sbi
2、tCoil1_bit6=Coil1^6;sbitCoil1_bit7=Coil1^7;sbitCoil2_bit8=Coil2^0;sbitCoil2_bit9=Coil2^1;sbitCoil2_bit10=Coil2^2;sbitCoil2_bit11=Coil2^3;sbitCoil2_bit12=Coil2^4;sbitCoil2_bit13=Coil2^5;sbitCoil2_bit14=Coil2^6;sbitCoil2_bit15=Coil2^7;uintidataReOnlybuf[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x
3、07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};uintidataReWrbuf[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};//CRC校验查表码值constucharcodeauchCRCHi[]={0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x00,0xC1
4、,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,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0
5、x00,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,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x8
6、1,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,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x01,
7、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,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x00,0xC1,0x81,0x40,0x01,0xC0,0x80,0x41,0x00,0xC1,0x81,0x40,0x01,0xC0,0x8