这是一个自己写的程序 可是不知道哪里有错误,就是发不出去,对照着pdf写的寄存器啊,二姨家的大侠帮帮忙啊
#include <reg52.h>
#include <common.h>
#include <led1602.h>
#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
sbit
TX_EN
=P1^6;
sbit
TRX_CE
=P1^5;
sbit
PWR_UP
=P2^4;
sbit
MISO
=P2^3;
sbit
MOSI
=P2^2;
sbit
SCK
=P2^1;
sbit
CSN
=P2^0;
sbit
AM
=P3^2;
sbit
DR
=P3^3;
sbit
CD
=P3^5;
sbit LED =P1^3;
code unsigned char RFConf[11]={
0x00,
0x6c,
0x2f,
0x44,
0x01,
0x01,
0xcc,0xcc,0xcc,0xcc,
0x58
};
code unsigned char TxAddress[4]={0xcc,0xcc,0xcc,0xcc};
unsigned char TxRxBuf='S';
void Init_Nrf905();
void Config905_Register();
void SpiWrite_Nrf905(unsigned char writedata);
unsigned char SpiRead_Nrf905();
void SetTxMode();
void SetRxMode();
void TxPacket(unsigned char senddata);
void Delay_1ns_12M(unsigned int x) //x*0.14MS
{
unsigned int i;
for(i=0;i<x;i++)
{
}
}
/*
void Delay_1ms_12M(unsigned int x)
{
unsigned char i;
while(x--)
{
for(i=0;i<120;i++)
{}
}
}
*/
void Init_Nrf905()
{
CSN=1;
SCK=0;
DR=0;
AM=0;
CD=0;
PWR_UP=1;
TRX_CE=0;
TX_EN=0;
Config905_Register();
}
void Config905_Register()
{
unsigned char i;
CSN=0;
//CSN为低时,SPI接口开始等待一条指令
for(i=0;i<11;i++)
{
SpiWrite_Nrf905(RFConf[i]);
}
CSN=1;
//任何一条新指令均由CSN的下降沿触发
Delay_1ns_12M(500);
}
void SpiWrite_Nrf905(unsigned char writedata)
{
unsigned char i;
for(i=0;i<8;i++)
{
if((writedata&0x80))
{
MOSI=1;
}
else
{
MOSI=0;
}
SCK=1;
writedata=writedata<<1;
Delay_1ns_12M(40);
SCK=0;
}
}
unsigned char SpiRead_Nrf905()
{
unsigned char i,readdata=0;
for(i=0;i<8;i++)
{
readdata=readdata<<1;
SCK=1;
if (MISO)
{
readdata|=0x01;
}
else
{
readdata&=~0x01;
}
Delay_1ns_12M(40);
SCK=0;
}
return readdata;
}
void SetTxMode()
{
PWR_UP=1;
TRX_CE=0;
//发送时TRX_CE置1即可
TX_EN=1;
Delay_1ns_12M(650);
}
void SetRxMode()
{
PWR_UP=1;
TRX_CE=1;
TX_EN=0;
Delay_1ns_12M(650);
}
void TxPacket(unsigned char senddata)
{
unsigned char i;
SetTxMode();
Delay_1ms_12M(1);
CSN=0;
// Spi enable for write a spi command
SpiWrite_Nrf905(WTP);
// Write payload command
//
for(i=0;i<32;i++)
//
{
SpiWrite_Nrf905(senddata);
// Write 32 bytes Tx data
//
}
CSN=1;
// Spi disable
Delay_1ns_12M(300);
CSN=0;
// Spi enable for write a spi command
SpiWrite_Nrf905(WTA);
// Write address command
for(i=0;i<4;i++)
// Write 4 bytes address
{
SpiWrite_Nrf905(TxAddress[i]);
}
CSN=1;
// Spi disable
TRX_CE=1;
// Set TRX_CE high,start Tx data transmission
Delay_1ms_12M(2000);
TRX_CE=0;
// Set TRX_CE low
}
void main()
{
unsigned char i;
Init_Nrf905();
Init_1602();
LED=1;
/*
DataWrite_1602('a');
CSN=1;
Delay_1ns_12M(280);
CSN=0;
SpiWrite_Nrf905(0x1e);
for(i=0;i<11;i++)
{
LCD_Print_Num_int((unsigned int)SpiRead_Nrf905());
DataWrite_1602(' ');
//
if(i==3){PointerClear_1602();}
}
CSN=1;
while(1);
*/
while(1)
{
TxPacket(TxRxBuf);
if(DR==1)
{
DR=0;
LED=0;
Delay_1ms_12M(1000);
}
//LED=1;
}
} |