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

📄 intspc3.lst

📁 使用8052单片机控制SPC3总线桥实现PROFIBUS-DP现场总线的从站部分C程序源码
💻 LST
📖 第 1 页 / 共 2 页
字号:
 188   2              result = DPS_CFG_OK;
 189   2      
 190   2              do
 191   2                      {   /* check configuration data until no conflict behavior m*/
 192   3                      cfg_ptr = DPS2_GET_CFG_BUF_PTR();             /* pointer to the config_data_block */
 193   3                      config_data_len = DPS2_GET_CFG_LEN();
 194   3      
 195   3                      /* In this example the only possible configurations are 0x13 and 0x23
 196   3                         (4 Byte I/O) or 0x11 and 0x21 (2 Byte I/O) are possible */
 197   3      
 198   3                      if ( config_data_len != 2)
 199   3                              cfg_result = DPS2_SET_CFG_DATA_NOT_OK();
 200   3                      else
 201   3                              {   /* Length of the configuration data  o.k. */
 202   4                                      /* check the configuratin bytes           */
 203   4      
 204   4                              if ((cfg_akt[0] == cfg_ptr[0]) && (cfg_akt[1] == cfg_ptr[1]))
 205   4                                      result = DPS_CFG_OK;
 206   4                                      /* the desired conf. is equal the actuall configuration */
 207   4                              else
 208   4                                      {
 209   5                                      if (((cfg_ptr[0] == 0x13) && (cfg_ptr[1]) ==0x23)
 210   5                                        || ((cfg_ptr[0] == 0x11) && (cfg_ptr[1]) ==0x21))
 211   5                                              {
 212   6                                              cfg_akt[0] = cfg_ptr[0];
 213   6                                              cfg_akt[1] = cfg_ptr[1];
 214   6                                              result = DPS_CFG_UPDATE;
 215   6                                              }
 216   5                                      else
 217   5                                              result = DPS_CFG_FAULT;              /* as example !!!!! */
 218   5      
 219   5      
 220   5                                      if (result == DPS_CFG_UPDATE)
 221   5                                              {
 222   6                                              user_io_data_len_ptr = dps2_calculate_inp_outp_len (cfg_ptr,(UWORD)config_data_len);
 223   6                                              if (user_io_data_len_ptr != (DPS2_IO_DATA_LEN *)0)
 224   6                                                      {
 225   7                                                      DPS2_SET_IO_DATA_LEN(user_io_data_len_ptr);
 226   7                                                      }
 227   6                                              else
 228   6                                                      result = DPS_CFG_FAULT;
 229   6                                              }
 230   5                                      }
 231   4                              switch (result)
 232   4                                      {
 233   5                                      case DPS_CFG_OK: cfg_result = DPS2_SET_CFG_DATA_OK();
 234   5                                              break;
 235   5      
 236   5                                      case DPS_CFG_FAULT: cfg_result = DPS2_SET_CFG_DATA_NOT_OK();
 237   5                                              break;
 238   5      
 239   5                                      case DPS_CFG_UPDATE: cfg_result = DPS2_SET_CFG_DATA_UPDATE();
 240   5                                              break;
 241   5                                      }
C51 COMPILER V7.50   INTSPC3                                                               10/24/2007 09:35:19 PAGE 5   

 242   4                              }
 243   3      
 244   3                      } while(cfg_result == DPS2_CFG_CONFLICT);
 245   2              }
 246   1      
 247   1      if(DPS2_GET_IND_NEW_SSA_DATA())
 248   1              {   /*=== New Slave address received ===*/
 249   2              address_data_function(DPS2_GET_SSA_BUF_PTR(), DPS2_GET_SSA_LEN());
 250   2              DPS2_CON_IND_NEW_SSA_DATA();    /* confirm this indication */
 251   2              }
 252   1      
 253   1      if(DPS2_GET_IND_WD_DP_MODE_TIMEOUT())
 254   1              {   /*=== Watchdog is run out ===*/
 255   2              wd_dp_mode_timeout_function();
 256   2              DPS2_CON_IND_WD_DP_MODE_TIMEOUT();  /* confirm this indication */
 257   2              }
 258   1      if(SPC3_GET_IND_USER_TIMER_CLOCK())
 259   1              {   /*==== Timer tick received ====*/
 260   2              SPC3_CON_IND_USER_TIMER_CLOCK();
 261   2              }
 262   1      
 263   1      if(SPC3_GET_IND_BAUDRATE_DETECT())
 264   1              {   /*==== Baudrate found  ====*/
 265   2      
 266   2              /* If the baudrate has lost and again found in the state WAIT_CFG,  */
 267   2              /*  DATA_EX the SPC3 would answer to the next telegramms            */
 268   2              /*  with his default mintsdr.                                       */
 269   2              /* But he should answer in the meantime parametrized mindstr        */
 270   2      
 271   2              if ((DPS2_GET_DP_STATE() ==  DPS2_DP_STATE_WAIT_CFG )
 272   2                      ||  (DPS2_GET_DP_STATE()  ==  DPS2_DP_STATE_DATA_EX))
 273   2                       SPC3_SET_MINTSDR(store_mintsdr);
 274   2      
 275   2              SPC3_CON_IND_BAUDRATE_DETECT();
 276   2              }
 277   1      SPC3_SET_EOI(); /* */
 278   1      }   /* End dps2_ind() */
 279          
 280          
 281          
 282          /************************************************************************/
 283          /*  D e s c r i p t i o n :                                             */
 284          /*                                                                      */
 285          /*  address data function                                               */
 286          /************************************************************************/
 287          #pragma global
 288          
 289          void address_data_function (void SPC3_PTR_ATTR*(address_data_ptr), UBYTE address_data_len)
 290          {
 291   1      char    ch;
 292   1      
 293   1      /* change the slave-address */
 294   1      struct dps_address_data SPC3_PTR_ATTR * addr_ptr;
 295   1      
 296   1      ch=address_data_len;
 297   1      
 298   1      addr_ptr = address_data_ptr;
 299   1      
 300   1      this_station = addr_ptr->new_address;
 301   1      real_no_add_chg = addr_ptr->no_add_chg;
 302   1      
 303   1      /* store the new address and the bit real_no_add_chg for the next startup */
C51 COMPILER V7.50   INTSPC3                                                               10/24/2007 09:35:19 PAGE 6   

 304   1      
 305   1      DPS2_FREE_SSA_BUF(); /* release the Set Slave Address buffer */
 306   1      }
 307          #pragma public
 308          
 309          
 310          /************************************************************************/
 311          /*  D e s c r i p t i o n :                                             */
 312          /*                                                                      */
 313          /*  restart_function                                               */
 314          /************************************************************************/
 315          
 316          #pragma global
 317          
 318          void wd_dp_mode_timeout_function (void)
 319          {
 320   1      UBYTE rueck;
 321   1              /* Watchdog is run out. The SPC3 reset the PROFIBUS DP Statemachine */
 322   1      
 323   1      user_wd_state = SPC3_GET_WD_STATE();
 324   1      
 325   1              /*SX    small weakness of the SPC3
 326   1                              Update of the diagnosis with 00
 327   1                              otherwise the bit "static diagnosis" would appear in the
 328   1                              next startup */
 329   1      
 330   1      
 331   1      rueck = DPS2_SET_DIAG_LEN(6);
 332   1      rueck = DPS2_SET_DIAG_STATE(0x00);
 333   1      DPS2_DIAG_UPDATE();
 334   1      
 335   1      
 336   1      }
 337          #pragma public
 338          
 339          /************************************************************************/
 340          /*  D e s c r i p t i o n :                                             */
 341          /*                                                                      */
 342          /*  global_ctrl_command_function                                        */
 343          /************************************************************************/
 344          #pragma global
 345          
 346          void global_ctrl_command_function (void)
 347          {
 348   1      
 349   1      user_global_ctrl_command = DPS2_GET_GC_COMMAND();
 350   1      
 351   1      }
 352          #pragma public
 353          
 354          /************************************************************************/
 355          /*  D e s c r i p t i o n :                                             */
 356          /*                                                                      */
 357          /*  go_leave_data_ex_function                                           */
 358          /************************************************************************/
 359          #pragma global
 360          
 361          void go_leave_data_ex_function (void)
 362          {
 363   1      
 364   1      user_dps_state = DPS2_GET_DP_STATE();
 365   1      }
C51 COMPILER V7.50   INTSPC3                                                               10/24/2007 09:35:19 PAGE 7   

 366          
 367          #pragma public
 368          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    871    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =      4       6
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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