📄 nrf905.txt
字号:
SystemBuffers.nRFTxBuff[11] = 0x04;
SystemBuffers.nRFTxBuff[12] = 0x10;
SystemBuffers.nRFTxBuff[13] = 0x26;
SystemBuffers.nRFTxBuff[14] = 0x21;
SystemBuffers.nRFTxBuff[15] = 0x09;
SystemBuffers.nRFTxCount = 32;//主机要求间接无线发送
}
else if (SystemBuffers.nRFRxBuff[9] == 0x83) {//子机变址请求
// LED2 = 0;//主机变址灯亮
SystemBuffers.nRFTxBuff[9] = 0x03;//主机变址应答
SystemBuffers.nRFTxBuff[10] = TH0;//
SystemBuffers.nRFTxBuff[11] = TL0;
SystemBuffers.nRFTxBuff[12] = SystemBuffers.WaitTime;
SystemBuffers.nRFTxBuff[13] = SystemBuffers.TimeCount;
SystemBuffers.nRFTxCount = 32;//主机要求间接无线发送
}
else if (SystemBuffers.nRFRxBuff[9] == 0x84) {//子机跳频请求
// LED3 = 0;//主机跳频灯亮
SystemBuffers.nRFTxBuff[9] = 0x04;//主机跳频应答
SystemBuffers.nRFTxBuff[10] = SystemBuffers.nRFTxBuff + 1;//主机跳频
SystemBuffers.nRFTxCount = 32;//主机要求间接无线发送
}
else if (SystemBuffers.nRFRxBuff[9] == 0x03) {//主机变址应答
LED2 = 0;//子机变址灯亮
SystemBuffers.nRFRxBuff[0] = SystemBuffers.nRFRxBuff[10];//改写接收地址第1字节
SystemBuffers.nRFRxBuff[1] = SystemBuffers.nRFRxBuff[11];//改写接收地址第2字节
SystemBuffers.nRFRxBuff[2] = SystemBuffers.nRFRxBuff[12];//改写接收地址第3字节
SystemBuffers.nRFRxBuff[3] = SystemBuffers.nRFRxBuff[13];//改写接收地址第4字节
WritenRFConfig(SystemBuffers.nRFRxBuff);//子机重新配置nRF905接收地址
}
else if (SystemBuffers.nRFRxBuff[9] == 0x04) {//主机跳频应答
// LED3 = 0;//子机跳频灯亮
SystemBuffers.nRFRxBuff = SystemBuffers.nRFRxBuff[10];
FastWritenRFConfig(SystemBuffers.nRFRxBuff);//快速配置nRF905,子机跳频
}
}
else if (!CD && (SystemBuffers.nRFTxCount == 32)) {//要求间接无线发送(发送命令处理)
SetTxMode();//设置发送模式
WriteTXBuffer(SystemBuffers.nRFTxBuff);
ClrWdt();//清除看门狗计数器
StartTx();//开始发送
SystemBuffers.nRFTxCount = 0;//结束发送模式
if (SystemBuffers.nRFTxBuff[9] == 0x03) {//主机变址应答
SystemBuffers.nRFRxBuff[4] = SystemBuffers.nRFTxBuff[10];//改写呼叫地址第1字节
SystemBuffers.nRFRxBuff[5] = SystemBuffers.nRFTxBuff[11];//改写呼叫地址第2字节
SystemBuffers.nRFRxBuff = SystemBuffers.nRFTxBuff[12];//改写呼叫地址第3字节
SystemBuffers.nRFRxBuff[7] = SystemBuffers.nRFTxBuff[13];//改写呼叫地址第4字节
}
else if (SystemBuffers.nRFTxBuff[9] == 0x04) {//主机跳频应答
SystemBuffers.nRFRxBuff = SystemBuffers.nRFTxBuff[10];//工作频率低8位
for (t = 0; t < 2500; t ++);//延时,等待发送结束
FastWritenRFConfig(SystemBuffers.nRFRxBuff);//快速配置nRF905,主机跳频
}
SetRxMode();//设置接收模式
}
}
//键
void Key00(void) using 0
{
unsigned char i;
if (SystemBuffers.nRFTxCount == 0) {//无线发送缓冲区为空
SystemBuffers.nRFTxBuff[0] = SystemBuffers.nRFRxBuff[4];//呼叫地址第1字节
SystemBuffers.nRFTxBuff[1] = SystemBuffers.nRFRxBuff[5];//呼叫地址第2字节
SystemBuffers.nRFTxBuff[2] = SystemBuffers.nRFRxBuff;//呼叫地址第3字节
SystemBuffers.nRFTxBuff[3] = SystemBuffers.nRFRxBuff[7];//呼叫地址第4字节
SystemBuffers.nRFTxBuff[4] = SystemBuffers.nRFRxBuff[0];//本机地址第1字节
SystemBuffers.nRFTxBuff[5] = SystemBuffers.nRFRxBuff[1];//本机地址第2字节
SystemBuffers.nRFTxBuff = SystemBuffers.nRFRxBuff[2];//本机地址第3字节
SystemBuffers.nRFTxBuff[7] = SystemBuffers.nRFRxBuff[3];//本机地址第4字节
SystemBuffers.nRFTxBuff = SystemBuffers.nRFRxBuff;//工作频率低8位
SystemBuffers.nRFTxBuff[9] = 0x81;//请求命令
for (i = 10; i < 32; i ++) SystemBuffers.nRFTxBuff = 0;
SystemBuffers.nRFTxCount = 32;//要求间接无线发送
for (i = 0; i < 32; i ++) SioBuffers.SioTxBuff = SystemBuffers.nRFTxBuff;
SioBuffers.SioTXCount = 32;//要求间接串口发送
TI = 1;//送串口显示
// LED0 = 0;//压键灯亮
}
}
//键
void Key01(void) using 0
{
unsigned char i;
if (SystemBuffers.nRFTxCount == 0) {//无线发送缓冲区为空
SystemBuffers.nRFTxBuff[0] = SystemBuffers.nRFRxBuff[4];//呼叫地址第1字节
SystemBuffers.nRFTxBuff[1] = SystemBuffers.nRFRxBuff[5];//呼叫地址第2字节
SystemBuffers.nRFTxBuff[2] = SystemBuffers.nRFRxBuff;//呼叫地址第3字节
SystemBuffers.nRFTxBuff[3] = SystemBuffers.nRFRxBuff[7];//呼叫地址第4字节
SystemBuffers.nRFTxBuff[4] = SystemBuffers.nRFRxBuff[0];//本机地址第1字节
SystemBuffers.nRFTxBuff[5] = SystemBuffers.nRFRxBuff[1];//本机地址第2字节
SystemBuffers.nRFTxBuff = SystemBuffers.nRFRxBuff[2];//本机地址第3字节
SystemBuffers.nRFTxBuff[7] = SystemBuffers.nRFRxBuff[3];//本机地址第4字节
SystemBuffers.nRFTxBuff = SystemBuffers.nRFRxBuff;//工作频率低8位
SystemBuffers.nRFTxBuff[9] = 0x82;//请求
for (i = 10; i < 32; i ++) SystemBuffers.nRFTxBuff = 0;
SystemBuffers.nRFTxCount = 32;//要求间接无线发送
for (i = 0; i < 32; i ++) SioBuffers.SioTxBuff = SystemBuffers.nRFTxBuff;
SioBuffers.SioTXCount = 32;//要求间接串口发送
TI = 1;//送串口显示
// LED1 = 0;//压键灯亮
}
}
void Key02(void) using 0
{
unsigned char i;
if (SystemBuffers.nRFTxCount == 0) {//无线发送缓冲区为空
SystemBuffers.nRFTxBuff[0] = SystemBuffers.nRFRxBuff[4];//呼叫地址第1字节
SystemBuffers.nRFTxBuff[1] = SystemBuffers.nRFRxBuff[5];//呼叫地址第2字节
SystemBuffers.nRFTxBuff[2] = SystemBuffers.nRFRxBuff;//呼叫地址第3字节
SystemBuffers.nRFTxBuff[3] = SystemBuffers.nRFRxBuff[7];//呼叫地址第4字节
SystemBuffers.nRFTxBuff[4] = SystemBuffers.nRFRxBuff[0];//本机地址第1字节
SystemBuffers.nRFTxBuff[5] = SystemBuffers.nRFRxBuff[1];//本机地址第2字节
SystemBuffers.nRFTxBuff = SystemBuffers.nRFRxBuff[2];//本机地址第3字节
SystemBuffers.nRFTxBuff[7] = SystemBuffers.nRFRxBuff[3];//本机地址第4字节
SystemBuffers.nRFTxBuff = SystemBuffers.nRFRxBuff;//工作频率低8位
SystemBuffers.nRFTxBuff[9] = 0x83;//变址请求
for (i = 10; i < 32; i ++) SystemBuffers.nRFTxBuff = 0;
SystemBuffers.nRFTxCount = 32;//要求间接无线发送
for (i = 0; i < 32; i ++) SioBuffers.SioTxBuff = SystemBuffers.nRFTxBuff;
SioBuffers.SioTXCount = 32;//要求间接串口发送
TI = 1;//送串口显示
// LED2 = 0;//压键灯亮
}
}
void Key03(void) using 0
{
unsigned char i;
if (SystemBuffers.nRFTxCount == 0) {//无线发送缓冲区为空
SystemBuffers.nRFTxBuff[0] = SystemBuffers.nRFRxBuff[4];//呼叫地址第1字节
SystemBuffers.nRFTxBuff[1] = SystemBuffers.nRFRxBuff[5];//呼叫地址第2字节
SystemBuffers.nRFTxBuff[2] = SystemBuffers.nRFRxBuff;//呼叫地址第3字节
SystemBuffers.nRFTxBuff[3] = SystemBuffers.nRFRxBuff[7];//呼叫地址第4字节
SystemBuffers.nRFTxBuff[4] = SystemBuffers.nRFRxBuff[0];//本机地址第1字节
SystemBuffers.nRFTxBuff[5] = SystemBuffers.nRFRxBuff[1];//本机地址第2字节
SystemBuffers.nRFTxBuff = SystemBuffers.nRFRxBuff[2];//本机地址第3字节
SystemBuffers.nRFTxBuff[7] = SystemBuffers.nRFRxBuff[3];//本机地址第4字节
SystemBuffers.nRFTxBuff = SystemBuffers.nRFRxBuff;//工作频率低8位
SystemBuffers.nRFTxBuff[9] = 0x84;//跳频请求
for (i = 10; i < 32; i ++) SystemBuffers.nRFTxBuff = 0;
SystemBuffers.nRFTxCount = 32;//要求间接无线发送
for (i = 0; i < 32; i ++) SioBuffers.SioTxBuff = SystemBuffers.nRFTxBuff;
SioBuffers.SioTXCount = 32;//要求间接串口发送
TI = 1;//送串口显示
// LED3 = 0;//压键灯亮
}
}
void Key10(void) using 0
{
LED0 = 1;//放键灭灯
}
void Key11(void) using 0
{
LED1 = 1;//放键灭灯
}
void Key12(void) using 0
{
LED2 = 1;//放键灭灯
}
void Key13(void) using 0
{
LED3 = 1;//放键灭灯
}
void Key20(void) using 0
{
LED0 = 1;//长压键灭灯
Key00();//连发
}
void Key21(void) using 0
{
LED0 = 1;//长压键灭灯
Key01();//连发
}
void Key22(void) using 0
{
LED0 = 1;//长压键灭灯
Key02();//连发
}
void Key23(void) using 0
{
LED0 = 1;//长压键灭灯
Key03();//连发
}
=============================================
*----------------------------------------------------------
具备跳号跳频和跳址的nrf905的C51演示程序nrf905.h
HotPower@126.com 2006.6.6 于大雁塔村队部
----------------------------------------------------------*/
#define nRFMainDev //主设备
//#define SysWaitTime 20//0.5*20=10S不压键停止闪烁
#define SysWaitTime 6//0.5*20=3S不压键停止闪烁
#define SysPushKeyTime 150//长压键150 * 20mS = 3。0S
#define T2_5mS -921.6*5//5ms 12MHz
/*------------------------------------------------
AT89S5X
--------------------------------------------------*/
sfr AUXR = 0x8e;
sfr WDTRST = 0xa6;
sfr16 TIMEER2 = 0xcc;
sfr16 RCAP = 0xca;
//全局变量定义
typedef struct Systemstruct{//系统数据结构
// unsigned char SystemFlage;//系统标志
unsigned char TimeCount;
unsigned int RamTest;
unsigned char TestTime;
unsigned char WaitTime;
unsigned char KeyCount[4];
unsigned char nRFTxCount;
unsigned char nRFRxCount;
unsigned char nRFTxBuff[32];
unsigned char nRFRxBuff[32];
}SystemData;
//全局变量定义
typedef struct Siostruct{//系统数据结构
unsigned char SioTxBuff[32];
unsigned char SioRxBuff[32];
unsigned char SioTXCount;
unsigned char SioRXCount;
}SioData;
/*-----------------------------------------------
nrf905管脚定义
------------------------------------------------*/
sbit TX_EN = P2^6;//0
sbit TRX_CE = P2^5;//0
sbit PWR_UP = P2^4;//1
sbit MISO = P2^3;//1
sbit MOSI = P2^2;//1
sbit SCK = P2^1;//0
sbit CSN = P2^0;//1
sbit AM = P3^2;//1
sbit DR = P3^3;//1
sbit CD = P3^5;//1
sbit KEY0 = P0^0;
sbit KEY1 = P0^1;
sbit KEY2 = P0^2;
sbit KEY3 = P0^3;
sbit LED0 = P0^4;
sbit LED1 = P0^5;
sbit LED2 = P0^6;
sbit LED3 = P0^7;
#define Status_AM 0x80
#define Status_DR 0x20
/*-----------------------------------------------
nrf905命令控制字
------------------------------------------------*/
#define WC 0x00 // Write configuration register command
#define RC 0x10 // Read configuration register command
#define WTP 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 RRP 0x24 // Read RX Payload command
#define CC 0x80 // fast config
/*-------------------------------------------------------------------------------------------
nrf905配置寄存器(10Byte)
工作频率f=(422.4+CH_NO/10)*(1+HFREQ_PLL)MHz
-------------------------------------------------------------------------------------------*/
#ifdef nRFMainDev
#define RX_ADDRESS 0x00000000 &nb
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -