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

📄 arm_nrf905.txt

📁 这是一个arm做的无线收发的程序.可以实现无线数据采集系统。代替了有线传输。而且传输速率高。
💻 TXT
📖 第 1 页 / 共 2 页
字号:
#include "option.h"
#include "44b.h"
#include "44blib.h"

#define   uchar unsigned char
#define   uint  unsigned int
#define   ulong unsigned long

#define  nRF905_txen            (1<<4)         //PC4~7做输出
#define  nRF905_trx_ce          (1<<5)
#define  nRF905_pwr_up          (1<<6)
#define  nRF905_spi_csn         (1<<7)


#define  nRF905_cd               (1<<0)            //PD0~2做input,PD3~4做output
#define  nRF905_am               (1<<1)
#define  nRF905_spi_miso         (1<<2)
#define  nRF905_spi_mosi         (1<<3)
#define  nRF905_spi_sck          (1<<4)



#define nRF905_dr                (1<<2)      //PG2做input检测dr信号(可以做外部中断2)



#define WC					0x00			// Write configuration register command
#define RC					0x10 			// Read  configuration register command
#define W_TX_PAYLOAD		0x20 			// Write TX Payload  command
#define RTP					0x21			// Read  TX Payload  command
#define WTA					0x22			// Write TX Address  command
#define RTA					0x23			// Read  TX Address  command
#define R_RX_PAYLOAD		0x24			// Read  RX Payload  command



//收发控制
#define R_nRF905	1
#define W_nRF905	0

//收发数据长度
#define C_RX_LEN	32
#define C_TX_LEN	32

//告警时间设定
#define WarnningHour 0x08
#define WarnningMin  0x00
#define WarnningSec  0x20 


#define Printf_TempTest   'p'
#define Get_Temp          'g'

volatile uchar RecvDataFinshed = 0;
volatile uchar Data_Recv = 0;
volatile uchar Rtc_finished = 0 ;
uchar  n;
uchar  Payload[32];
uchar my_address = '1';
//uchar TranmistionCMD[32] = {0x00,0x01,0xAA};
uchar TranmistionCMD[32] = {0xAA,0xBB,0xCC};
uchar RecvData[256][4][10];//后面10字节空间放测温器号,传感器号和8字节温度值
uchar RecvDataBuffer[32];
uchar CWQNum,CGQNum,TempNnm;
uchar SerialCMD;
uint  RecvDataCount; 
//uint CWQCount, CGQCount;
/****************************************************************************
* 名称:void Date_Store( uchar *Data)
* 功能:存储温度数据
* 入口参数:Data       
* 出口参数:无
*****************************************************************************/
void Date_Store( uchar *Data)
 {

  // CWQNum = Data[1];
  // CGQNum = Data[2];
   
 //  RecvData[CWQNum][CGQNum][0] = CWQNum;
 //  for (TempNnm = 1; TempNnm<10;TempNnm++)
//   {
//     RecvData[CWQNum][CGQNum][TempNnm] = Data[TempNnm + 1];
 //  }
   
   
   
 //  CGQNum = Data[11];
   
 //  RecvData[CWQNum][CGQNum][0] = CWQNum;
 //  for (TempNnm = 1; TempNnm<10;TempNnm++)
 //  {
 //    RecvData[CWQNum][CGQNum][TempNnm] = Data[TempNnm + 10];
  // }
   CWQNum = Data[0];
   CGQNum = Data[1];
   for (TempNnm = 0; TempNnm<10;TempNnm++)
   {
     RecvData[CWQNum][CGQNum][TempNnm] = Data[TempNnm];
   }

 }  
     
/*************************************************************
*名称: void PG2Input_Mod (void)
*功能: 将dr方式设为查询方式
**************************************************************/   

void PG2Input_Mod (void)
{
  rPCONG = 0X00;
}

/*************************************************************
*名称: void PG2Multi_Mod(void) 
*功能: 将dr方式设为中断方式
**************************************************************/   


void PG2Multi_Mod(void)  
{
  
  rPCONG = 0xffffffff;
  
 
}


/*************************************************************
*名称: void Power_Up(void)
*功能: 给nrf905上电,使其工作在工作模式
**************************************************************/   
 
void Power_Up(void)
{
   rPDATC = rPDATC | nRF905_pwr_up;
   Delay(1);
   rPDATC = rPDATC & (~nRF905_trx_ce);
   Delay(1);
   rPDATC = rPDATC & (~nRF905_txen);
   Delay(1);
   rPDATC = rPDATC | nRF905_spi_csn;
   Delay(1);
   rPDATD = rPDATD & (~nRF905_spi_sck);
   Delay(1);
   rPDATD = rPDATD | nRF905_spi_mosi;
   Delay(1);
}   
 
 
 
/*************************************************************
*名称: unsigned char HW_MasterIO(unsigned char HW_SPI_out)
*功能: 通过spi总线往nRF905里面写/读(可同时进行)一个字节数据
*入口参数: HW_SPI_out (要写的数据)
*出口参数: ReadData   (读出的数据)  
**************************************************************/   

unsigned char HW_MasterIO(unsigned char HW_SPI_out)
{
	uchar BitCounter;		// bit counter 
	uchar WriteData;	// temporarily store the data 
	uchar ReadData = 0;		// temporarily store the data 

   	WriteData=HW_SPI_out;
	for (BitCounter=0; BitCounter<8; BitCounter++)
	{
		// give the correspond bit to mosi 
		if ((WriteData &0x80) == 0x80)
		{
			
			
			 rPDATD = rPDATD |  nRF905_spi_mosi;
		}
		else
		{
			
			
			rPDATD = rPDATD &  (~nRF905_spi_mosi);
		}
		// modify the data 
		WriteData = WriteData<<1;


		// generator the rising clock 
		
		 rPDATD = rPDATD & (~nRF905_spi_sck);
		Delay(1);
		
		rPDATD = rPDATD | nRF905_spi_sck;
		Delay(1);

		// read the SPI interface 
		ReadData = ReadData<<1;
		
	   if (  (rPDATD & nRF905_spi_miso ) != 0 )
		  {
			
			ReadData = ReadData + 1;
		
		  }
	}
	
	return(ReadData);
}



/*************************************************************
*名称: void RW_nRF905 (uchar Command, uchar RWbit, uchar RWnumber, uchar* Data)  
*功能: 通过spi总线往nRF905里面写/读数据
*入口参数: Command 
*入口参数: RWbit (读/写)
*入口参数: RWnumber(读/写的个数)
*入口参数: Data  (要写数据的指针/读出数据存放的地址)
 
**************************************************************/   



void RW_nRF905 (uchar Command, uchar RWbit, uchar RWnumber, uchar* Data)  
{

//	WM_CS=1; WM_SCLK=0;WM_MOSI=1,WM_MISO=1;
	
	rPDATC = rPDATC | nRF905_spi_csn;
	Delay(1);
	
	rPDATD = rPDATD &(~nRF905_spi_sck);
	Delay(1);
	
	rPDATD = rPDATD | nRF905_spi_mosi;
	Delay(1);
	
	rPDATC = rPDATC & (~nRF905_spi_csn);
	Delay(1);
	
	HW_MasterIO(Command);
	
	do
	{
		if (RWbit == W_nRF905)
		{
			// write the SPI interface 
			HW_MasterIO(*Data);
			
		}
		
		else
		
		{
			// read the SPI interface 
			*Data = HW_MasterIO(0x00);
			
		}

		Data++;

	}while(--RWnumber);

	
	rPDATC = rPDATC | nRF905_spi_csn;
}
   
   

   
 
 
 /****************************************************************************
* 名称 nRF905_SPI_CFG(void)
* 功能:
* 入口参数:
*          
* 出口参数:
****************************************************************************/


void nRF905_SPI_CFG(void)
{
	
	
	//uchar  cfg_tab[10] = { 0x6c,0x0c,0x44,0x20,0x20,0xe7,0xe7,0xe7,0xe7,0xdc } ; //433M
	
	uchar  cfg_tab[10] = { 0x0c,0x2e,0x44,0x20,0x20,0xe7,0xe7,0xe7,0xe7,0xdc } ;   //915M
	
	RW_nRF905(WC, W_nRF905,10,cfg_tab);
	
}

 
 
 /****************************************************************************
* 名称:Init_nRF905(void)
* 功能:nRF905初始化,填写配置字。
* 入口参数
*          
* 出口参数:
****************************************************************************/


void Init_nRF905(void)
{
	
	
	Power_Up() ;
	Delay(2);
	
	nRF905_SPI_CFG();			//开始配置过程
	Delay(2);
	
	
}

 
 
 
/****************************************************************************
* 名称:nRF905Receive ( uint8* Payload)
* 功能:receive the payload from the address
* 入口参数  Payload - the pointer for receiving data
*          
* 出口参数:
****************************************************************************/


 

void nRF905Receive ( uchar* Payload)
{

	
	rPDATC = rPDATC &(~nRF905_txen);	
	rPDATC = rPDATC | nRF905_trx_ce;
	Delay(2);
	
	do

⌨️ 快捷键说明

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