微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 基于CC1101与STC89C52无线收发程序(发射程序)

基于CC1101与STC89C52无线收发程序(发射程序)

时间:11-27 来源:互联网 点击:

void delay_ms(uint x)
{
uint i;
while(x--)for(i=0;i<120;i++);
}

void delay_us(uint x)
{
do {
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
} while (--x);
}
//------------------------------------------------/
//函数功能:通过SPI写读一字节/
//输入参数:value/
//输出参数:B_value/
//-----------------------------------------------/
uchar SPI_WR_Byte(uchar value)
{
uchar i,B_value=0;
SCLK=0;
for(i=0;i<8;i++)
{
if(value&0x80)
SI=1;
else
SI=0;
value<=1;
SCLK=1;
_nop_();_nop_();
B_value<=1;
if(SO)
B_value|=0x01;
SCLK=0;
_nop_();_nop_();
}
return B_value;
}
//-------------------------------------------------/
//函数功能:重置CC1101/
//输入参数:无/
//输出参数:无/
//----------------------------------------------/
void CC1101_RESET(void)
{
SPI_Write_Strobe(SIDLE);
CSN=0;
while(SO);
SPI_WR_Byte(SRES);
while(SO);
CSN=1;
}
//-----------------------------------------------/
//函数功能:CC1101上电重置/
//输入参数:无/
//输出参数:无/
//--------------------------------------------/
void POWER_UP_RESET(void)
{

CSN=1;
delay_us(1);
CSN=0;
delay_us(1);
CSN=1;
delay_us(41);
CC1101_RESET();
}

//-----------------------------------------------/
//函数功能:CC1101初始化/
//输入参数:无/
//输出参数:无/
//--------------------------------------------/
void CC1101_Init(void)
{
CSN=0;
SCLK=0;
CSN=1;
delay_ms(10);
POWER_UP_RESET();
Write_Config();
SPI_Write_Burst(PATABLE,P_Config,8);
SPI_Write_Strobe(SCAL);
SPI_Write_Strobe(SIDLE);
SPI_Write_Strobe(SFTX);
//for(i=0;i<100;i++)
//SPI_Write_Strobe(SNOP);
//SPI_Write_Strobe(SIDLE);
//SPI_Write_Strobe(SRX);
}
//-----------------------------------------------/
//函数功能:SPI写命令/
//输入参数:Strobe/
//输出参数:无/
//---------------------------------------------/
void SPI_Write_Strobe(uchar strobe)
{
CSN=0;
while(SO);
SPI_WR_Byte(strobe);
CSN=1;
}

uchar SPI_Read_Byte(uchar addr)
{
uchar value;
CSN=0;
while(SO);
SPI_WR_Byte(addr|0x80);
value=SPI_WR_Byte(0);
CSN=1;
return value;
}
void SPI_Write_Byte(uchar addr,uchar value)
{
CSN=0;
while(SO);
SPI_WR_Byte(addr);
SPI_WR_Byte(value);
CSN=1;
}

void SPI_Write_Burst(uchar addr,uchar *buffer,uchar count)
{
uchar i;
CSN=0;
while(SO);
SPI_WR_Byte(addr|0x40);
for(i=0;i{
SPI_WR_Byte(buffer[i]);
delay_us(10);
}
CSN=1;
}

void SPI_Read_Burst(uchar addr,uchar *buffer,uchar count)
{
uchar i;
CSN=0;
while(SO);
SPI_WR_Byte(addr|0xc0);
for(i=0;ibuffer[i]=SPI_WR_Byte(0);
CSN=1;
}

uchar SPI_Read_Status(uchar addr)
{
uchar value;
CSN=0;
while(SO);
SPI_WR_Byte(addr|0xc0);//
value=SPI_WR_Byte(0);
CSN=1;
return value;
}

void SPI_Write_Packet(uchar *TX_Buffer,uchar size)
{
//uchar j;

SPI_Write_Byte(TX_FIFO,size);
SPI_Write_Burst(TX_FIFO,TX_Buffer,size);
SPI_Write_Strobe(STX);
while(!GDO0);
LED=1;
while(GDO0);
LED=0;
SPI_Write_Strobe(SIDLE);
SPI_Write_Strobe(SFTX);

}

void Write_Config(void)
{
SPI_Write_Byte(IOCFG2,0x0b);//

SPI_Write_Byte(IOCFG0,0x06);//

SPI_Write_Byte(FIFOTHR,0x07);//
//SPI_Write_Byte(SYNC1,0xd3);//
//SPI_Write_Byte(SYNC0,0x91);//
SPI_Write_Byte(PKTLEN,0xff);//
SPI_Write_Byte(PKTCTRL1, 0x04);//
SPI_Write_Byte(PKTCTRL0, 0x05);//
//SPI_Write_Byte(ADDR,0x01);//
//SPI_Write_Byte(CHANNR,0x00);//
SPI_Write_Byte(FSCTRL1,0x06);//
SPI_Write_Byte(FSCTRL0,0x00);//
SPI_Write_Byte(FREQ2,0x10);//
SPI_Write_Byte(FREQ1,0xb0);//
SPI_Write_Byte(FREQ0,0x71);//
SPI_Write_Byte(MDMCFG4,0x2d);//
SPI_Write_Byte(MDMCFG3,0x3b);//
SPI_Write_Byte(MDMCFG2,0x71);//
SPI_Write_Byte(MDMCFG1,0xa2);//
SPI_Write_Byte(MDMCFG0,0xf8);//
SPI_Write_Byte(DEVIATN,0x15);//
//SPI_Write_Byte(MCSM2 ,0x07);//
SPI_Write_Byte(MCSM1 ,0x30);//
SPI_Write_Byte(MCSM0 ,0x18);//

SPI_Write_Byte(FOCCFG,0x16);//
SPI_Write_Byte(BSCFG,0x6c);//
SPI_Write_Byte(AGCCTRL2, 0x03);//
//SPI_Write_Byte(AGCCTRL1, 0x00);//
SPI_Write_Byte(AGCCTRL0, 0x91);//
//SPI_Write_Byte(WOREVT1 , 0x87);//
//SPI_Write_Byte(WOREVT0 , 0x6b);//
//SPI_Write_Byte(WORCTRL,0xf8);//
SPI_Write_Byte(FREND1,0x56);//
SPI_Write_Byte(FREND0,0x10);//



SPI_Write_Byte(FSCAL3,0xe9);//
SPI_Write_Byte(FSCAL2,0x0a);//
//SPI_Write_Byte(FSCAL1,0x00);//
SPI_Write_Byte(FSCAL0,0x1f);//
//SPI_Write_Byte(RCCTRL1 , 0x41);//
//SPI_Write_Byte(RCCTRL0 , 0x00);//
SPI_Write_Byte(FSTEST,0x59);//
//SPI_Write_Byte(PTEST ,0x7f);//
SPI_Write_Byte(TEST2,0x81);//
SPI_Write_Byte(TEST1,0x35);//
SPI_Write_Byte(TEST0,0x09);//

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top