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

📄 nrf905_reference_firmware.c

📁 nRF905无线收发模块的应用
💻 C
📖 第 1 页 / 共 2 页
字号:

void write_tx_payload(unsigned char tx_payload_bytes_num)	
{
	CSN=0;
	write_spi_one_byte(0x20);//0b00100000
	while(tx_payload_bytes_num--)
	{
		write_spi_one_byte(tx_data_buf[0]);
	}
	write_spi_one_byte(tx_data_buf[1]);
	write_spi_one_byte(tx_data_buf[2]);
	CSN=1;
}
/**********************************************************************************/

/***********************************************************************************
* function:         read_tx_payload()									
* use:	            		
* input parameter:	 									
* output parameter:								
***********************************************************************************/
/*
void read_tx_payload(unsigned char tx_payload_bytes_num)	
{
	unsigned char i;
	CSN=0;
	write_spi_one_byte(0x21);0b00100001
	i=0;
	while(tx_payload_bytes_num--)
	{
		tx_data_buf[i]=read_spi_one_byte();
		i++;
	}
	CSN=1;
}
/**********************************************************************************/

/***********************************************************************************
* function:         write_tx_address()									
* use:	            		
* input parameter:	 									
* output parameter:								
***********************************************************************************/

void write_tx_address(unsigned char tx_address_bytes_num)	
{
	unsigned char i;
	CSN=0;
	write_spi_one_byte(0x22);//0b00100010
	i=0;
	while(tx_address_bytes_num--)
	{
		write_spi_one_byte(tx_address_reg_buf[i]);
		i++;
	}
	CSN=1;
}
/**********************************************************************************/

/***********************************************************************************
* function:         read_tx_address()									
* use:	            		
* input parameter:	 									
* output parameter:								
***********************************************************************************/
/*
void read_tx_address(unsigned char tx_address_bytes_num)	
{
	unsigned char i;
	CSN=0;
	write_spi_one_byte(0x23);//0b00100011
	i=0;
	while(tx_address_bytes_num--)
	{
		tx_address_buf[i]=write_spi_one_byte();
		i++;
	}
	CSN=1;
}
/**********************************************************************************/

/***********************************************************************************
* function:         read_rx_payload()									
* use:	            		
* input parameter:	 									
* output parameter:								
***********************************************************************************/

void read_rx_payload(unsigned char rx_payload_bytes_num)	
{
	unsigned char i;
	CSN=0;
	write_spi_one_byte(0x24);//0b00100100
	i=0;
	while(rx_payload_bytes_num--)
	{
		rx_data_buf[i]=read_spi_one_byte();
		i++;
	}
	CSN=1;
}
/**********************************************************************************/

/***********************************************************************************
* function:         fast_channel_config()									
* use:	            		
* input parameter:	 									
* output parameter:								
***********************************************************************************/
/*
void fast_channel_config(unsigned char freq_value,unsigned char ch_no_value)	
{
	CSN=0;
	freq_value|=0x80;
	write_spi_one_byte(freq_value);
	write_spi_one_byte(ch_no_value);
	CSN=1;
}
/**********************************************************************************/

/***********************************************************************************
* function:         send_rx_data_to_pc()									
* use:	             send the received data to pc used UART		
* input parameter:	 none		
* output parameter: none												
***********************************************************************************/

void send_rx_data_to_pc(void)
{		
	unsigned char i;
	i=0;
	for(i=0;i<32;i++)	//send ASCII char'Comait CRM401XNC' use UART 
	{
		TI=0;
		SBUF=rx_data_buf[i];
		while(TI==0);
	}
}
/**********************************************************************************/

/**********************************************************************************
* function:       delay_ms()											
* use:	       delay x ms(Max 65535ms,only for at89c2051 MCU)
* input parameter:	unsigned int delay_counter								
* output parameter: none											
***********************************************************************************/
void delay_ms(unsigned int delay_counter)
{
	unsigned int i;
	while(delay_counter--)
	{
		i=250;
		while(i--);
	}
}
/**********************************************************************************/

/***********************************************************************************
* function:       send_rf_data()											
* use:	          doing the arrange work for transimit mode
* input parameter:	none
* output parameter: none										
***********************************************************************************/

void send_rf_data(void)
{
	unsigned char i;
	write_tx_address(4);
	write_tx_payload(30);
	TRX_CE=1;
	i=2;						//delay 20us
	while(i--);
	TRX_CE=0;
	delay_ms(1);
}
/**********************************************************************************/

/***********************************************************************************
* function:       transmit_mode()											
* use:	          doing the arrange work for transimit mode
* input parameter:	none
* output parameter: none										
***********************************************************************************/

void transmit_mode(void)
{
	TXEN=1;						//Change the RF to the transmit mode
	while(STOP_SW==1)
	{	LED2=0;	
	  	LED2=1;	

		LED1=0;//
      
		send_rf_data();			//Do if start_send_data button was pressed
		tx_data_buf[0]++;
		if(tx_data_buf[0]==0x5b)
		{
			tx_data_buf[0]=0x41;	
		}
		delay_ms(70);
		LED1=1;//
       	delay_ms(80);
	}
	task_switch=2;				//Change the status toggle to the receive mode	
}
/**********************************************************************************/

/***********************************************************************************
* function:       receive_mode()											
* use:	          doing the arrange work for receive mode
* input parameter:	none
* output parameter: none										
***********************************************************************************/

void receive_mode(void)
{
	TXEN=0;						//Change the RF to the receive mode
	TRX_CE=1;
	LED1=0;
	delay_ms(1);
	while(START_SW==1)
	{
		if(DR==1)
		{
			LED1=1;
			read_rx_payload(32);
			send_rx_data_to_pc();
			delay_ms(55);
			LED1=0;
		}
	}
	TRX_CE=0;
	task_switch=1;				//Change the status toggle to transmit mode
}
/**********************************************************************************/

/***********************************************************************************
* function:         main()										
* use:	             blend all subroutines to do all work			    	
* input parameter:	 none								
* output parameter: none						
***********************************************************************************/
 void main(void)
{
	system_init();	
    task_switch=2;  //send	

	while (1)
	{	   		
   		switch (task_switch)
		{
			case 0:
				break;		
			case 1:	

			transmit_mode();		//The test board working in the transmit mode
         //	Delay100ms(5);
			  //	LED2=!LED2;	
				break;		
			case 2: 
				receive_mode();		//The test board working in the receive mode
				break;										
			default:
				break;			
		}   		
     }
}
/************************************* THE END **************************************/

⌨️ 快捷键说明

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