您的位置 首页 观点

根据CC1101与STC89C52无线收发程序(接纳程序)

CC1101与STC89C52无线通讯接收程序:includereg52h>includeintrinsh>defineIOCFG20x00defineIOCFG10x01defineIO

CC1101STC89C52无线通讯接纳程序:

#include
#include

#define IOCFG2 0x00
#define IOCFG10x01
#define IOCFG00x02
#define FIFOTHR0x03//rx和tx FIFO门限
#define SYNC10x04//同步词汇,高字节
#define SYNC00x05//同步词汇,低字节
#define PKTLEN0x06//数据包长度
#define PKTCTRL10x07//数据包主动操控
#define PKTCTRL00x08//数据包主动操控
#define ADDR0x09//设备地址
#define CHANNR0x0a//信道数
#define FSCTRL10x0b//频率组成操控器
#define FSCTRL00x0c//频率操控词汇,高字节
#define FREQ20x0d//频率操控词汇,中心字节
#define FREQ10x0e//频率操控词汇,低字节
#define FREQ00x0f//调置器装备
#define MDMCFG40x10//调置器装备
#define MDMCFG30x11//调置器装备
#define MDMCFG20x12//调置器装备
#define MDMCFG10x13//调置器装备
#define MDMCFG00x14//调置器装备
#define DEVIATN0x15//主通讯操控状况机装备
#define MCSM20x16//主通讯操控状况机装备
#define MCSM10x17//主通讯操控状况机装备
#define MCSM00x18//频率偏移补偿装备
#define FOCCFG0x19//位同步装备
#define BSCFG0x1a//AGC操控
#define AGCCTRL20x1b//AGC操控
#define AGCCTRL10x1c//AGC操控
#define AGCCTRL00x1d//高字节时刻0暂停
#define WOREVT10x1e//低字节时刻0暂停
#define WOREVT00x1f//电磁波激活操控
#define WORCTRL0x20//前结尾RX装备
#define FREND10x21//前结尾TX装备
#define FREND00x22//频率组成器校准
#define FSCAL30x23//频率组成器校准
#define FSCAL20x24//频率组成器校准
#define FSCAL10x25//频率组成器校准
#define FSCAL00x26//RC振荡器装备
#define RCCTRL10x27//RC振荡器装备
#define RCCTRL00x28//频率组成器校准操控
#define FSTEST0x29//产品测验
#define PTEST0x2a//AGC测验
#define AGCTEST0x2b//不同的测验设置
#define TEST20x2c//不同的测验设置
#define TEST10x2d//不同的测验设置
#define TEST00x2e//

#define SRES0x30//重启芯片
#defineSFSTXON0x31//敞开和校准频率组成器
#define SXOFF0x32//封闭晶体振荡器
#define SCAL0x33//校准频率组成器并判别
#define SRX0x34//启用SRX
#define STX0x35//闲暇状况:启用STX
#define SIDLE0x36//脱离RX/TX,关断频率组成器
#define SAFC0x37//频率组成器AFC调理
#define SWOR0x38//主动RX推举序列(电磁波激活)
#define SPWD0x39//当CSN为高时进入功率下降形式
#define SFRX0x3a//冲刷RX FIFO缓存
#define SFTX0x3b//冲刷TX FIFO缓存
#define SWORRST0x3c//从头设置实在时刻时钟
#define SNOP0x3d//无操作

#define PARTNUM0x30//CC2550组成部分数目
#define VERSION0x31//当时版本数
#define FREQEST0x32//频率偏移估量
#define LQI0x33//衔接质量的解调器估量
#define RSSI0x34//接纳信号强度指示
#define MARCSTATE0x35//操控状况机状况
#define WORTIME10x36//WOR计时器高字节
#define WORTIME00x37//WOR计时器低字节
#define PKTSTATUS0x38//当时GDOx状况和数据包状况
#define VCO_VC_DAC0x39//PLL校准模块的当时设定
#define TXBYTES0x3a//TX FIFO中的下溢和比特数
#define RXBYTES0x3b//RX FIFO中的下溢和比特数
#define PATABLE0x3e
#define TX_FIFO0x3f
#define RX_FIFO0x3f
#define data_len8

typedef unsigned intuint;
typedef unsigned charuchar;

uchar rx_buffer[data_len]={0,0,0,0,0,0,0,0};//rx data
//uchar const code TX_Buffer[data_len]={0x02,0x55};//tx data
uchar data_length=0;
uchar code P_Config[]={0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0};//功率装备

sbit CSN=P2^1;
sbit SCLK=P2^7;
sbit SI=P2^2;
sbit SO=P2^0;
sbit GDO0=P2^6;

sbit LED=P0^0;
sbit LED1=P0^6;

void CC1101_Init(void);
void CC1101_RESET(void);
void POWER_UP_RESET(void);
uchar SPI_WR_Byte(uchar value);
void SPI_Write_Byte(uchar addr,uchar value);
uchar SPI_Read_Byte(uchar addr);
void SPI_Write_Strobe(uchar strobe);
void SPI_Write_Burst(uchar addr,uchar *buffer,uchar count);
void SPI_Read_Burst(uchar addr,uchar *buffer,uchar count);
void SPI_Write_Packet(uchar *TX_Buffer,uchar size);
uchar SPI_Read_Packet(uchar *RX_Buffer,uchar length);
void CC1101_Set_TX(void);
void CC1101_Set_RX(void);
void Write_Config(void);

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,status=0;
SCLK=0;
for(i=0;i<8;i++)
{
if(value&0x80)
SI=1;
else
SI=0;
value<<=1;
SCLK=1;
status<<=1;
_nop_();_nop_();

if(SO)
status|=0x01;
SCLK=0;
_nop_();_nop_();
}
return status;
}
//————————————————–/
//函数功用:重置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)
{
//uchar i;
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(SFRX);
//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]);
//LED=~LED;
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);
while(GDO0);
//LED1=~LED1;
SPI_Write_Strobe(SIDLE);
SPI_Write_Strobe(SFTX);

}

uchar SPI_Read_Packet(uchar *RX_Buffer,uchar length)
{
uchar status[2];
uchar size=0;
SPI_Write_Strobe(SRX);
delay_ms(10);
if(SPI_Read_Status(RXBYTES)==0) return 0;
while(GDO0)
{
SPI_Write_Strobe(SIDLE);
return 0;
}
size=SPI_Read_Byte(RX_FIFO);
if(size==length)
{
SPI_Read_Burst(RX_FIFO,RX_Buffer,size);
SPI_Read_Burst(RX_FIFO,status,2);
SPI_Write_Strobe(SFRX);
return(status[1]&0x80);
}
else
{
SPI_Write_Strobe(SIDLE);
SPI_Write_Strobe(SFRX);
return 0;
}

}

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);//mark
SPI_Write_Byte(FSCAL2,0x0a);//mark
//SPI_Write_Byte(FSCAL1,0x00);//
SPI_Write_Byte(FSCAL0,0x1f);//mark
//SPI_Write_Byte(RCCTRL1 , 0x41);//
//SPI_Write_Byte(RCCTRL0 , 0x00);//
SPI_Write_Byte(FSTEST,0x59);//mark
//SPI_Write_Byte(PTEST ,0x7f);//
SPI_Write_Byte(TEST2,0x81);//mark
SPI_Write_Byte(TEST1,0x35);//mark
SPI_Write_Byte(TEST0,0x09);//mark



}
void main(void)
{
uchar i,j=0;
CC1101_Init();
delay_ms(100);
while(1)
{
if(SPI_Read_Packet(rx_buffer,sizeof(rx_buffer)))
{
//LED=0;
for(i=0;i{
P0=rx_buffer[i];
delay_ms(100);
}
}
//else
//SPI_Write_Strobe(SFRX);
}
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/news/guandian/257770.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部