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

📄 arm_nrf905.txt

📁 这是一个arm做的无线收发的程序.可以实现无线数据采集系统。代替了有线传输。而且传输速率高。
💻 TXT
📖 第 1 页 / 共 2 页
字号:
	{
		
		
		Delay(1);						// 5ms
		
		
	} while ( ( rPDATG&nRF905_dr ) == 0);					// wait for receiving data 
	//while(Data_Recv == 0);
    //Data_Recv = 0 ;
	
					
    rPDATC = rPDATC & (~nRF905_trx_ce);
	// read the paylload 
	RW_nRF905 (R_RX_PAYLOAD, R_nRF905, 0x20, Payload);
	
   for (n= 0;n<32;n++)
   {
     Uart_Printf("%x ",Payload[n]);
   }
   
   Uart_Printf("\n");
   
} 


/****************************************************************************
* 名称: void nRF905Transmit ( uchar* Payload)  
* 功能:Transmit the payload from the address
* 入口参数  Payload - the pointer for transmiting data
*          
* 出口参数:
****************************************************************************/



 void nRF905Transmit ( uchar* Payload)     
{
	
	uchar Tx_Address[4] = {0xE7,0xE7,0xE7,0xE7};
	
	rINTMSK= rINTMSK | BIT_GLOBAL;     //关总中断
	
	rPDATC = rPDATC | nRF905_txen;
	rPDATC = rPDATC & (~nRF905_trx_ce);
	Delay(5);

	RW_nRF905 (WTA, W_nRF905, 0x04, Tx_Address);
	Delay(5);

	// write the payload 
	RW_nRF905 (W_TX_PAYLOAD, W_nRF905, 0x20, Payload);

    // the mode of receiving data 
    rPDATC  = rPDATC | nRF905_trx_ce;
	do
	{
		
		Delay(1);					// 5ms
	
	}while ( ( rPDATD&nRF905_cd ) != 0);			// wait for carrier detect 
	
	
	rPDATC = rPDATC | nRF905_txen;
	Delay(5);
	rPDATC = rPDATC | nRF905_trx_ce;
	Delay(5);
	
	do
	{
		
		Delay(1);
		
		
	}while ( ( rPDATG&nRF905_dr ) == 0);	// transimit completed 

   
   
    Uart_Printf("Command word has been send!\n");
	
	Delay(2);//keep for carrier
	
   // rPDATC = rPDATC & (~nRF905_trx_ce);   //发送完毕置为空闲模式
	
	// the mode of receive 
	rPDATC = rPDATC & (~nRF905_txen);
	
	rI_ISPC = BIT_EINT2 ; //不中断但是同样会置位,所以需要清位
	
	rINTMSK= rINTMSK & (~BIT_GLOBAL);   //开中断
}


 
/************************************************************
*名称:  void __irq Rtc_Interrupt(void)
*功能:  实时中断
 
*************************************************************/
void __irq Rtc_Interrupt(void)      //时钟中断
{
    rI_ISPC = BIT_RTC;        //清除挂起位
    Uart_Printf("RTC Alarm Interrupt O.K.\n");
    Rtc_finished = 1;
}



/************************************************************
*名称:  void Set_AlamTimer(void)
*功能:  设置报警时钟
 
*************************************************************/


void Set_AlamTimer(void)
 {
   rRTCCON = 0x01; // R/W enable, 1/32768, Normal(merge), No reset

    rALMYEAR=rBCDYEAR ;//设置报警日期时间
    rALMMON =rBCDMON;
    rALMDAY =rBCDDAY  ;
    rALMHOUR=rBCDHOUR ;
    rALMMIN =rBCDMIN  ;
    rALMSEC =WarnningSec;
    
    pISR_RTC=(unsigned)Rtc_Interrupt;     //写中断向量的入口地址
    rRTCALM=0x7f;                       //使能实时报警时钟
    rINTMSK=~(BIT_GLOBAL|BIT_RTC);      //允许时钟中断
   
   // R/W disable(for power consumption), 1/32768, Normal(merge), No reset
    rRTCCON = 0x0;

  }





void Ready_recvdata(void)  //让nrf905工作在接收模式
 {
   rPDATC = rPDATC &(~nRF905_txen);	
   rPDATC = rPDATC | nRF905_trx_ce;
   Delay(5);
 }



/*****************************************************************
*名称: void __irq DR_Interrupt (void)
*功能: 接收中断并存储温度值
*****************************************************************/


void __irq DR_Interrupt (void)
 {
   
   
   rI_ISPC = BIT_EINT2 ;
   RecvDataCount ++ ;
   if(RecvDataCount == 64) { RecvDataCount = 0;RecvDataFinshed = 1;} 
  // rPDATC = rPDATC & (~nRF905_trx_ce);          //置为休闲模式
   Uart_Printf("ok!\n");
   RW_nRF905 (R_RX_PAYLOAD, R_nRF905, 0x20, Payload);
  // Uart_Printf("%x ",Payload);
   for (n= 0;n<32;n++)
   {
     Uart_Printf("%x ",Payload[n]);
   }  


   Date_Store(Payload);
   Data_Recv = 1;
 
  // rPDATC = rPDATC | nRF905_trx_ce;            //置为接收模式
 }



/*****************************************************************
*名称: void Eint2_init(void)
*功能: 外部中断初始化(上跳沿触发 IRQ模式)
*****************************************************************/


void Eint2_init(void)
 {
   
   rINTCON = 0x5 ;		//无向量中断模式
   rINTMOD = 0x0 ;		//All=IRQ mode
   pISR_EINT2 = (unsigned)DR_Interrupt ; //修改中断入口地址
   rEXTINT = 0x44444444;            //上升沿中断
   rINTMSK = rINTMSK & (~BIT_EINT2)  ;
  }



void Main()
 {
   uchar i,j,m;
  
      
   Port_Init();
  
   Uart_Select(0);
   Uart_Init( 0, 115200 );
   Uart_Printf("\nThe transmition is Start!\n");
   Init_nRF905();
   //rINTCON = 0x5 ;		//无向量中断模式
   //rINTMOD = 0x0 ;		//All=IRQ mode
   Rtc_Init();
   Set_AlamTimer();
   Eint2_init();
    
   // while (Rtc_finished == 0);
   // Rtc_finished = 0;
   
   while(1)      //做主机方的程序
    {
      
        while (Rtc_finished == 0);
        Rtc_finished = 0;
        //Uart_Printf("");
        //PG2Input_Mod();
       // nRF905Transmit(TranmistionCMD);  //向分机发送命令要求分机把测温器的数据发送过来
       // PG2Multi_Mod();
       // while (RecvDataCount < 0x4){  };
       // RecvDataCount = 0 ;
       // while (RecvDataFinshed == 0)
       // {
      // Uart_Printf("从分机读数据请按g键/显示温度表请按p键: \n");
       
       while (Rtc_finished == 0)
         {
           Uart_Printf("从分机读数据请按g键/显示温度表请按p键: \n");
           
                        
           if(RecvDataFinshed == 1)
             {
               RecvDataFinshed = 0;
               Uart_Printf("\n从分机接收数据完毕!\n");
               Uart_Printf("\n请按p进行更新数据表: \n"); 
               //Uart_Printf("从分机读数据请按g键/显示温度表请按p键: \n");
               //SerialCMD = Uart_Getch(); 
             } 
           
           
           SerialCMD = Uart_Getch();
          
           if(SerialCMD == Printf_TempTest)
             {
               SerialCMD = 0x00;
               
               Uart_Printf("                          温度检测系统\n");
               Uart_Printf("测温机号   传感器号   1点温度  2点温度  3点温度  4点温度\n");
               for(i = 0;i<16;i++)
                  for(j = 0;j<4;j++)
                     for(m = 0;m <10;m++)
         
                    {
                       //Uart_Printf("%x           00%x      %0x%0x     %0x%0x      %0x%0x     %0x%0x\n",RecvData[i][j][80],RecvData[i][j][81],RecvData[i][j][82],RecvData[i][j][83],RecvData[i][j][84],RecvData[i][j][85],RecvData[i][j][86],RecvData[i][j][87],RecvData[i][j][88],RecvData[i][j][89]);
                       //Uart_Printf("00%x           00%x       %0x%0x      %0x%0x       %0x%0x      %0x%0x\n",RecvData[i][j][0],RecvData[i][j][1],RecvData[i][j][2],RecvData[i][j][3],RecvData[i][j][4],RecvData[i][j][5],RecvData[i][j][6],RecvData[i][j][7],RecvData[i][j][8],RecvData[i][j][9]);
                       // Uart_Printf("%x           00%x      %0x%0x     %0x%0x      %0x%0x     %0x%0x\n",RecvData[i][j][],RecvData[i][j][],RecvData[i][j][],RecvData[i][j][],RecvData[i][j][],RecvData[i][j][],RecvData[i][j][],RecvData[i][j][],RecvData[i][j][],RecvData[i][j][]);
                       Uart_Printf ("%x ",RecvData[i][j][m]);
                     }
                     
                //Uart_Printf("\n请按p进行更新数据表: \n");     
                     
               } 
               
            if (SerialCMD == Get_Temp ) 
             
             { 
                 SerialCMD = 0x00;
                 
                 
                 PG2Input_Mod();
                 nRF905Transmit(TranmistionCMD);  //向分机发送命令要求分机把测温器的数据发送过来
                 PG2Multi_Mod();
             }  
             
    
         }            
        //}
       // RecvDataFinshed = 0;

//写打印的程序
    //  Uart_Printf("                          温度检测系统\n");
    //  Uart_Printf("测温机号   传感器号   1点温度  2点温度  3点温度  4点温度\n");
    //  for(i = 0;i<8;i++)
    //   for(j = 0;j<4;j++)
         
     //     {
            //Uart_Printf("%x           00%x      %0x%0x     %0x%0x      %0x%0x     %0x%0x\n",RecvData[i][j][80],RecvData[i][j][81],RecvData[i][j][82],RecvData[i][j][83],RecvData[i][j][84],RecvData[i][j][85],RecvData[i][j][86],RecvData[i][j][87],RecvData[i][j][88],RecvData[i][j][89]);
     //       Uart_Printf("%x           00%x      %0x%0x     %0x%0x      %0x%0x     %0x%0x\n",RecvData[i][j][0],RecvData[i][j][1],RecvData[i][j][2],RecvData[i][j][3],RecvData[i][j][4],RecvData[i][j][5],RecvData[i][j][6],RecvData[i][j][7],RecvData[i][j][8],RecvData[i][j][9]);
           // Uart_Printf("%x           00%x      %0x%0x     %0x%0x      %0x%0x     %0x%0x\n",RecvData[i][j][],RecvData[i][j][],RecvData[i][j][],RecvData[i][j][],RecvData[i][j][],RecvData[i][j][],RecvData[i][j][],RecvData[i][j][],RecvData[i][j][],RecvData[i][j][]);
      //    }
  }  
  
}
    
    
    
    
/*void Main()
 {
        
  // uchar i,j;
  
      
   Port_Init();
  
   Uart_Select(0);
   Uart_Init( 0, 115200 );
   Uart_Printf("\nThe transmition is Start!\n");
   Init_nRF905();
   //rINTCON = 0x5 ;		//无向量中断模式
   //rINTMOD = 0x0 ;		//All=IRQ mode
   Rtc_Init();
   Set_AlamTimer();
   Eint2_init();
    
   while (Rtc_finished == 0);
   Rtc_finished = 0; 
   
   
   PG2Input_Mod();
   nRF905Transmit(TranmistionCMD);  //向分机发送命令要求分机把测温器的数据发送过来
   PG2Multi_Mod();
   
   while(1){};
   
   
 }  */ 
    
    

⌨️ 快捷键说明

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