#includereg52.h#includeintrins.h#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_F