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

📄 nrf905-.h

📁 905读写程序,主要有子程序的说明,尽情个位关注,并指导
💻 H
字号:
/*-------------------------------------------------------------------------------------------
nrf905配置寄存器宏定义

        nrf905配置寄存器(10Byte)
工作频率f=(422.4+CH_NO/10)*(1+HFREQ_PLL)MHz


-------------------------------------------------------------------------------------------*/
#ifndef   _RF905_H
 #define  _RF905_H
 
#include <msp430x41x.h>
#include "type.h"
#define uchar unsigned char
#define uint  unsigned int

typedef struct
        {
        	uchar *ReceAdd;                /*接收地址*/        	
        	uchar ReceNum;                 /*接收字节数*/
        	uchar SendNum;                 /*发送字节数*/
        	uchar FMSelect;                /*频段选择*/
        }RFCONFG; 
        
/***********************RF905参数设置***********************/
#define RX_ADDRESS           0x00000000               //接收有效地址(本方)
#define TX_ADDRESS           0x02345678               //发送有效地址(对方)

#define CH_NO_FREQ_422_4MHz  0x000                     //工作频率422.4MHz(433MHz频段最低频率)
#define CH_NO_FREQ_422_5MHz  0x001                     //工作频率422.5MHz
#define CH_NO_FREQ_425_0MHz  0x01a                     //工作频率425.0MHz
#define CH_NO_FREQ_427_5MHz  0x033                     //工作频率427.5MHz

#define CH_NO_FREQ_430_0MHz  0x04c                     //工作频率430.0MHz
#define CH_NO_FREQ_433_0MHz  0x06a                     //工作频率433.0MHz(433MHz频段基准频率)
#define CH_NO_FREQ_433_1MHz  0x06b                     //工作频率433.1MHz
#define CH_NO_FREQ_433_2MHz  0x06c                     //工作频率433.2MHz
#define CH_NO_FREQ_434_7MHz  0x07b                     //工作频率434.7MHz
#define CH_NO_FREQ_473_5MHz  0x1ff                     //工作频率473.5MHz(433MHz频段最高频率)

#define CH_NO_FREQ_844_8MHz  0x000                     //工作频率844.8MHz(868MHz频段最低频率)

#define CH_NO_FREQ_862_0MHz  0x056                     //工作频率862.0MHz
#define CH_NO_FREQ_868_0MHz  0x074                     //工作频率868.0MHz(868MHz频段基准频率)
#define CH_NO_FREQ_868_2MHz  0x075                     //工作频率868.2MHz
#define CH_NO_FREQ_868_4MHz  0x076                     //工作频率868.4MHz
#define CH_NO_FREQ_869_8MHz  0x07d                     //工作频率869.8MHz
#define CH_NO_FREQ_895_8MHz  0x0ff                     //工作频率895.8MHz
#define CH_NO_FREQ_896_0MHz  0x100                     //工作频率896.0MHz
#define CH_NO_FREQ_900_0MHz  0x114                     //工作频率900.0MHz
#define CH_NO_FREQ_902_2MHz  0x11f                     //工作频率902.2MHz
#define CH_NO_FREQ_902_4MHz  0x120                     //工作频率902.4MHz
#define CH_NO_FREQ_915_0MHz  0x15f                     //工作频率915.0MHz(915MHz频段基准频率)
#define CH_NO_FREQ_927_8MHz  0x19f                     //工作频率927.8MHz

#define CH_NO_FREQ_947_0MHz  0x1ff                     //工作频率947.0MHz(915MHz频段最高频率)

#define CH_NO_FREQ           CH_NO_FREQ_430_0MHz       //工作频率433.0MHz


#define CH_NO_BYTE           CH_NO_FREQ & 0xff         //工作频率低8位       Byte0       01101100

#define AUTO_RETRAN          0x20                      //重发数据包          Byte1.5     0
#define RX_RED_PWR           0x10                      //接收低功耗模式      Byte1.4     0
#define PA_PWR__10dBm        0x00                      //输出功率-10dBm      Byte1.3~2   00
#define PA_PWR_2dBm          0x04                      //输出功率+2dBm       Byte1.3~2
#define PA_PWR_6dBm          0x08                      //输出功率+6dBm       Byte1.3~2
#define PA_PWR_10dBm         0x0c                      //输出功率+10dBm      Byte1.3~2   
#define HFREQ_PLL_433MHz     0x00                      //工作在433MHz频段    Byte1.1     0
#define HFREQ_PLL_868MHz     0x02                      //工作在868MHz频段    Byte1.1
#define HFREQ_PLL_915MHz     0x02                      //工作在915MHz频段    Byte1.1
#define CH_NO_BIT8           CH_NO_FREQ >> 8           //工作频率第9位       Byte1.0     0

#define TX_AFW_1BYTE         1 * 16                    //发送地址宽度1字节   Byte2.7~4
#define TX_AFW_2BYTE         2 * 16                    //发送地址宽度2字节   Byte2.7~4
#define TX_AFW_3BYTE         3 * 16                    //发送地址宽度3字节   Byte2.7~4
#define TX_AFW_4BYTE         4 * 16                    //发送地址宽度4字节   Byte2.7~4   100
#define RX_AFW_1BYTE         1                         //接收地址宽度1字节   Byte2.3~0
#define RX_AFW_2BYTE         2                         //接收地址宽度2字节   Byte2.3~0
#define RX_AFW_3BYTE         3                         //接收地址宽度3字节   Byte2.3~0
#define RX_AFW_4BYTE         4                         //接收地址宽度4字节   Byte2.3~0   100
#define RX_PW_1BYTE          1                         //接收数据宽度1字节   Byte3.5~0
#define RX_PW_32BYTE         32                        //接收数据宽度32字节  Byte3.5~0   00100000
#define TX_PW_1BYTE          1                         //发送数据宽度1字节   Byte4.5~0 
#define TX_PW_32BYTE         32                        //发送数据宽度32字节  Byte4.5~0   00100000
#define RX_ADDRESS_0         RX_ADDRESS >> 24          //接收有效地址第1字节 Byte5       11100111
#define RX_ADDRESS_1         (RX_ADDRESS >> 16)& 0xff  //接收有效地址第2字节 Byte6       11100111 
#define RX_ADDRESS_2         (RX_ADDRESS >> 8) & 0xff  //接收有效地址第3字节 Byte7       11100111
#define RX_ADDRESS_3         RX_ADDRESS & 0xff         //接收有效地址第4字节 Byte8       11100111
       
#define CRC_MODE_16BIT       0x80                      //CRC16模式           Byte9.7     1
#define CRC_MODE_8BIT        0x00                      //CRC8模式            Byte9.7     
#define CRC_EN               0x40                      //CRC使能             Byte9.6     1
#define CRC16_EN             0xc0                      //CRC16模式使能       Byte9.7~6   11
#define CRC8_EN              0x40                      //CRC8模式使能        Byte9.7~6
#define XOF_20MHz            0x20                      //晶体振荡器频率20MHz Byte9.5~3
#define XOF_16MHz            0x18                      //晶体振荡器频率16MHz Byte9.5~3   100
#define XOF_12MHz            0x10                      //晶体振荡器频率12MHz Byte9.5~3
#define XOF_8MHz             0x08                      //晶体振荡器频率8MHz  Byte9.5~3
#define XOF_4MHz             0x00                      //晶体振荡器频率4MHz  Byte9.5~3
#define UP_CLK_EN            0x40                      //输出时钟使能        Byte9.2     1
#define UP_CLK_FREQ_500kHz   0x03                      //输出时钟频率500kHz  Byte9.1~0   11
#define UP_CLK_FREQ_1MHz     0x02                      //输出时钟频率1MHz    Byte9.1~0
#define UP_CLK_FREQ_2MHz     0x01                      //输出时钟频率2MHz    Byte9.1~0
#define UP_CLK_FREQ_4MHz     0x00                      //输出时钟频率4MHz    Byte9.1~0

#define UP_CLK_EN_500kHz     0x43                      //输出时钟频率500kHz  Byte9.2~0   111
#define UP_CLK_EN_1MHz       0x42                      //输出时钟频率1MHz    Byte9.2~0
#define UP_CLK_EN_2MHz       0x41                      //输出时钟频率2MHz    Byte9.2~0
#define UP_CLK_EN_4MHz       0x40                      //输出时钟频率4MHz    Byte9.2~0

#define TX_ADDRESS_0         TX_ADDRESS >> 24          //发送有效地址第1字节
#define TX_ADDRESS_1         (TX_ADDRESS >> 16) & 0xff //发送有效地址第2字节
#define TX_ADDRESS_2         (TX_ADDRESS >> 8) & 0xff  //发送有效地址第3字节
#define TX_ADDRESS_3         TX_ADDRESS & 0xff         //发送有效地址第4字节

/***********************RF端口定义***********************/
// #define RFDIR    P1DIR 
// #define RFOUT    P1OUT 
// #define RFIN     P1IN
// #define DRDIR    P1DIR
// #define DROUT    P1OUT 
// #define DRSEL    P1SEL
// #define DRIFG    P1IFG
// #define DRIES    P1IES
// #define DRIE     P1IE
// #define DRIN     P1IN
 
// #define RFDIR    P3DIR 
// #define RFOUT    P3OUT 
// #define RFIN     P3IN
// #define DRDIR    P3DIR
// #define DROUT    P2OUT 
// #define DRSEL    P2SEL
// #define DRIFG    P2IFG
// #define DRIES    P2IES
// #define DRIE     P2IE
// #define DRIN     P2IN
 

 #define RFDIR    P2DIR 
 #define RFOUT    P2OUT 
 #define RFIN     P2IN
 #define DRDIR    P2DIR
 #define DROUT    P2OUT 
 #define DRSEL    P2SEL
 #define DRIFG    P2IFG
 #define DRIES    P2IES
 #define DRIE     P2IE
 #define DRIN     P2IN

 #define RFTX_EN      BIT0
 #define SetRFTX_EN() RFOUT |= RFTX_EN
 #define ClrRFTX_EN() RFOUT &=~RFTX_EN
 
 #define RFTX_CE      BIT1
 #define SetRFTX_CE() RFOUT |= RFTX_CE
 #define ClrRFTX_CE() RFOUT &=~RFTX_CE
 
 #define RF_PWR       BIT2
 #define SetRF_PWR()  RFOUT |= RF_PWR
 #define ClrRF_PWR()  RFOUT &=~RF_PWR
 
 #define RF_DR        BIT3
 //#define SetRF_DR   DROUT |= RF_DR
 //#define ClrRF_DR   DROUT &=~RF_DR
 
 #define RF_SO        BIT4
 //#define SetRF_SO()   RFOUT |= RF_SO
 //#define ClrRF_SO()   RFOUT &=~RF_SO
  
 #define RF_SI        BIT5
 #define SetRF_SI()   RFOUT |= RF_SI
 #define ClrRF_SI()   RFOUT &=~RF_SI
 
 #define RF_SCK       BIT6
 #define SetRF_SCK()  RFOUT |= RF_SCK
 #define ClrRF_SCK()  RFOUT &=~RF_SCK
 
 #define RF_CSN       BIT7
 #define SetRF_CSN()  RFOUT |= RF_CSN
 #define ClrRF_CSN()  RFOUT &=~RF_CSN 

 #ifndef  _SET_PORT
  #define _SET_PORT
  #define SetPortOUT(PortDir,Port) PortDir |= Port    //设置端口为输出状态
  #define SetPortIN(PortDir,Port)  PortDir &=~Port    //设置端口为输入状态
  #define SetPortH(PortOut,Port)   PortOut |= Port    //设置端口为高电平
  #define SetPortL(PortOut,Port)   PortOut &=~Port    //设置端口为低电平
  #define GetPortSt(PortIn,Port)   PortIn  &  Port    //获取端口状态,需先将相应端口设为输入
 #endif 
/***********************RF命令定义***********************/
 #define WTP  0x20    //Write TX-payload
 #define RTP  0X21    //Read  TX-payload
 #define WTA  0X22    //Write TX-Address
 #define RTA  0x23    //Read  TX-Address
 #define RRP  0x24    //Read  RX-payload

#define RFPowerDown() ClrRF_PWR();
void SPI_ByteWrite(uchar Data);
void RF_Delay(uint temp);
void RFStandby(void);
void RFRXModel(void);
void RFTXModel(void);
void RFPortInit(void);
void RFConfig(RFCONFG *p);
void RFReadConfig(uchar *p);
void RF_SendBytes(uchar *Add,uchar *p,uchar Len);
void RF_RecBytes(uchar *p,uchar Len);
void RF_Send(uchar *Add);
uchar SPI_ByteRead(void);

#endif

⌨️ 快捷键说明

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