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

📄 bakeup.#1

📁 采用无线收发模块at86rf211的一个程序开发包,单片机采用Cygnal 8051F015,希望能对您有所帮助
💻 #1
字号:
//---------------------------------------------------------------------------//
//   接收数据信息包                                                          //
//---------------------------------------------------------------------------//
unsigned char   Receive_Information_Package()
{     
     unsigned char r_count=0;
	 unsigned char count  =0;
	 unsigned char sample_number=0;
	 unsigned char first=0;
	 unsigned char sencond=0;
	 unsigned char r_timers=0;	  
	 
	 timer0_count=0;
	 while(count<34)
	   {
	                														//在1ms中检测datamsg有无高电平到来
																			//如果检测到datamsg的高电平,则退出循环
		if (timer0_count<10)                                                 
		{
		    if (DATAMSG==1)                                                 //如果在其间检测到DATAMSG的高电平,则计数变量加1.
			 {
			    r_count++;
				//if(r_count>=100)break;                                    //如果连续监测到DATAMSG保持为高电平的时间为65us,则表明为有效的信号。    
			 }
			 else r_count=0;                                                //否则,计数变量清0
		}       
        else
		{ 
		   count++;                                                         //否则在1ms中内没有检测到高电平,则循环计数变量加1
	       if (r_count>=10000) break;                                       
		 }
	   }	     

       if (count>=34)  return(0x00);                                        //如果在100us*10*34=34ms中之内datamsg一直为低电平,则返回接收失败信息0x00
       else                                                                 //否则表明在其间检测到有效的datamsg信号,即找到了datamsg=1;接下来需要找datamsg为0的有效信号
    	{
	      timer0_count=0;
		  count=0;
		  while(1)
		  {
		   if(timer0_count<15)                                              //如果15*100=1.5ms之内,执行下面的过程
		   {
		        if (DATAMSG==0)                                             //查找DATAMSG=0
				{
				    count++;
					if (count>=40) break;                                   //连续采集40次(--21us)
				}
				else count=0;                                               //只要datamsg=1,则计数变量清0
		   }
           else break;                                                      //否则,退出循环,进入外围循环。
		  }     
		if (count>=40)                                                      //如果采集到有效的datamsg=0信号
		{
		     if(timer0_count>=7)                                            //如果timer0_count>0.7ms,则表明低电平信号有效
			 {
			       timer0_count=0;                                          //定时计数器清0
				   count=9;                                                 //开始数据接收
                   			
                   while(count<9)
				   {
			          wait_time_100us();                                    //等待100us    	 	  	       
				      timer0_count=0;
					  r_count=0;
					  
					  while(sample_number<8)
					  {
					    //采样8次
					    if (datamsg==0) r_count++;
					  }
                      first=r_count;
					  wait_time_100us();                                    //等待100us    	 	  	        
					  timer0_count=0;
					  r_count=0;
					  while(sample_number<8)
					  {
					                                                        //采样8次
					    if (datamsg==0) r_count++;
					  }
                     
					 sencond=r_count;
                      
				   }
			 }    
		}	
	}
  }
}

//-----------------------------------2003-12-10日备份-------------------------------------//

//---------------------------------------------------------------------------//
//   接收数据信息包                                                          //
//---------------------------------------------------------------------------//
unsigned char   Receive_Information_Package()
{     
     unsigned char r_count=0;
	 unsigned int count  =0;
	 unsigned char start_flag=0;
	 unsigned char ch_numbers=0;
     unsigned char b_bits=0;
	 unsigned char nCh=0;
     unsigned int  inde=0;

	 timer0_count=0;
	 start_flag=0;
     
	 Read_Wakeup_Data();  
     Make_Receive_Mode();
     
	 RFLAG=0;

	  while(count<400)
	  {
	    if (timer0_count<=10)
		{
			if (DATAMSG==1)              						       //在1ms中检测datamsg有无高电平到来
	        {
			  level_count=0;

	          DATACLK =1;
			  //如果datamsg为高电平,则最多等待1.5ms,判断是否为数据的头标志
			  while(DATAMSG==1)                                                              
		      {
		         if (level_count>8) break;
		      }
                   
               //如果在还没有到1ms的时间内,就跳变为0,则表示不是有用的起始信号,也就是说起始信号必须至少要大于等于1ms的高电平
			   if ((level_count>8)&&(level_count<=15))
			   {
			      /*if (DATAMSG==0) 
				  {
				    start_flag=1;
				    break; 
				  }
				  level_count=0;
				 */     
				 
				 DATACLK=0;
				// wait_time_100us();                                         //找到合适的信号。        
				level_count=0;
				while(DATAMSG==1)                                             //等待下降沿的到来                                                       
		        {
		          if (level_count>=1) break;
		        }
            
				 if(level_count<=1)
				 { start_flag=1;                    
				   DATACLK=1;
				 }
				 //break;
			    }
		     }
			 else 
			 {
			   level_count=0;
			 }
		}
		else 
		  {
		     count++;
			 timer0_count=0;
			 level_count=0;
		   }
	  }

	  //如果找到合适的起始信号
	  //即在合适的时间内找到了有效的下降沿
	  /*
	  if (start_flag)
	  {
	     wait_time_100us();                                              //等待100us      
         ch_numbers=10;                                                  //接收10个字节
         while(ch_numbers--)                                             //开始接收10个字节
		 {
    		 wait_time_100us();                                          //等待100us      
             timer0_count=0;
		     		  	
             b_bits = 8;
			 while(b_bits--)
			 {
			   if (DATAMSG==1)                                           //如果datamsg=1,表明实际的值为0。
			    {
				  while(DATAMSG==1)
                  {
                      if (timer0_count>1) break;                         //等待100us,如果低电平还没到来,则强行退出			
				  }
				  //_nop_();
				  DATACLK=0;
                  //wait_time_100us();                                   //等待100us      
                  while(DATAMSG==0)
                  {
                      if (timer0_count>1) break;                         //等待100us,如果低电平还没到来,则强行退出			
				  }
   	     		  if (timer0_count<=1)                                   //如果有下降沿产生
				  {
				    nCh = nCh|0x00;
				    nCh = nCh<<1;
					timer0_count=0;
					DATACLK=0;
				  }
				  
                 }
		         else if (DATAMSG==0)
				 {
				    while(DATAMSG==1)
                    {
                      if (timer0_count>1) break;       		
				    }  
					_nop_();
					//DATACLK=1;
                    wait_time_100us();                                   //等待100us      
					while(DATAMSG==0)
                    {
                      if (timer0_count>1) break;                         //等待100us,如果低电平还没到来,则强行退出			
				    }
					if (timer0_count<2)                                  //如果有上升沿产生
					 {
					   nCh = nCh|0x01;
				       nCh = nCh<<1;
					   timer0_count=0;
					   DATACLK=1;
                     }
				  }              
			 } //end while(b_bits--)
            
			INPUT_BUF[inde++] = nCh;	
         } //end  while(ch_numbers--)                                    //开始接收10个字节
		 _nop_();
		 _nop_();
		 for(inde=0;inde<100;inde++)
	     INPUT_BUF[inde]=0;
		 _nop_();
      } //end if (start_flag)
	  
      timer0_count=0;
      while(timer0_count<=400);
*/
	  Make_Wakeup_Mode();
}

/------------------------2003-12-11日备份--------------------------------------//

⌨️ 快捷键说明

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