CC1101接收程序及相关电路图.docx

上传人:b****3 文档编号:4593720 上传时间:2022-12-07 格式:DOCX 页数:29 大小:45.31KB
下载 相关 举报
CC1101接收程序及相关电路图.docx_第1页
第1页 / 共29页
CC1101接收程序及相关电路图.docx_第2页
第2页 / 共29页
CC1101接收程序及相关电路图.docx_第3页
第3页 / 共29页
CC1101接收程序及相关电路图.docx_第4页
第4页 / 共29页
CC1101接收程序及相关电路图.docx_第5页
第5页 / 共29页
点击查看更多>>
下载资源
资源描述

CC1101接收程序及相关电路图.docx

《CC1101接收程序及相关电路图.docx》由会员分享,可在线阅读,更多相关《CC1101接收程序及相关电路图.docx(29页珍藏版)》请在冰豆网上搜索。

CC1101接收程序及相关电路图.docx

CC1101接收程序及相关电路图

相关电路

#include"main.h"

#include"cc1101.h"

#include"lcd1602.h"

voidmain(void)

{

inti;

UCHARleng=0;//待接收字节长度

UCHARTxBuf[8]={0};//8字节,如果需要更长的数据包,请正确设置

UCHARRxBuf[8]={0};//接收缓存区

InitLcd1602();

WriteAddressLcd1602(1,0);

WriteCharForLCD1602("TheCC1101Test!

");

WriteAddressLcd1602(2,0);

WriteCharForLCD1602("DesignbyXuJie!

");

Delaynms(6000);

ClearLcd1602();

CpuInit();

POWER_UP_RESET_CC1100();

halRfWriteRfSettings();

halSpiWriteBurstReg(CCxxx0_PATABLE,PaTabel,8);

TxBuf[0]=1;

TxBuf[1]=1;

TxBuf[2]=1;

TxBuf[3]=1;

TxBuf[4]=1;

TxBuf[2]=1;

TxBuf[6]=1;

TxBuf[7]=1;

halRfSendPacket(TxBuf,8);//TransmitTxbufferdata

delay(6000);

InitTimer0();

//显示格式

//Bulboverturnat

//*****SEClater!

WriteAddressLcd1602(1,0);

WriteCharForLCD1602("Bulboverturnat");

WriteAddressLcd1602(2,6);

WriteCharForLCD1602("SEClater!

");

while

(1)

{

led=1;//指示灯一直熄灭,只有接收到数据时才闪烁

leng=8;//预计接受8bytes

ResultToDisplay(SetTime);

WriteAddressLcd1602(2,0);

for(i=0;i<5;i++)

WriteLcd1602(1,DisplayResult[i]);

if(halRfReceivePacket(RxBuf,&leng))

{

if(RxBuf[1]==1)//确认,开始灭定时

{

led=0;

TR0=0;

TR1=1;

}

if(RxBuf[2]==1)

{//确认,开始亮定时

led=0;

TR0=1;

TR1=0;

}

if(RxBuf[3]==1)//时间加

{

led=0;

SetTime++;

}

if(RxBuf[4]==1)//时间减

{

led=0;

SetTime--;

}

if(RxBuf[5]==1)//灯亮

{

led=0;

bulb=0;

}

if(RxBuf[6]==1)//灯灭

{

led=0;

bulb=1;

}

delay(1000);

}

RxBuf[1]=0xff;//接收正确数据后复位数据,防止旧数据对新数据影响

RxBuf[2]=0xff;

RxBuf[3]=0xff;

RxBuf[4]=0xff;

RxBuf[5]=0xff;

RxBuf[6]=0xff;

}

}

/*---------------------------------------------

定时器0函数:

控制灯定时一定时间后点亮

---------------------------------------------*/

voidTimer0()interrupt1

{

TH0=(65536-50000)/256;//50ms定时,定时20次,12M晶振约为1s

TL0=(65536-50000)%256;

count0++;

if(20==count0)

{

count0=0;

time0++;

if(time0==SetTime)

{

time0=0;

led=0;

bulb=0;//定时时间到,灯亮

}

}

}

/*---------------------------------------------

定时器1函数:

控制灯点亮时定时一段时间后熄灭

---------------------------------------------*/

voidTimer1()interrupt3

{

TH1=(65536-50000)/256;//50ms定时,定时20次,12M晶振约为1s

TL1=(65536-50000)%256;

count1++;

if(20==count1)

{

count1=0;

time1++;

if(time1==SetTime)

{

time1=0;

led=0;

bulb=1;//定时时间到,灯灭

}

}

}

#ifndef_MAIN_H_

#define_MAIN_H_

#include

#include

#include

//宏定义

#defineUCHARunsignedchar

#defineUINTunsignedint

#defineULONGunsignedlong

sbitled=P2^2;//LED指示灯,每接收到字节闪烁一次p

sbitbulb=P2^0;

intSetTime=0;//定时时间,单位:

s

intcount0,count1,time0,time1;//定时器中断内部变量

UCHARDisplayResult[5];//全局显示结果数组

/**************************************************

函数功能:

延时函数:

延时nms

入口参数:

yms

***************************************************/

voidDelaynms(UINTy)

{

UINTx;

for(;y>0;y--)

for(x=110;x>0;x--);

}

/**************************************************

函数功能:

将长整型数据转换为字符数组形式以待显示

***************************************************/

voidResultToDisplay(intdat)

{

DisplayResult[4]=dat%10+0x30;

DisplayResult[3]=dat%100/10+0x30;

DisplayResult[2]=dat%1000/100+0x30;

DisplayResult[1]=dat%10000/1000+0x30;

DisplayResult[0]=dat%100000/10000+0x30;

}

/*---------------------------------------------

定时初始函数:

初始值50000=50ms

定时器0

---------------------------------------------*/

voidInitTimer0()

{

TMOD=0x11;//定时器0,定时器1工作方式1

TH0=(65536-50000)/256;//定时器0装初值

TL0=(65536-50000)%256;

TH1=(65536-50000)/256;//定时器1装初值

TL1=(65536-50000)%256;

EA=1;//开总中断

ET0=1;//开Timer0中断

ET1=1;

}

#endif

#ifndef_CC1101_H_

#define_CC1101_H_

#defineWRITE_BURST0x40//连续写入

#defineREAD_SINGLE0x80//读

#defineREAD_BURST0xC0//连续读

#defineBYTES_IN_RXFIFO0x7F//接收缓冲区的有效字节数

#defineCRC_OK0x80//CRC校验通过位标志

//***********************************

CC1100接口

*************************************************

sbitGDO0=P1^6;

sbitGDO2=P1^5;

sbitMISO=P1^2;

sbitMOSI=P1^3;

sbitSCK=P1^4;

sbitCSN=P1^1;

//***********************************按键********************************************************

//sbitKEY1=P0^0;

//sbitKEY2=P0^1;

//***********************************数码管位选**************************************************

//sbitled3=P2^0;

//sbitled2=P2^1;

//sbitled1=P2^2;

//sbitled0=P2^3;

//***********************************蜂鸣器*******************************************************

//sbitBELL=P3^4;

//***************更多功率参数设置可详细参考DATACC1100英文文档中第48-49页的参数表******************

//UCHARPaTabel[8]={0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04};//-30dBm功率最小

UCHARPaTabel[8]={0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60};//0dBm

//UCHARPaTabel[8]={0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0};//10dBm功率最大

//***********************************************************************************************

voidSpiInit(void);

voidCpuInit(void);

voidRESET_CC1100(void);

voidPOWER_UP_RESET_CC1100(void);

voidhalSpiWriteReg(UCHARaddr,UCHARvalue);

voidhalSpiWriteBurstReg(UCHARaddr,UCHAR*buffer,UCHARcount);

voidhalSpiStrobe(UCHARstrobe);

UCHARhalSpiReadReg(UCHARaddr);

voidhalSpiReadBurstReg(UCHARaddr,UCHAR*buffer,UCHARcount);

UCHARhalSpiReadStatus(UCHARaddr);

voidhalRfWriteRfSettings(void);

voidhalRfSendPacket(UCHAR*txBuffer,UCHARsize);

UCHARhalRfReceivePacket(UCHAR*rxBuffer,UCHAR*length);

//*****************************************************************************************

//CC1100STROBE,CONTROLANDSTATUSREGSITER

#defineCCxxx0_IOCFG20x00//GDO2outputpinconfiguration

#defineCCxxx0_IOCFG10x01//GDO1outputpinconfiguration

#defineCCxxx0_IOCFG00x02//GDO0outputpinconfiguration

#defineCCxxx0_FIFOTHR0x03//RXFIFOandTXFIFOthresholds

#defineCCxxx0_SYNC10x04//Syncword,highUCHAR

#defineCCxxx0_SYNC00x05//Syncword,lowUCHAR

#defineCCxxx0_PKTLEN0x06//Packetlength

#defineCCxxx0_PKTCTRL10x07//Packetautomationcontrol

#defineCCxxx0_PKTCTRL00x08//Packetautomationcontrol

#defineCCxxx0_ADDR0x09//Deviceaddress

#defineCCxxx0_CHANNR0x0A//Channelnumber

#defineCCxxx0_FSCTRL10x0B//Frequencysynthesizercontrol

#defineCCxxx0_FSCTRL00x0C//Frequencysynthesizercontrol

#defineCCxxx0_FREQ20x0D//Frequencycontrolword,highUCHAR

#defineCCxxx0_FREQ10x0E//Frequencycontrolword,middleUCHAR

#defineCCxxx0_FREQ00x0F//Frequencycontrolword,lowUCHAR

#defineCCxxx0_MDMCFG40x10//Modemconfiguration

#defineCCxxx0_MDMCFG30x11//Modemconfiguration

#defineCCxxx0_MDMCFG20x12//Modemconfiguration

#defineCCxxx0_MDMCFG10x13//Modemconfiguration

#defineCCxxx0_MDMCFG00x14//Modemconfiguration

#defineCCxxx0_DEVIATN0x15//Modemdeviationsetting

#defineCCxxx0_MCSM20x16//MainRadioControlStateMachineconfiguration

#defineCCxxx0_MCSM10x17//MainRadioControlStateMachineconfiguration

#defineCCxxx0_MCSM00x18//MainRadioControlStateMachineconfiguration

#defineCCxxx0_FOCCFG0x19//FrequencyOffsetCompensationconfiguration

#defineCCxxx0_BSCFG0x1A//BitSynchronizationconfiguration

#defineCCxxx0_AGCCTRL20x1B//AGCcontrol

#defineCCxxx0_AGCCTRL10x1C//AGCcontrol

#defineCCxxx0_AGCCTRL00x1D//AGCcontrol

#defineCCxxx0_WOREVT10x1E//HighUCHAREvent0timeout

#defineCCxxx0_WOREVT00x1F//LowUCHAREvent0timeout

#defineCCxxx0_WORCTRL0x20//WakeOnRadiocontrol

#defineCCxxx0_FREND10x21//FrontendRXconfiguration

#defineCCxxx0_FREND00x22//FrontendTXconfiguration

#defineCCxxx0_FSCAL30x23//Frequencysynthesizercalibration

#defineCCxxx0_FSCAL20x24//Frequencysynthesizercalibration

#defineCCxxx0_FSCAL10x25//Frequencysynthesizercalibration

#defineCCxxx0_FSCAL00x26//Frequencysynthesizercalibration

#defineCCxxx0_RCCTRL10x27//RCoscillatorconfiguration

#defineCCxxx0_RCCTRL00x28//RCoscillatorconfiguration

#defineCCxxx0_FSTEST0x29//Frequencysynthesizercalibrationcontrol

#defineCCxxx0_PTEST0x2A//Productiontest

#defineCCxxx0_AGCTEST0x2B//AGCtest

#defineCCxxx0_TEST20x2C//Varioustestsettings

#defineCCxxx0_TEST10x2D//Varioustestsettings

#defineCCxxx0_TEST00x2E//Varioustestsettings

//Strobecommands

#defineCCxxx0_SRES0x30//Resetchip.

#defineCCxxx0_SFSTXON0x31//Enableandcalibratefrequencysynthesizer(ifMCSM0.FS_AUTOCAL=1).

//IfinRX/TX:

Gotoawaitstatewhereonlythesynthesizeris

//running(forquickRX/TXturnaround).

#defineCCxxx0_SXOFF0x32//Turnoffcrystaloscillator.

#defineCCxxx0_SCAL0x33//Calibratefrequencysynthesizerandturnitoff

//(enablesquickstart).

#defineCCxxx0_SRX0x34//EnableRX.PerformcalibrationfirstifcomingfromIDLEand

//MCSM0.FS_AUTOCAL=1.

#defineCCxxx0_STX0x35//InIDLEstate:

EnableTX.Performcalibrationfirstif

//MCSM0.FS_AUTOCAL=1.IfinRXstateandCCAisenabled:

//OnlygotoTXifchannelisclear.

#defineCCxxx0_SIDLE0x36//ExitRX/TX,turnofffrequencysynthesizerandexit

//Wake-On-Radiomodeifapplicable.

#defineCCxxx0_SAFC0x37//PerformAFCadjustmentofthefrequencysynthesizer

#defineCCxxx0_SWOR0x38//StartautomaticRXpollingsequence(Wake-on-Radio)

#defineCCxxx0_SPWD0x39//EnterpowerdownmodewhenCSngoeshigh.

#defineCCxxx0_SFRX0x3A//FlushtheRXFIFObuffer.

#defineCCxxx0_SFTX0x3B//FlushtheTXFIFObuffer.

#defineCCxxx0_SWORRST0x3C//Resetrealtimeclock.

#defineCCxxx0_SNOP0x3D//Nooperation.Maybeusedtopadstrobecommandstotwo

//UCHARsforsimpler

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 初中教育 > 语文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1