请高手帮我看看我的发送程序,到底是什么问题,一直发送不出去
#include<reg52.h>
#include<intrins.h>
#include<stdio.h>
#include <ABSACC.h>
#define uchar unsigned char
#define uint unsigned int
//*******************定义命令字**********************
#define WC 0x00 // Writeconfigurationregistercommand
#define RC 0x10 //Read configurationregistercommand
#define WTP 0x20 //WriteTXPayload command
#define RTP 0x21 //Read TXPayload command
#define WTA 0x22 //WriteTXAddress command
#define RTA 0x23
#define RRP 0x24
//---------------------------------------------------------------
#define BYTE_BIT0 0x01
#define BYTE_BIT1 0x02
#define BYTE_BIT2 0x04
#define BYTE_BIT3 0x08
#define BYTE_BIT4 0x10
#define BYTE_BIT5 0x20
#define BYTE_BIT6 0x40
#define BYTE_BIT7 0x80
bdata unsigned char DATA_BUF;
#define DATA7 ((DATA_BUF&BYTE_BIT7) != 0)
#define DATA0 ((DATA_BUF&BYTE_BIT0) != 0)
sbit flag=DATA_BUF^7;
sbit flag1=DATA_BUF^0;
//*******************管脚配置*********
//SPI口定义
sbit MOSI=P1^4;
sbit CSN=P1^5;
sbit SCK=P3^1;
sbit MISO=P3^0;
//配置口
sbit TRX_CE=P1^6;
sbit TXEN=P1^0;
sbit PWR=P1^1;
//状态口
sbit DR=P1^3;
sbit CD=P1^2;
sbit AM=P1^7;
sbit K1=P2^4;
//sbit K2=P2^5;
//sbit K3=P2^6;
//sbit K4=P2^7;
sbit LED1=P0^0;
sbit LED2=P0^1;
sbit LED3=P0^2;
//sbit d4=P0^3;
//uchar tf;
uchar TxRxBuf[4]={0x31,0x32,0x33,0x34};
uchar TxAddress[4]={0xE7,0xE7,0xE7,0xE7};
uchar RFConf[11]={0x00,0x4C,0x0E,0x44,0x04,0x04,0xE7,0xE7,0xE7,0xE7,0xDE};
//------------------------------------------------
void Delay(uint x)
{
uint i;
for(i=0;i<x;i++)
{
_nop_();
}
}
//----------------------------------100us延时子程序-----------------------------
/*void Delay(uint x)
{
uint i;
while(x--)
for(i=0;i<80;i++);
} */
//=================================================SPI读函数=======================================================
unsigned char SpiRead(void)
{
uchar i;
for (i=0;i<8;i++)
{
DATA_BUF=DATA_BUF<<1;
SCK=1;
if (MISO) //读取最高位,保存至最末尾,通过左移位完成整个字节
{
DATA_BUF|=BYTE_BIT0;
}
else
{
DATA_BUF&=~BYTE_BIT0;
}
SCK=0;
}
return DATA_BUF;
}
//=========================NRF905 SPI读写函数(IO模拟SPI时序)==================
void SpiWrite( uchar send)
{
unsigned char i;
DATA_BUF=send;
for (i=0;i<8;i++)
{
if (((DATA_BUF&0x80) != 0)) //总是发送最高位
{
MOSI=1;
}
else
{
MOSI=0;
}
SCK=1;
DATA_BUF=DATA_BUF<<1;
SCK=0;
}
}
//------------------------------初始化nRF905///////////////////
void nRF905Init(void)
{
CSN=1; // Spi disable
SCK=0; // Spi clock line init low
DR=0; // Init DR for input
AM=0; // Init AM for input
CD=0; // Init CD for input
PWR=1; // nRF905 power on
TRX_CE=0; // Set nRF905 in standby mode
TXEN=0; // set radio in Rx mode
}
////////初始化寄存器
void Config905(void)
{
uchar i;
CSN=0; // Spi enable for write a spi command
for (i=0;i<11;i++) // Write configration words 写放配置字
{
SpiWrite(RFConf[i]);
}
CSN=1; // Disable Spi
}
//--------------------------------------------------
void TxPacket(void)
{
uchar i;
TXEN=1;
CSN=0;
SpiWrite(WTP);
for(i=0;i<4;i++)
{
SpiWrite(TxRxBuf[i]);
}
CSN=1;
_nop_();_nop_();
CSN=0;
SpiWrite(WTA);
for(i=0;i<4;i++)
{
SpiWrite(TxAddress[i]);
}
CSN=1;
_nop_();_nop_();
TRX_CE=1;
Delay(50);
TRX_CE=0;
while(!DR);
}
//-------------------------------------------------
void Set_TxMode()
{
PWR=1; // PWR_UP TRX_CE TXEN MODE
TRX_CE=0; // 1 1 1SHOCKBURSTTX
TXEN=1;
Delay(2000); //timeustbe>=650us
}
//-----------------------------------------------------
void main()
{
nRF905Init();
Config905();
K1=1;
LED1=1;
LED2=1;
LED3=1;
while(1)
{
Set_TxMode();
if(K1==0)
{ Delay(10);
if(K1==0)
{
LED1=0;
Delay(1000);
LED1=1;
Delay(1000);
TxPacket();
Delay(200);
LED2=0;
Delay(1000);
LED2=1;
Delay(1000);
}
else
{ LED3=0;Delay(1000);LED3=1;Delay(1000); }
}
}
} |