基于51的CC1101 接收程序.docx

上传人:b****5 文档编号:30737231 上传时间:2023-08-20 格式:DOCX 页数:23 大小:19.14KB
下载 相关 举报
基于51的CC1101 接收程序.docx_第1页
第1页 / 共23页
基于51的CC1101 接收程序.docx_第2页
第2页 / 共23页
基于51的CC1101 接收程序.docx_第3页
第3页 / 共23页
基于51的CC1101 接收程序.docx_第4页
第4页 / 共23页
基于51的CC1101 接收程序.docx_第5页
第5页 / 共23页
点击查看更多>>
下载资源
资源描述

基于51的CC1101 接收程序.docx

《基于51的CC1101 接收程序.docx》由会员分享,可在线阅读,更多相关《基于51的CC1101 接收程序.docx(23页珍藏版)》请在冰豆网上搜索。

基于51的CC1101 接收程序.docx

基于51的CC1101接收程序

#include

#include

#defineINT8Uunsignedchar

#defineINT16Uunsignedint

#defineWRITE_BURST0x40//连续写入

#defineREAD_SINGLE0x80//读

#defineREAD_BURST0xC0//连续读

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

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

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

sbitCSN=P2^0;

sbitGDO0=P2^1;

sbitGDO2=P2^3;

sbitMISO=P2^4;

sbitSCK=P2^5;

sbitMOSI=P2^6;

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

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

sbitled0=P0^0;

sbitled1=P0^1;

sbitled2=P0^2;

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

//INT8UPaTabel[8]={0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60};

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

voidSpiInit(void);

voidCpuInit(void);

voidRESET_CC1100(void);

voidPOWER_UP_RESET_CC1100(void);

voidhalSpiWriteReg(INT8Uaddr,INT8Uvalue);

voidhalSpiWriteBurstReg(INT8Uaddr,INT8U*buffer,INT8Ucount);

voidhalSpiStrobe(INT8Ustrobe);

INT8UhalSpiReadReg(INT8Uaddr);

voidhalSpiReadBurstReg(INT8Uaddr,INT8U*buffer,INT8Ucount);

INT8UhalSpiReadStatus(INT8Uaddr);

voidhalRfWriteRfSettings(void);

voidhalRfSendPacket(INT8U*txBuffer,INT8Usize);

INT8UhalRfReceivePacket(INT8U*rxBuffer,INT8U*length);

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

//CC1100STROBE,CONTROLANDSTATUSREGSITER

#defineCCxxx0_IOCFG20x00//GDO2outputpinconfiguration

#defineCCxxx0_IOCFG10x01//GDO1outputpinconfiguration

#defineCCxxx0_IOCFG00x02//GDO0outputpinconfiguration

#defineCCxxx0_FIFOTHR0x03//RXFIFOandTXFIFOthresholds

#defineCCxxx0_SYNC10x04//Syncword,highINT8U

#defineCCxxx0_SYNC00x05//Syncword,lowINT8U

#defineCCxxx0_PKTLEN0x06//Packetlength

#defineCCxxx0_PKTCTRL10x07//Packetautomationcontrol

#defineCCxxx0_PKTCTRL00x08//Packetautomationcontrol

#defineCCxxx0_ADDR0x09//Deviceaddress

#defineCCxxx0_CHANNR0x0A//Channelnumber

#defineCCxxx0_FSCTRL10x0B//Frequencysynthesizercontrol

#defineCCxxx0_FSCTRL00x0C//Frequencysynthesizercontrol

#defineCCxxx0_FREQ20x0D//Frequencycontrolword,highINT8U

#defineCCxxx0_FREQ10x0E//Frequencycontrolword,middleINT8U

#defineCCxxx0_FREQ00x0F//Frequencycontrolword,lowINT8U

#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//HighINT8UEvent0timeout

#defineCCxxx0_WOREVT00x1F//LowINT8UEvent0timeout

#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

//INT8Usforsimplersoftware.

#defineCCxxx0_PARTNUM0x30

#defineCCxxx0_VERSION0x31

#defineCCxxx0_FREQEST0x32

#defineCCxxx0_LQI0x33

#defineCCxxx0_RSSI0x34

#defineCCxxx0_MARCSTATE0x35

#defineCCxxx0_WORTIME10x36

#defineCCxxx0_WORTIME00x37

#defineCCxxx0_PKTSTATUS0x38

#defineCCxxx0_VCO_VC_DAC0x39

#defineCCxxx0_TXBYTES0x3A

#defineCCxxx0_RXBYTES0x3B

#defineCCxxx0_PATABLE0x3E

#defineCCxxx0_TXFIFO0x3F

#defineCCxxx0_RXFIFO0x3F

//RF_SETTINGSisadatastructurewhichcontainsallrelevantCCxxx0registers

typedefstructS_RF_SETTINGS

{

INT8UFSCTRL2;//自已加的

INT8UFSCTRL1;//Frequencysynthesizercontrol.

INT8UFSCTRL0;//Frequencysynthesizercontrol.

INT8UFREQ2;//Frequencycontrolword,highINT8U.

INT8UFREQ1;//Frequencycontrolword,middleINT8U.

INT8UFREQ0;//Frequencycontrolword,lowINT8U.

INT8UMDMCFG4;//Modemconfiguration.

INT8UMDMCFG3;//Modemconfiguration.

INT8UMDMCFG2;//Modemconfiguration.

INT8UMDMCFG1;//Modemconfiguration.

INT8UMDMCFG0;//Modemconfiguration.

INT8UCHANNR;//Channelnumber.

INT8UDEVIATN;//Modemdeviationsetting(whenFSKmodulationisenabled).

INT8UFREND1;//FrontendRXconfiguration.

INT8UFREND0;//FrontendRXconfiguration.

INT8UMCSM0;//MainRadioControlStateMachineconfiguration.

INT8UFOCCFG;//FrequencyOffsetCompensationConfiguration.

INT8UBSCFG;//BitsynchronizationConfiguration.

INT8UAGCCTRL2;//AGCcontrol.

INT8UAGCCTRL1;//AGCcontrol.

INT8UAGCCTRL0;//AGCcontrol.

INT8UFSCAL3;//Frequencysynthesizercalibration.

INT8UFSCAL2;//Frequencysynthesizercalibration.

INT8UFSCAL1;//Frequencysynthesizercalibration.

INT8UFSCAL0;//Frequencysynthesizercalibration.

INT8UFSTEST;//Frequencysynthesizercalibrationcontrol

INT8UTEST2;//Varioustestsettings.

INT8UTEST1;//Varioustestsettings.

INT8UTEST0;//Varioustestsettings.

INT8UIOCFG2;//GDO2outputpinconfiguration

INT8UIOCFG0;//GDO0outputpinconfiguration

INT8UPKTCTRL1;//Packetautomationcontrol.

INT8UPKTCTRL0;//Packetautomationcontrol.

INT8UADDR;//Deviceaddress.

INT8UPKTLEN;//Packetlength.

}RF_SETTINGS;

/////////////////////////////////////////////////////////////////

constRF_SETTINGSrfSettings=

{

0x00,

0x08,//FSCTRL1Frequencysynthesizercontrol.

0x00,//FSCTRL0Frequencysynthesizercontrol.

0x10,//FREQ2Frequencycontrolword,highbyte.

0xA7,//FREQ1Frequencycontrolword,middlebyte.

0x62,//FREQ0Frequencycontrolword,lowbyte.

0x5B,//MDMCFG4Modemconfiguration.

0xF8,//MDMCFG3Modemconfiguration.

0x03,//MDMCFG2Modemconfiguration.

0x22,//MDMCFG1Modemconfiguration.

0xF8,//MDMCFG0Modemconfiguration.

0x00,//CHANNRChannelnumber.

0x47,//DEVIATNModemdeviationsetting(whenFSKmodulationisenabled).

0xB6,//FREND1FrontendRXconfiguration.

0x10,//FREND0FrontendRXconfiguration.

0x18,//MCSM0MainRadioControlStateMachineconfiguration.

0x1D,//FOCCFGFrequencyOffsetCompensationConfiguration.

0x1C,//BSCFGBitsynchronizationConfiguration.

0xC7,//AGCCTRL2AGCcontrol.

0x00,//AGCCTRL1AGCcontrol.

0xB2,//AGCCTRL0AGCcontrol.

0xEA,//FSCAL3Frequencysynthesizercalibration.

0x2A,//FSCAL2Frequencysynthesizercalibration.

0x00,//FSCAL1Frequencysynthesizercalibration.

0x11,//FSCAL0Frequencysynthesizercalibration.

0x59,//FSTESTFrequencysynthesizercalibration.

0x81,//TEST2Varioustestsettings.

0x35,//TEST1Varioustestsettings.

0x09,//TEST0Varioustestsettings.

0x0B,//IOCFG2GDO2outputpinconfiguration.

0x06,//IOCFG0DGDO0outputpinconfiguration.RefertoSmartRF?

StudioUserManualfordetailedpseudoregisterexplanation.

0x04,//PKTCTRL1Packetautomationcontrol.

0x05,//PKTCTRL0Packetautomationcontrol.

0x00,//ADDRDeviceaddress.

0x0c//PKTLENPacketlength.

};

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

//函数名:

delay(unsignedints)

//输入:

时间

//输出:

//功能描述:

普通廷时,内部用

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

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

当前位置:首页 > 小学教育 > 语文

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

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