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

📄 ytep_rf.c.bak

📁 完成数据的采集
💻 BAK
字号:
//******************************************
#include"ytep.h"
#include"ytepfunction.h"
#define  ytep_RF_file

Int32U IsrReceive(REC *Re)
{
	static _ReSend IR;
  Boolean IO_RFRX=1;
	if((Re->B_Send!=0)||Re->Flag!=0)
        {
          IR.sys=0,IR.low=0;
          return 0;
        }
	if((IO_RFIn1&B_RFIn1)==0)IO_RFRX=0;
	if((IO_RFIn2&B_RFIn2)==0)IO_RFRX=0;	
	if((IO_RFIn3&B_RFIn3)==0)IO_RFRX=0;
  if((IO_RFIn4&B_RFIn4)==0)IO_RFRX=0;
	Clr_bit(IO_RFCTL,B_RFCTL);
	if(IR.sys==0&&IO_RFRX!=0)
	{
		if(IR.low>=30)
                IR.sys=1,IR.REG=0,IR.loop=0,IR.counter=0;
		IR.low=0,IR.high=0;
	}
	if(IO_RFRX==0&&IR.sys==0)IR.low++; 
	if(IO_RFRX==0&&IR.sys!=0)
	{
		if(IR.B_high!=0)
		 {
				IR.B_high=0,IR.REG<<=1;
				if(IR.high>=8)
                                 IR.REG|=1;
				if(++IR.counter>=8)
				{
					Re->Rec8U[IR.loop]=IR.REG;
					IR.loop++;
                                        IR.counter=0;
				} 
			  IR.low=IR.high=0;	
		 }else if(++IR.low>=20)IR.sys=0;	
	}
	if(IO_RFRX!=0&&IR.sys!=0)
	{
		IR.B_high=1;
	 if(++IR.high>=30||IR.loop>=7)
          IR.sys=0,Re->Flag=1;
	 
	}
	return 0;
}
//////////////////////////////////////////

Int32U		IsrSend(REC *Re)
{
	static _ReSend IS;
	Int16U Sa;
	if(Re->B_Send==0)
	{
		IS.sys=IS.counter=0;
		return  0;
	}
	Set_bit(IO_RFCTL,B_RFCTL);
	if(IS.sys==0)
	{
			if(IS.counter<=3)Set_bit(IO_RFTX,B_RFTX);
			else                Clr_bit(IO_RFTX,B_RFTX);
			
			if(++IS.counter>=43)IS.sys=1,IS.loop=IS.counter=0;
			return 0;
	}
	if(IS.sys!=0)
	{
		if((IS.loop&1)==0)
		{
			Set_bit(IO_RFTX,B_RFTX);
			
			if(Re->SendChannel&0x8)Sa=C_asyn_H;
			else									  Sa=C_asyn_L;
			if(IS.loop>=8)Sa=1;
			if(++IS.counter>=Sa)
				{
					IS.counter=0;
					IS.loop++;
					Re->SendChannel<<=1;
				}	
		}else
		{
			Clr_bit(IO_RFTX,B_RFTX);	
			if(++IS.counter>=C_asyn_L)IS.loop++,IS.counter=0;
			if(IS.loop>=9)Set_bit(IO_RFTX,B_RFTX),Re->B_Send=Re->Flag=0;
					
		}
	}
	return 0;
}
//////////////////////////////////////////////
//////////////////////////////////
/*CHK_RF(&RF,YT->Sensor);*///5ms
/************************************/
Int32U CHK_RF(REC *p,SensorRF *pos)
{
	volatile Int8U  a,b;
	Int16U crc_data;
  static Int8U   Timcount;
	static Int8U	 RF_error[5]={0,0,0,0,0};	
	
	 if(++Timcount<4)return 0;
	 Timcount=0;
	if(p->channel>=4)p->channel=0;		
	if(p->Flag!=0)
 {
		crc_data=cal_crc(&p->Rec8U[0],6);
  	crc_data=crc_data&0xff;    //??????????? 
        a=(p->channel)&0x03;	
  	b=p->Rec8U[0]>>6;
       
  	 if(a==b&&crc_data==p->Rec8U[6])
    {
   	 RF_error[p->channel]=0;
   	 pos+=p->channel;
   	 pos->ATem=p->Rec8U[2];
		 pos->AVol=p->Rec8U[0]&0XF;
		 if((p->Rec8U[0]&0x20))pos->AVol+=21;
		 pos->BTem=p->Rec8U[3];
		 pos->BVol=p->Rec8U[1]>>4;
		 if((p->Rec8U[0]&0x20))pos->BVol+=21;
		 pos->CTem=p->Rec8U[4];
		 pos->CVol=p->Rec8U[1]&0XF;
		 if((p->Rec8U[0]&0x20))pos->CVol+=21;
    }
  	 p->Flag=FALSE;
	}
			
		if(++RF_error[p->channel]>=5)
		{
			pos+=p->channel;
			pos->ATem=0xFF;
			pos->AVol=0xFF;
			pos->BTem=0XFF;
			pos->BVol=0xFF;
			pos->CTem=0XFF;
			pos->CVol=0xFF;
		}
		 if(++(p->channel)>=4)p->channel=0;
		 a=(p->channel)<<2,b=(p->channel)^0x03;
 	   p->SendChannel=a|b;
     p->B_Send=TRUE,p->Flag=FALSE;;   		
		 Set_bit(IO_RFCTL,B_RFCTL);
	return 0;  	
}
//////////////////////////////////////////////
//////////////////////////////////////////////
//////////////////////////////////////////////
Int16U cal_crc(Int8U *ptr, Int8U len)
{
  Int16U crc=0xffff;
  Int8U  i;
  while(len!=0)
  {
    crc^=*ptr;
    for(i=0;i<8;i++)
    {
     if((crc&0x0001)==0) crc=crc>>1;
     else
     {
                crc=crc>>1;
                crc^=0xA001;
     }
    }
    len-=1,ptr++;          		
  }
    return crc;
}	
	























⌨️ 快捷键说明

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