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

📄 userspc3 0810.lst

📁 pROFIBUS 从站源程序 SPC3 pROFIBUS 从站源程序 SPC3
💻 LST
📖 第 1 页 / 共 3 页
字号:
 213          UBYTE                   zyk_dps_state;
 214          UBYTE                   prm_tst_buf[32]= {0,0,0,0,0,0,0,0,0,0,
 215                                                                                                  0,0,0,0,0,0,0,0,0,0,
 216                                                                                                  0,0,0,0,0,0,0,0,0,0,0,0};
 217          enum ERRORCODES error_code;/*枚举类型*/
 218          
 219          /* Locate the structure of the SPC3 in the address space  定位!! */
 220          
 221          SPC3 xdata spc3 _at_ 0x1000;   /*见.Hp3;定位*/
 222          DPRAM xdata dpram _at_ 0x2800;
 223          
 224          /************************************************************************/
 225          /*  D e s c r i p t i o n :                                             */
 226          /*                                                                      */
 227          /*  USER-TASK                                                           */
 228          /************************************************************************/
 229          
 230          
 231          void    main ()
 232          {
 233   1      
 234   1      #if defined __C51__
 235   1              UBYTE xdata * xdata loesch;/* $ */
 236   1              UWORD zaehl;
 237   1      
 238   1              SPC3_RESET = SPC3_RESET_SET;        /* force the Reset Pin 置1复位          */
 239   1              //for(i = 100; i>0 ; i--);             /*  延时  */
 240   1      
 241   1              SPC3_RESET = !SPC3_RESET_SET;        /* sbit  SPC3_RESET = P3^4;  */
C51 COMPILER V7.02b   USERSPC3_0810                                                        11/01/2004 20:51:05 PAGE 5   

 242   1      
 243   1              HW_WATCHDOG_TRIGGER = 1;            /* Retrigger the HW Watchdog    */
 244   1              HW_WATCHDOG_TRIGGER = 0;
 245   1      
 246   1              SPC3_INTERRUPT_ENABLE = !I_ENABLE;  /* Set the interrupt parameters */
 247   1              SPC3_INTERRUPT_PRIOR = P_HIGH;      /* of the microprocessor        */
 248   1      
 249   1              loesch = &spc3.int_req.b[0];        /* Delete the SPC3 internal RAM */
 250   1                                                /* 清空SPC3的RAM .Hp3*/
 251   1              for (zaehl=0x16; zaehl<=0x05ff; zaehl++)      /* 5FFH=1535 */
 252   1                      {
 253   2                      *(loesch + zaehl) = 00;
 254   2                      }
 255   1      
 256   1      #elif   _C166
                      T3OUT = 1;                          /* force the SPC3 reset pin (P3.3) */
                      for(i = 100; i ; i--);
                      T3OUT = 0;
                      CC11IC = 0x18;                      /* SPC3-Interrupt: ILVL = 6, GLVL = 0 */
              #else
                      UBYTE * loesch;
                      UWORD zaehl;
              
                      outp(SPC3_RESET,0x21);
                      outp(SPC3_RESET,0x00);
                      loesch = &spc3.int_req.b[0];        /* Delete the SPC3 internal RAM */
                      for (zaehl=0x16; zaehl<=0x05ff; zaehl++)
                      {
                              *(loesch + zaehl) = 00;
                      }
              #endif
 273   1      
 274   1      /* activate indication functions激活指示函数;用于中断;PDF22&69 .Hp6;函数说明.Hp7;SPC3 0X04 */
 275   1      SPC3_SET_IND(GO_LEAVE_DATA_EX | WD_DP_MODE_TIMEOUT | NEW_GC_COMMAND |\
 276   1                                 NEW_SSA_DATA | NEW_CFG_DATA | NEW_PRM_DATA | BAUDRATE_DETECT);
 277   1      
 278   1      /* set the watchdog value in the SPC3, which checks the microprocessor */
 279   1      DPS2_SET_USER_WD_VALUE(20000);/* .P1 */
 280   1      
 281   1      RL_flag=0x75;
 282   1      LR_flag=0x21;
 283   1      RL_flag=0x75;
 284   1      LR_flag=0x21;
 285   1      /* In this example the input and output bytes are transfered to the
 286   1         IO area, which is addressed by the io_byte_ptr. In the case of the IM183
 287   1         there is RAM. */
 288   1      
 289   1              io_byte_ptr = ((UBYTE*) 0x2E000L); /* $ */
 290   1      
 291   1      for (i=0; i<2; i++)                     /* $ */
 292   1              {
 293   2              (*(io_byte_ptr + i)) = 0;
 294   2              }
 295   1      
 296   1      /* fetch取 the station address, in this case the station address
 297   1         is fixed in EPROM;$p此例中站地址存在EPROM */
 298   1      this_station = OWN_ADDRESS;
 299   1      
 300   1      /* get the Identnumber    */
 301   1      ident_numb_high = IDENT_HIGH; /*ident_numb_high 定义为全局变量 */
 302   1      ident_numb_low =  IDENT_LOW;
 303   1      
C51 COMPILER V7.02b   USERSPC3_0810                                                        11/01/2004 20:51:05 PAGE 6   

 304   1      
 305   1      /* Allow not the change of the slave address by the PROFIBUS DP */
 306   1      /* Attention: The set_slave_address service is not blocked by this */
 307   1      /* 从站地址改变许可性设置 */
 308   1      real_no_add_chg = TRUE;
 309   1      
 310   1      /* Reset the User und DPS;复位User和DPS */
 311   1      user_dps_reset();                /* .U */
 312   1      
 313   1      
 314   1      /* Enable the SPC3 interrupt in the interupt controller of the microprocessor */
 315   1      #if defined __C51__                      /* 中断使能 */
 316   1        SPC3_INTERRUPT_ENABLE = I_ENABLE;
 317   1        GLOBAL_INTERRUPT_ENABLE = I_ENABLE;
 318   1      #elif _C166
                CC11IE = 1;
              #endif
 321   1      
 322   1      
 323   1      
 324   1      for (;;)
 325   1              {   /*=== Begin  of the endless loop ===*/
 326   2              zyk_wd_state = SPC3_GET_WD_STATE();    /*for info.: the actuall WD State;zyk_wd_state全局变量*/
 327   2                                                   /*读Status Register中WD_STATE状态位 , .P1;PDF22 */
 328   2              zyk_dps_state = DPS2_GET_DP_STATE();   /*for info.: the actuall PROFIBUS DP State*/
 329   2                                                   /*读Status Register中DP_STATE状态位 , .P1 */
 330   2      
 331   2              DPS2_RESET_USER_WD();           /* Trigger the user watchdog of the SPC3;重触发SPC3的WD */
 332   2                                                          /*  即 spc3.x1.w.mode_reg1_s = RES_USER_WD */
 333   2      #ifdef __C51__
 334   2              HW_WATCHDOG_TRIGGER = 1;    /* Retrigger the HW Watchdog of the IM183;重触发IM183硬件狗 */
 335   2              HW_WATCHDOG_TRIGGER = 0;    /* 已定义 sbit  HW_WATCHDOG_TRIGGER = P1^0 */
 336   2      #endif
 337   2      
 338   2      /*======Handling of the output  data;output  data处理输出数据=========*/
 339   2                                        /* .Hp8; DPS2_POLL_IND_DX_OUT()即spc3.int_req.b[_IMH] & DX_OUT_B;00H */
 340   2              if (DPS2_POLL_IND_DX_OUT()) /* are new output date available? *见PDF77;SPC3接收到读写数据报文且新的输出数
             -据已在N buffer里。在'Power_On'和'Leave_Master'状态清楚SPC3 的 N buffer同时也产生这个中断*/
 341   2                      {                       /* Confirm the receiving */
 342   3                      DPS2_CON_IND_DX_OUT(); /*DPS2_CON_IND_DX_OUT()即spc3.int_reg.ack.b[_IMH] = (UBYTE)DX_OUT_B;写*/
 343   3      
 344   3                      /* Get the pointer to the actual output data;获得实际输出数据的指针 */
 345   3             user_output_buffer_ptr = DPS2_OUTPUT_UPDATE();/*即获得用于存输出数据的buf的实际指针;见PDF79  .Cp9 *
             -/
 346   3      
 347   3      
 348   3                      /* Example: Copy the output data to the IO;例:把新数据拷到io_byte_ptr所指区 */
 349   3                      for (i=0; i<user_io_data_len_ptr->outp_data_len; i++)
 350   3                         {
 351   4                         (*((io_byte_ptr) + i)) = (*(((UBYTE SPC3_PTR_ATTR*) user_output_buffer_ptr) + i));
 352   4                         }
 353   3       TEST_flag=RL_flag;/*$*/
 354   3       TEST_flag=RL_flag;
 355   3      
 356   3      if(TEST_flag==0x75)
 357   3               {
 358   4      o_byte_ptr=((UBYTE*)0x22C00L) ; /*$*/
 359   4      
 360   4      for (i=0; i<user_io_data_len_ptr->outp_data_len; i++)
 361   4                         {
 362   5                         (*((o_byte_ptr) + i)) = (*(((UBYTE SPC3_PTR_ATTR*) user_output_buffer_ptr) + i));
 363   5                         }
C51 COMPILER V7.02b   USERSPC3_0810                                                        11/01/2004 20:51:05 PAGE 7   

 364   4       
 365   4      RL_flag=0x57;/*$*/
 366   4      RL_flag=0x57;
 367   4      
 368   4               }
 369   3                  }                              /* io_byte_ptr为IO区指针 */
 370   2      
 371   2      /*========== Handling of the input data;input data处理输入数据============*/
 372   2      
 373   2      /* Write the input data from the periphery to the ASIC */
 374   2       TEST_flag=LR_flag;/*$*/
 375   2       TEST_flag=LR_flag;
 376   2      
 377   2      if(TEST_flag==0x12)
 378   2      {
 379   3      i_byte_ptr=((UBYTE*)0x22800L); /*$*/
 380   3              for (i=0; i<user_io_data_len_ptr->inp_data_len; i++)
 381   3                      {
 382   4                      *(((UBYTE SPC3_PTR_ATTR*) user_input_buffer_ptr) + i) = *((i_byte_ptr) + i);
 383   4                      }                                   /* user_input_buffer_ptr为全局XDATA变量 */
 384   3      for (i=0; i<user_io_data_len_ptr->inp_data_len; i++)
 385   3                      {
 386   4                      *(((UBYTE SPC3_PTR_ATTR*) user_input_buffer_ptr) + i) = *((i_byte_ptr) + i);
 387   4                      }          
 388   3              user_input_buffer_ptr = DPS2_INPUT_UPDATE();/*写完后更新指针P1定下个数据用哪个BUFFER*/
 389   3         
 390   3      LR_flag=0x21;/*$*/
 391   3      LR_flag=0x21;
 392   3      
 393   3          }
 394   2              
 395   2      
 396   2      
 397   2      /*== Handling of the external diagnosis and other user defined actions 处理外部诊断和其它用户功能=====*/
 398   2      /* ATTENTION注意: 这仅是一个例子     this is only an example          */
 399   2      
 400   2      /* Use the first Byte of the Input data as a service byte;使用Input data第一字节为服务字节*/
 401   2      /*  for the change diag function;WHp49 */
 402   2      
 403   2              dps_chg_diag_srvc_byte_new = *((UBYTE*)(io_byte_ptr));
 404   2      
 405   2              if (user_diag_flag) /* is a diagnosis buffer available? 全局变量user_diag_flag */
 406   2                      {
 407   3                      /* Is there a change in the service byte (1.input byte) */
 408   3                      if (dps_chg_diag_srvc_byte_new == dps_chg_diag_srvc_byte_old)
 409   3                              {
 410   4                               /* no action */
 411   4                               }
 412   3                      else
 413   3                              {
 414   4                              /*== Handling of the external diagnosis  =====*/
 415   4                              /* only the least significant 3 byte are used PDF35*/
 416   4                              if ((dps_chg_diag_srvc_byte_new & 0x07) !=
 417   4                                        (dps_chg_diag_srvc_byte_old & 0x07))
 418   4                                      {
 419   5                                      /* Mask过滤the 3 bits ; 全局变量diag_service_code */
 420   5                                      diag_service_code = dps_chg_diag_srvc_byte_new & 0x07;
 421   5                                 
 422   5                                      /* Write the length of the diagnosis data to the SPC3;见PDF35 */
 423   5                                      if (dps_chg_diag_srvc_byte_new & 0x01)
 424   5                                              diag_len = 16;   /* max. value of the IM308B */
 425   5                                      else
C51 COMPILER V7.02b   USERSPC3_0810                                                        11/01/2004 20:51:05 PAGE 8   

 426   5                                              diag_len = 6;     /* 最少是六位,见PDF35  */
 427   5      
 428   5                                      diag_len = DPS2_SET_DIAG_LEN(diag_len);/* 确定诊断字节长度;Hp9 */ 
 429   5      

⌨️ 快捷键说明

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