基于51单片机的cc1100无线温度传输程序接收.docx
《基于51单片机的cc1100无线温度传输程序接收.docx》由会员分享,可在线阅读,更多相关《基于51单片机的cc1100无线温度传输程序接收.docx(26页珍藏版)》请在冰点文库上搜索。
基于51单片机的cc1100无线温度传输程序接收
#include
#include
#defineINT8Uunsignedchar
#defineINT16Uunsignedint
#defineWRITE_BURST0x40//连续写入
#defineREAD_SINGLE0x80//读
#defineREAD_BURST0xC0//连续读
#defineBYTES_IN_RXFIFO0x7F//接收缓冲区的有效字节数
#defineCRC_OK0x80//CRC校验通过位标志
//*****************************************************************************************
sbitGDO0=P1^3;
sbitGDO2=P3^2;
sbitMISO=P1^6;
sbitMOSI=P1^5;
sbitSCK=P1^7;
sbitCSN=P1^2;
//*****************************************************************************************
sbitLED2=P3^4;
sbitLED1=P3^5;
sbitKEY1=P3^6;
sbitKEY2=P3^7;
//*****************************************************************************************
sbitled3=P2^3;
sbitled2=P2^2;
sbitled1=P2^1;
sbitled0=P2^0;
chartemp[6];
INT8Useg[10]={0xC0,0xCF,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};//0~~9段码
INT8Useg1[10]={0x40,0x4F,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
INT8Udatatemp_data[2]={0x00,0x00};
INT8Udispaly[8];
//*****************************************************************************************
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);
voidStartUART(void);
voidR_S_Byte(INT8UR_Byte);
//*****************************************************************************************
//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