#include<reg51.h>
#include"uart.h"
#include"spi.h"
#include"rf4432.h"
#define uchar unsigned char
#define uint unsigned int
#define LampOn LED=0;
#define LampOff LED=1;
sbit LED=P1^0;
sbit btn_press=P2^7;
//-------------------------------------------射频芯片相关定义--------------------------------
#define RF4432_TxBuf_Len 10
#define RF4432_RxBuf_Len 5 //定义RF4432数据包长度
char RF4432_RxBuf[RF4432_RxBuf_Len];
char RF4432_TxBuf[RF4432_TxBuf_Len]={0x30,0x31,0x32,3,4,5,6,7,8,9};
char A[RF4432_TxBuf_Len];
//uchar FSK[10]={0xaa,0xaa,0x00,0xaa,0x00,0x00,0x00,0xaa,0x00,0x00};
bit send_enable=0;
bit receive_enable=1;
/////////////////////////////////////////////////////////////////
// RF4432_SDI=1; //SPI数据输入
// RF4432_SCLK=1; //SPI时钟输入端口
// RF4432_SEL=1; //SPI片选
// RF4432_SDI=0; //SPI数据输入
// RF4432_SCLK=0; //SPI时钟输入端口
// RF4432_SEL=0; //SPI片选
////////////////////////////////////////////////////////////////////
void main(void)
{
unsigned char i,send_enable=0;
LampOn;
// init();
btn_press=1;
UART_Init();
SPI_Init();
UART_Send_Str("初始化完毕....\n");
RF4432_Init();
UART_Send_Str("RF芯片si4432初始化完毕....\n");
RF4432_SetRxMode(); //设置成接收模式
UART_Send_Str("模块处于接收状态....\n");
while(1)
{
if(RF4432_RxPacket())
{
RF4432_ReadBurestReg(FIFO_ACCESS,RF4432_RxBuf,RF4432_RxBuf_Len);
for(i=0;i<RF4432_RxBuf_Len;i++)
{
//serialsend(RF4432_RxBuf);
UART_Send_Byte(RF4432_RxBuf); //向串口发送接收到的数据
delay_10us(10);
}
RF4432_SetRxMode(); //设置成接收模式
UART_Send_Str("成功接收完毕,恢复到接收状态....\n");
// send_enable=1;
}
LampOn; delay(50) ;LampOff;delay(50) ;
if(btn_press==0)
{
while(btn_press==0);
UART_Send_Str("按键被按下,开始发送....\n");
send_enable=1;
}
else send_enable=0;
if(send_enable)
{
send_enable=0;
// UART_Send_Str("开始发送....\n");
/*for(i=1;i<RF4432_TxBuf_Len;i++)
{
RF4432_TxBuf=RF4432_RxBuf;
}*/
RF4432_TxPacket();
RF4432_SetRxMode(); //设置成接收模式
UART_Send_Str("发送完毕,恢复到接收状态....\n");
}
}
}
|