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

📄 userspc3.c

📁 使用8052单片机控制SPC3总线桥实现PROFIBUS-DP现场总线的从站部分C程序源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
+------------------------------------------------------------------------+
| Project: D P S 2   w i t h   S P C 3                                   |
|                                                                        |
| File:   DPS2SPC3.C                                                     |
| Date:   27-Sep-2007                                                    |
| Version: V 1.17                                                        |
| Initial Editor:   Thomas Lang   Final Editor:  Wujiang Zhang           |
+------------------------------------------------------------------------+
| Description:                                                           |
|     This module contains the main routine and some supporting          |
|     routines.                                                          |
|                                                                        |
|     In this example the input and output bytes are transfered to the   |
|      IO area, which is addressed by the io_byte_ptr.                   |
|     In the case of the IM183-1 there is RAM.                           |
|     The first byte of the input data is used as a service byte         |
|      for the change diag function.                                     |
|     The received user parameter data were copied to an interim buffer  |
|      and from this to the user diagnosis data.                         |
+------------------------------------------------------------------------+
| following environments are supported                                   |
|  Processor: SAB C165                                                   |
|   Compiler: BSO Tasking 80166 C Cross-Compiler, V 4.0                  |
|  Processor: iNTEL 8032                                                 |
|   Compiler: Keil                                                       |
|                                                                        |
|                                                                        |
+------------------------------------------------------------------------+
|                    Copyright (C) SIEMENS AG, 1994                      |
|                         All Rights reserved                            |
+------------------------------------------------------------------------+
| History:																 |
| V0.9,SX,24-Oct-1995, Pilot verion                                      |
| V1.0,SX,02-Nov-1995, 1st version                                       |
| V1.1,SX,09-Nov-1995, Delete RAM from 0x16H, not from 16d               |
|                       no initialization of the interrupt 1 level/egde  |
| V1.2,SX,05-Aug-1996, changes for Keil-C51 V5                           |
| V1.2,SX,09-Aug-1996, IM182 support added                               |
| V1.3,MM,25-Mar-1997, IM182 support extracted                           |
|                                                                        |
+------------------------------------------------------------------------+
| Technical support:       Siemens Schnittstellencenter                  |
|                          AUT7 WKF B1 TDL2                              |
|                                                                        |
|   Schmidt Xaver                   Mittelberger Martin                  |
|   Tel.: 0911/750-2079             Tel.: 0911/750-2072                  |
|                                                                        |
|                   Fax.:         -2100                                  |
|                   Mailbox: 0911/737972                                 |
|                                                                        |
+------------------------------------------------------------------------+
*/

#define SPC3_INTEL_MODE         TRUE
#define SPC3_FAR

#define SPC3_DPS2
#define SPC3_DATA_XDATA



#include "spc3dps2.h"

#if defined __C51__

	#include <reg52.h>

	#define huge
	#define global
	#define public

	/* Defines for the IM183-1 */
	sbit  HW_WATCHDOG_TRIGGER = P1^0;   /* trigger input of the HW-WD   */
	sbit  SPC3_RESET = P3^4;            /* SPC3-reset-Pin               */
	#define SPC3_RESET_SET 1            /* reset-polarity               */
	#define SPC3_INTERRUPT_ENABLE  EX0  /* external interrupt of SPC3   */
	#define I_ENABLE 1                  /* enable interrupt             */
	#define SPC3_INTERRUPT_PRIOR   PX0  /* ext Interrupt SPC3 polarity  */
	#define P_HIGH  1                   /* ext Interrupt SPC3 prio high */
	#define GLOBAL_INTERRUPT_ENABLE EA  /* global interrupt             */

#elif	_C166
	/* C166 */
	#include "reg.h"

	#pragma global
	#pragma class hb=SPC3_CLASS
	#pragma default_attributes
	#pragma public
	#pragma class hb=DIN_CLASS
	#pragma default_attributes

#endif


/*----------------------------------------------------------------------*/
/*                       STRUCTURES AND TYPEDEFS                        */
/*----------------------------------------------------------------------*/

/* This is an example for a structure of a diagnosis with user data */
struct  diag_data_blk
  {
  UBYTE                               stationstatus_1;
  UBYTE                               stationstatus_2;
  UBYTE                               stationstatus_3;
  UBYTE                               master_add;
  UBYTE                               ident_high;
  UBYTE                               ident_low;

  /*------------------ extern diag data  -----------------*/
  UBYTE                               header;
  UBYTE                               ext_diag_0;
  UBYTE                               ext_diag_1;
  UBYTE                               ext_diag_2;
  UBYTE                               ext_diag_3;
  UBYTE                               ext_diag_4;
  UBYTE                               ext_diag_5;
  UBYTE                               ext_diag_6;
  UBYTE                               ext_diag_7;
  UBYTE                               ext_diag_8;
  UBYTE                               ext_diag_9;
  UBYTE                               ext_diag_10;
  UBYTE                               ext_diag_11;
  UBYTE                               ext_diag_12;
  UBYTE                               ext_diag_13;
  UBYTE                               ext_diag_14;
  UBYTE                               ext_diag_15;
  UBYTE                               ext_diag_16;
  UBYTE                               ext_diag_17;
  };

enum ERRORCODES {IO_LENGTH_ERROR,INIT_ERROR,UNUSED};

/*----------------------------------------------------------------------*/
/*                       EXTERNAL FUNCTIONS                             */
/*----------------------------------------------------------------------*/

/*----------------------------------------------------------------------*/
/*                       INTERNAL FUNCTIONS                             */
/*----------------------------------------------------------------------*/
void main (void);
void user_dps_reset (void);
void build_diag_data_blk (struct diag_data_blk*);
void user_error_function (enum ERRORCODES);
/*----------------------------------------------------------------------*/
/*                       LITERALS                                       */
/*----------------------------------------------------------------------*/

#define TSDRMIN                 11

#define OWN_ADDRESS             3
#define IDENT_HIGH              0x00
#define IDENT_LOW               0x08


#define DPS2_DISI()             IEN = 0
#define DPS2_ENI()              IEN = 1

#define CFG_LEN                 2
#define CONFIG_DATA_INP         0x13
#define CONFIG_DATA_OUTP        0x23


/*----------------------------------------------------------------------*/
/*                       MACROS                                         */
/*----------------------------------------------------------------------*/

/*----------------------------------------------------------------------*/
/*                       GLOBAL VARIABLES                               */
/*----------------------------------------------------------------------*/

#pragma global

UBYTE                   real_no_add_chg;
UBYTE                   this_station;
UBYTE                   cfg_akt [20];
UBYTE                   cfg_len_akt;
DPS2_IO_DATA_LEN SPC3_PTR_ATTR  *user_io_data_len_ptr;
#pragma public

struct diag_data_blk    *diag_ptr;
DPS2_BUFINIT            dps2_buf;

UBYTE   SPC3_PTR_ATTR   *user_output_buffer_ptr;

UBYTE   SPC3_PTR_ATTR   *user_input_buffer_ptr;
UBYTE   SPC3_PTR_ATTR   *real_config_data_ptr;
void    SPC3_PTR_ATTR   *user_diag_buffer_ptr;

UBYTE                   ident_numb_high;
UBYTE                   ident_numb_low;
UBYTE                   dps_chg_diag_srvc_byte_new;
UBYTE                   dps_chg_diag_srvc_byte_old;
UBYTE                   diag_service_code;
UBYTE                   diag_len;
UWORD                   user_baud_value;
UBYTE                   user_diag_flag;
UBYTE                   *io_byte_ptr;
UBYTE                   i;
UBYTE                   zyk_wd_state;
UBYTE                   zyk_dps_state;
UBYTE                   prm_tst_buf[32]= {0,0,0,0,0,0,0,0,0,0,
											0,0,0,0,0,0,0,0,0,0,
											0,0,0,0,0,0,0,0,0,0,0,0};
enum ERRORCODES error_code;

/* Locate the structure of the SPC3 in the address space               */

SPC3 xdata spc3 _at_ 0x1000;


/************************************************************************/
/*  D e s c r i p t i o n :                                             */
/*                                                                      */
/*  USER-TASK                                                           */
/************************************************************************/


void    main ()
{

#if defined __C51__
	UBYTE xdata * xdata loesch;
	UWORD zaehl;

	SPC3_RESET = SPC3_RESET_SET;        /* force the Reset Pin          */
	for(i = 100; i ; i--);
	SPC3_RESET = !SPC3_RESET_SET;

	HW_WATCHDOG_TRIGGER = 1;            /* Retrigger the HW Watchdog    */
	HW_WATCHDOG_TRIGGER = 0;

	SPC3_INTERRUPT_ENABLE = !I_ENABLE;  /* Set the interrupt parameters */
	SPC3_INTERRUPT_PRIOR = P_HIGH;      /* of the microprocessor        */

	loesch = &spc3.int_req.b[0];        /* Delete the SPC3 internal RAM */
	for (zaehl=0x16; zaehl<=0x05ff; zaehl++)
		{
		*(loesch + zaehl) = 00;
		}

#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


/* activate the indication functions */
SPC3_SET_IND(GO_LEAVE_DATA_EX | WD_DP_MODE_TIMEOUT | NEW_GC_COMMAND |\
			   NEW_SSA_DATA | NEW_CFG_DATA | NEW_PRM_DATA | BAUDRATE_DETECT);

/* set the watchdog value in the SPC3, which checks the microprocessor */
DPS2_SET_USER_WD_VALUE(20000);


/* In this example the input and output bytes are transfered to the
   IO area, which is addressed by the io_byte_ptr. In the case of the IM183
   there is RAM. */


	io_byte_ptr = ((UBYTE*) 0x2E000L);

for (i=0; i<2; i++)
	{
	(*(io_byte_ptr + i)) = 0;
	}

/* fetch the station address, in this case the station address
   is fixed in EPROM*/
this_station = OWN_ADDRESS;

/* get the Identnumber    */
ident_numb_high = IDENT_HIGH;
ident_numb_low =  IDENT_LOW;

/* Allow not the change of the slave address by the PROFIBUS DP      */
/* Attention: The set_slave_address service is not blocked by this */
real_no_add_chg = TRUE;


⌨️ 快捷键说明

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