⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rxr_cs.lst

📁 714771878051_MODBUS_RTU.rar
💻 LST
📖 第 1 页 / 共 4 页
字号:

 179   1               P0=0xFF;
 180   1          while(1)
 181   1               {
 182   2               WDT_CONTR = 0x36;
 183   2               addr=P0;     //取地址
 184   2               AV_in();
 185   2                       if(command_ok==1)
 186   2                         {XJ=0;command();}
 187   2               }
 188   1          }
 189          
 190          void command(void)
 191               {
 192   1               uint js_CRC,star_fun,sl_n,AI;
 193   1               RUN=0;
 194   1               pushMsg=&recebuf_com[0];
 195   1               crc_z=CRC16(pushMsg,command_Len-2);
 196   1      
 197   1           js_CRC=recebuf_com[command_Len-2];
 198   1           js_CRC=(js_CRC<<8)|((uint)(recebuf_com[command_Len-1]));
 199   1      
 200   1               if((recebuf_com[0]==addr)&&(js_CRC==crc_z))//是否发给本机,并CRC正确?
 201   1                 {
 202   2                 switch (recebuf_com[1])
 203   2                       {
 204   3                               case 0x01:    //读取线圈状态
 205   3                                   {
 206   4                        star_fun=recebuf_com[2];star_fun=(star_fun<<8)|(recebuf_com[3]);//取开始地址
 207   4                        sl_n=recebuf_com[4];sl_n=(sl_n<<8)|(recebuf_com[5]);     //读取地址
 208   4                                        switch (star_fun)
 209   4                                             {
 210   5                                                      case 0:
 211   5                                                          {
 212   6                                                              command_01();
 213   6                                                              sendbuf[3]=(0x01&OUT_IO)?1:0;      //低
 214   6                                                              group_out_ad();
 215   6                                                              break;
 216   6                                                              }
 217   5                                                      case 1:
 218   5                                                          {
 219   6                                                              command_01();
 220   6                                                              sendbuf[3]=(0x02&OUT_IO)?1:0;      //低
 221   6                                                              group_out_ad();
 222   6                                                              break;
 223   6                                                              }
 224   5                                                      case 2:
 225   5                                                          {
 226   6                                                              command_01();
 227   6                                                              sendbuf[3]=(0x04&OUT_IO)?1:0;      //低
 228   6                                                              group_out_ad();
 229   6                                                              break;
 230   6                                                              }
 231   5                                                      case 3:
 232   5                                                          {
 233   6                                                              command_01();
 234   6                                                              sendbuf[3]=(0x08&OUT_IO)?1:0;      //低
 235   6                                                              group_out_ad();
 236   6                                                              break;
 237   6                                                              }
 238   5                                                      case 4:
 239   5                                                          {
 240   6                                                              command_01();
C51 COMPILER V7.06   RXR_CS                                                                06/26/2006 22:51:01 PAGE 5   

 241   6                                                              sendbuf[3]=(0x10&OUT_IO)?1:0;      //低
 242   6                                                              group_out_ad();
 243   6                                                              break;
 244   6                                                              }
 245   5                                                      case 5:
 246   5                                                          {
 247   6                                                              command_01();
 248   6                                                              sendbuf[3]=(0x20&OUT_IO)?1:0;      //低
 249   6                                                              group_out_ad();
 250   6                                                              break;
 251   6                                                              }
 252   5                                                      default:
 253   5                                                          sendbuf[0]=addr;             //取地址
 254   5                                      sendbuf[1]=0xff;             //命令号
 255   5                                                              send_Len=2;                  //发送数据长度
 256   5                                                              group_out_ad();
 257   5                                                          break;
 258   5                                                  }
 259   4                                        break;
 260   4                                       }
 261   3                               case 0x02:    //读取输入状态
 262   3                                  {
 263   4                                      star_fun=recebuf_com[2];star_fun=(star_fun<<8)+recebuf_com[3];//取开始地址
 264   4                      //sl_n=recebuf_com[4];sl_n=(sl_n<<8)|(recebuf_com[5]);        //读取的数量
 265   4                                      switch  (star_fun)
 266   4                                              {
 267   5                                                      case 1:
 268   5                                                          {
 269   6                                                              command_02();
 270   6                                                              sendbuf[3]=(0x01&P1)?1:0;      //低
 271   6                                                              group_out_ad();
 272   6                                                              break;
 273   6                                                              }
 274   5                                                      case 2:
 275   5                                                          {
 276   6                                                              command_02();
 277   6                                                              sendbuf[3]=(0x02&P1)?1:0;      //低
 278   6                                                              group_out_ad();
 279   6                                                              break;
 280   6                                                              }
 281   5                                                      case 3:
 282   5                                                          {
 283   6                                                              command_02();
 284   6                                                              sendbuf[3]=(0x04&P1)?1:0;      //低
 285   6                                                              group_out_ad();
 286   6                                                              break;
 287   6                                                              }
 288   5                                                      case 4:
 289   5                                                          {
 290   6                                                              command_02();
 291   6                                                              sendbuf[3]=(0x08&P1)?1:0;      //低
 292   6                                                              group_out_ad();
 293   6                                                              break;
 294   6                                                              }
 295   5                                                      case 5:
 296   5                                                          {
 297   6                                                              command_02();
 298   6                                                              sendbuf[3]=(0x10&P1)?1:0;      //低
 299   6                                                              group_out_ad();
 300   6                                                              break;
 301   6                                                              }
 302   5                                                      case 6:
C51 COMPILER V7.06   RXR_CS                                                                06/26/2006 22:51:01 PAGE 6   

 303   5                                                          {
 304   6                                                              command_02();
 305   6                                                              sendbuf[3]=(0x20&P1)?1:0;      //低
 306   6                                                              group_out_ad();
 307   6                                                              break;
 308   6                                                              }
 309   5                                                      case 7:
 310   5                                                          {
 311   6                                                              command_02();
 312   6                                                              sendbuf[3]=(0x40&P1)?1:0;      //低
 313   6                                                              group_out_ad();
 314   6                                                              break;
 315   6                                                              }
 316   5                                                      case 8:
 317   5                                                          {
 318   6                                                              command_02();
 319   6                                                              sendbuf[3]=(0x80&P1)?1:0;      //低
 320   6                                                              group_out_ad();
 321   6                                                              break;
 322   6                                                              }
 323   5                                                      default :
 324   5                                                          sendbuf[0]=addr;             //取地址
 325   5                                      sendbuf[1]=0xff;             //命令号
 326   5                                                              send_Len=2;                  //发送数据长度
 327   5                                                              group_out_ad();
 328   5                                                          break;
 329   5                                                      }
 330   4                                        break;
 331   4                                        }
 332   3                               case 0x03:    //读取保持寄存器
 333   3                                    {
 334   4                        star_fun=recebuf_com[2];star_fun=(star_fun<<8)+recebuf_com[3];//取开始地址
 335   4                        sl_n=recebuf_com[4];sl_n=(sl_n<<8)|(recebuf_com[5]);          //读取的数量
 336   4                        switch(star_fun)     //必须从地址0开始
 337   4                              {
 338   5                              case 0:
 339   5                                   {
 340   6                                   switch (sl_n)
 341   6                                                         {
 342   7                                                                 case 1:
 343   7                                                                       {
 344   8                                                                           command_03();
 345   8                                                                           sendbuf[2]=(uchar)(sl_n*2);     //返回字节数
 346   8                                                                           AI=ad1;
 347   8                                               sendbuf[3]=(uchar)(AI>>8);      //高
 348   8                                                                           sendbuf[4]=(uchar)(ad1);        //低
 349   8                                                                           send_Len=(sendbuf[2]+3);        //发送数据长度
 350   8                                                                           group_out_ad();
 351   8                                                                           break;
 352   8                                                                           }
 353   7                                                                 case 2:
 354   7                                                                       {
 355   8                                                                           command_03();
 356   8                                                                           sendbuf[2]=(uchar)(sl_n*2);     //返回字节数
 357   8                                                                           AI=ad1;
 358   8                                               sendbuf[3]=(uchar)(AI>>8);      //高
 359   8                                                                           sendbuf[4]=(uchar)(ad1);        //低
 360   8                                                                           AI=ad2;
 361   8                                               sendbuf[5]=(uchar)(AI>>8);      //高
 362   8                                                                           sendbuf[6]=(uchar)(ad2);        //低
 363   8                                                                           send_Len=(sendbuf[2]+3);        //发送数据长度
 364   8                                                                           group_out_ad();
C51 COMPILER V7.06   RXR_CS                                                                06/26/2006 22:51:01 PAGE 7   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -