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

📄 rs485_51device._c

📁 电梯楼层采集器代码
💻 _C
字号:

#include"include.h"

//------------------------------------------------------------------------------
//获取51板的时间
void get_Device51_TIME(void)
{
 struct Device51_StructOfProtocol *C51_buf;
 struct data *communication;
 *Buffer485 = *C51Buffer485;
 C51_buf = (struct Device51_StructOfProtocol *)C51Buffer485;
 if(C51_buf->Length ==5)
 {//发送时间给PC
  	DayOfTime = ((unsigned int)C51_buf->Data[0] << 8) | C51_buf->Data[1];
 	SecondOfTime = ((unsigned int)C51_buf->Data[2] << 8) | C51_buf->Data[3];
 	communication->pc_txd = 1; 
  	Cyc_manage |= 0x01;
 }
}
//------------------------------------------------------------------------------
//取控制器历史事件
void get_Device51_EVENT(void)
{




}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//与51控制板进行通讯 
void communication_with_51director(void)
{
  unsigned char i;
  struct Device51_StructOfProtocol *C51_buf;
  struct Device51_Address *Device51; 
  struct data *communication;
  C51_buf = (struct Device51_StructOfProtocol *)C51Buffer485;
  if(communication->c51_txd)
  {//发送数据给51控制板 
  	communication->c51_txd = 0; 
	for(i=0;i<sizeof(struct ReadHC165Switch);i++)
	{
		C51_buf->Address = Device51->Address[i];
		BUS_SendPacket_51Device();//发送数据给51板
	}
  }
  if(communication->c51_rxd)
  {//接收51控制板发送过来的数据
    communication->c51_rxd = 0;  
	if(!BUS_GetPacket_51Device())
	{
     	for(i=0;i<sizeof(struct ReadHC165Switch);i++)
  		{  
       	   if((C51_buf->Address==Device51->Address[i])||(C51_buf->Address == 0xff))
	   	   { 
       	   	 	switch(C51_buf->Command)
	  	 		{
	      		 	case CMD_GET_TIME://获取C51控制板的时间
		 	  	 		 get_Device51_TIME();
			  	 		 break;
	     			case CMD_GET_EVENT://取控制器历史事件
		 	 	 		 get_Device51_EVENT();
			 	 		 break;
	     			default:
				 		 break;
	  	 	    }
           }
	    }
	}
  }
}
//------------------------------------------------------------------------------
//******************************************************************************
//------------------------------------------------------------------------------
//下载系统时间
void set_Device51_TIME(void)
{
  struct Device51_StructOfProtocol *C51_buf;
  struct data *communication;
  C51_buf = (struct Device51_StructOfProtocol*)C51Buffer485;
  C51_buf->Data[0] = DayOfTime >> 8;
  C51_buf->Data[1] = DayOfTime;
  C51_buf->Data[2] = SecondOfTime >> 8;
  C51_buf->Data[3] = SecondOfTime;
  C51_buf->Length = 5; 
  communication->c51_txd = 1; 
  Cyc_manage |= 0x02;	
}
//------------------------------------------------------------------------------
//下载系统卡注册表
void set_Device51_CARDSET(void)
{
  unsigned int point,count;
  struct Device51_StructOfProtocol *C51_buf;
  struct data *communication;
  C51_buf = (struct Device51_StructOfProtocol*)C51Buffer485;  
  point = *(unsigned int *)C51_buf->Data;
  if (point < sizeof(struct StructOfRegister))
  {//发送系统卡注册表给51控制板
  	count = sizeof(struct StructOfRegister) - point;
    if (count < 256 - 8) C51_buf->Length = count + 1;
    else  C51_buf->Length = 256 - 8;
	point += CARDSET_Address;
  	AT24_Read((unsigned char *)&C51_buf->Data,point,C51_buf->Length-1);
	I2C_Close();
  	communication->c51_txd = 1; 
	Cyc_manage |= 0x02;	
  }
}
//------------------------------------------------------------------------------
//下载门禁时间组(设用户楼层授权资料) 
void set_Device51_USER(void)
{
  unsigned int point,count;
  struct Device51_StructOfProtocol *C51_buf;
  struct data *communication;
  C51_buf = (struct Device51_StructOfProtocol*)C51Buffer485;
  point = *(unsigned int *)C51_buf->Data;
  if (point < sizeof(struct StructOfUserInformation))
  {//发送用户楼层授权资料给51控制板
  	count = sizeof(struct StructOfUserInformation) - point;
    if (count < 256 - 8) C51_buf->Length = count + 1;
    else  C51_buf->Length = 256 - 8;
	point += USER_INFORMATION_Address;
  	AT24_Read((unsigned char *)&C51_buf->Data,point,C51_buf->Length-1);
	I2C_Close(); 
  	communication->c51_txd = 1; 
	Cyc_manage |= 0x02;	
  }
}
//------------------------------------------------------------------------------
//设用户时间组授权资料 
void set_Device51_USER_TIME(void)
{
  unsigned int point,count;
  struct Device51_StructOfProtocol *C51_buf;
  struct data *communication;
  C51_buf = (struct Device51_StructOfProtocol*)C51Buffer485;
  point = *(unsigned int *)C51_buf->Data;
  if(point <sizeof(struct StructOfUserTimezone))
  {//发送用户时间组授权资料给51控制板
    count = sizeof(struct StructOfUserTimezone) - point ;
	if (count < 256 - 8) C51_buf->Length = count + 1;
    else  C51_buf->Length = 256 - 8;
	point += USER_TIMEZONE_Address;
	AT24_Read((unsigned char *)&C51_buf->Data,point,C51_buf->Length-1);
	I2C_Close();
  	communication->c51_txd = 1; 
	Cyc_manage |= 0x02;	
  }
}
//------------------------------------------------------------------------------
//设电梯授权时间组  
void set_Device51_AUTH_TIME(void)
{
  unsigned int point,count;
  struct Device51_StructOfProtocol *C51_buf;
  struct data *communication;
  C51_buf = (struct Device51_StructOfProtocol*)C51Buffer485;
  point = *(unsigned int *)C51_buf->Data;
  if(point <sizeof(struct StructOfLiftSchedule))
  {//发送电梯授权时间组给51控制板
   count = sizeof(struct StructOfLiftSchedule) - point;
   if (count < 256 - 8) C51_buf->Length = count + 1;
   else  C51_buf->Length = 256 - 8;
   point += LIFT_SCHEDULE_Address;
   AT24_Read((unsigned char *)&C51_buf->Data,point,C51_buf->Length-1);
   I2C_Close();
   communication->c51_txd = 1; 
   Cyc_manage |= 0x02;	
  }
}
//------------------------------------------------------------------------------
/*设置系统配置参数*/
void set_Device51_CONFIG(void)
{
  struct Device51_StructOfProtocol *C51_buf;
  struct data *communication;
  C51_buf = (struct Device51_StructOfProtocol*)C51Buffer485;
  C51_buf->Length = sizeof(SystemConfig) + 1;
  AT24_Read((unsigned char *)&C51_buf->Data,SystemConfig_Address,C51_buf->Length-1);
  I2C_Close();
  communication->c51_txd = 1; 
  Cyc_manage |= 0x02;	
}
//------------------------------------------------------------------------------
//设置产品标签代码 
void set_Device51_PRODUCT_CODE(void)
{
  struct Device51_StructOfProtocol *C51_buf;
  struct data *communication;
  C51_buf = (struct Device51_StructOfProtocol*)C51Buffer485;
  C51_buf->Length = sizeof(struct StructOfProductCode) + 1;
  AT24_Read((unsigned char *)&C51_buf->Data,StructOfProductCode_Address,C51_buf->Length-1);
  I2C_Close();
  communication->c51_txd = 1; 
  Cyc_manage |= 0x02;	
}
//------------------------------------------------------------------------------
/*设置控制器状态*/
void set_Device51_UNIT_STATUS(void)
{


}


//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//更新51控制板
void update_data_51director(void)
{
  unsigned char i;
  struct Device51_StructOfProtocol *C51_buf;
  struct Device51_Address *Device51; 
  C51_buf = (struct Device51_StructOfProtocol*)C51Buffer485;
  for(i=0;i<sizeof(struct ReadHC165Switch);i++)
  {  
   C51_buf->Address = Device51->Address[i]; 
   switch(C51_buf->Command)
   {
   	 case CMD_SET_TIME://下载系统时间
	 	  set_Device51_TIME();
		  break;
   	 case CMD_SET_CARDSET://下载系统卡注册表
	      set_Device51_CARDSET();
		  break;
	 case CMD_SET_USER://下载门禁时间组(设用户楼层授权资料)  	   
   	 	  set_Device51_USER();
		  break;
     case CMD_SET_USER_TIME://设用户时间组授权资料 
	 	  set_Device51_USER_TIME();
		  break; 
	 case CMD_SET_AUTH_TIME://设电梯授权时间组  
		  set_Device51_AUTH_TIME();
		  break;
	 case CMD_SET_CONFIG: //设置系统配置参数  
		  set_Device51_CONFIG();
		  break; 
	 case CMD_SET_PRODUCT_CODE://设置产品标签代码  
	 	  set_Device51_PRODUCT_CODE();
		  break;
	 case CTL_SET_UNIT_STATUS: /*设置控制器状态*/	 
		  set_Device51_UNIT_STATUS();
		  break;
	 default:
	 	  break;
   }
  }
}
//------------------------------------------------------------------------------

⌨️ 快捷键说明

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