新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > STC89C52單片機驅動CC1101無線模塊的接收C語言程序

        STC89C52單片機驅動CC1101無線模塊的接收C語言程序

        作者: 時間:2016-11-30 來源:網絡 收藏
        const RF_SETTINGS rfSettings ={0x00,0x08, // FSCTRL1 Frequency synthesizer control.0x00, // FSCTRL0 Frequency synthesizer control.0x10, // FREQ2 Frequency control word, high byte.0xA7, // FREQ1 Frequency control word, middle byte.0x62, // FREQ0 Frequency control word, low byte.0x5B, // MDMCFG4 Modem configuration.0xF8, // MDMCFG3 Modem configuration.0x03, // MDMCFG2 Modem configuration.0x22, // MDMCFG1 Modem configuration.0xF8, // MDMCFG0 Modem configuration.0x00, // CHANNR Channel number.0x47, // DEVIATN Modem deviation setting (when FSK modulation is enabled).0xB6, // FREND1 Front end RX configuration.0x10, // FREND0 Front end RX configuration.0x18, // MCSM0 Main Radio Control State Machine configuration.0x1D, // FOCCFG Frequency Offset Compensation Configuration.0x1C, // BSCFG Bit synchronization Configuration.0xC7, // AGCCTRL2 AGC control.0x00, // AGCCTRL1 AGC control.0xB2, // AGCCTRL0 AGC control.0xEA, // FSCAL3 Frequency synthesizer calibration.0x2A, // FSCAL2 Frequency synthesizer calibration.0x00, // FSCAL1 Frequency synthesizer calibration.0x11, // FSCAL0 Frequency synthesizer calibration.0x59, // FSTEST Frequency synthesizer calibration.0x81, // TEST2 Various test settings.0x35, // TEST1 Various test settings.0x09, // TEST0 Various test settings.0x0B, // IOCFG2 GDO2 output pin configuration.0x06, // IOCFG0D GDO0 output pin configuration. Refer to SmartRF?Studio User Manual for detailed pseudo register explanation.0x04, // PKTCTRL1 Packet automation control.0x05, // PKTCTRL0 Packet automation control.0x00, // ADDR Device address.0x0c // PKTLEN Packet length.};//***************************//函數名:delay(unsigned int s)//輸入:時間//輸出:無//功能描述:普通廷時,內部用//****************************static void delay(unsigned int s){unsigned int i;for(i=0; i0;i--); }void halWait(INT16U timeout) {do {_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();} while (--timeout);}void SpiInit(void){CSN=0;SCK=0;CSN=1;}/*****************************//函數名:CpuInit()//輸入:無//輸出:無//功能描述:SPI初始化程序/*************************************/void CpuInit(void){SpiInit();delay(5000);}//*************************************//函數名:SpisendByte(INT8U dat)//輸入:發送的數據//輸出:無//功能描述:SPI發送一個字節//*************************************INT8U SpiTxRxByte(INT8U dat){INT8U i,temp;temp = 0;SCK = 0;for(i=0; i<8; i++){if(dat & 0x80){MOSI = 1;}else MOSI = 0;dat <<= 1;SCK = 1;_nop_();_nop_();temp <<= 1;if(MISO)temp++;SCK = 0;_nop_();_nop_();}return temp;}//*************************************//函數名:void RESET_CC1100(void)//輸入:無//輸出:無//功能描述:復位CC1100//*************************************void RESET_CC1100(void){CSN = 0;while (MISO);SpiTxRxByte(CCxxx0_SRES); //寫入復位命令while (MISO);CSN = 1;}//************************************//函數名:void POWER_UP_RESET_CC1100(void)//輸入:無//輸出:無//功能描述:上電復位CC1100//**********************************void POWER_UP_RESET_CC1100(void){CSN = 1;halWait(1);CSN = 0;halWait(1);CSN = 1;halWait(41);RESET_CC1100(); //復位CC1100}//*************************************//函數名:void halSpiWriteReg(INT8U addr, INT8U value)//輸入:地址和配置字//輸出:無//功能描述:SPI寫寄存器//************************************void halSpiWriteReg(INT8U addr, INT8U value){CSN = 0;while (MISO);SpiTxRxByte(addr);//寫地址SpiTxRxByte(value);//寫入配置CSN = 1;}//***********************************//函數名:void halSpiWriteBurstReg(INT8U addr, INT8U *buffer, INT8U count)//輸入:地址,寫入緩沖區,寫入個數//輸出:無//功能描述:SPI連續寫配置寄存器//**********************************void halSpiWriteBurstReg(INT8U addr, INT8U *buffer, INT8U count){INT8U i, temp;temp = addr | WRITE_BURST;CSN = 0;while (MISO);SpiTxRxByte(temp);for (i = 0; i < count; i++){SpiTxRxByte(buffer[i]);}CSN = 1;}//*******************************//函數名:void halSpiStrobe(INT8U strobe)//輸入:命令//輸出:無//功能描述:SPI寫命令//******************************void halSpiStrobe(INT8U strobe){CSN = 0;while (MISO);SpiTxRxByte(strobe);//寫入命令CSN = 1;}//***********************************//函數名:INT8U halSpiReadReg(INT8U addr)//輸入:地址//輸出:該寄存器的配置字//功能描述:SPI讀寄存器//**********************************INT8U halSpiReadReg(INT8U addr){INT8U temp, value;temp = addr|READ_SINGLE;//讀寄存器命令CSN = 0;while (MISO);SpiTxRxByte(temp);value = SpiTxRxByte(0);CSN = 1;return value;}//**********************************//函數名:void halSpiReadBurstReg(INT8U addr, INT8U *buffer, INT8U count)//輸入:地址,讀出數據后暫存的緩沖區,讀出配置個數//輸出:無//功能描述:SPI連續寫配置寄存器//*********************************

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 沙坪坝区| 尼玛县| 淮南市| 临澧县| 嘉定区| 铜陵市| 德庆县| 凤冈县| 湟源县| 区。| 广德县| 启东市| 扎鲁特旗| 临汾市| 山西省| 前郭尔| 六盘水市| 京山县| 东源县| 诏安县| 皮山县| 乳山市| 德化县| 海兴县| 固始县| 满城县| 东安县| 出国| 怀远县| 惠州市| 中西区| 沂源县| 改则县| 庆阳市| 柏乡县| 方山县| 麻阳| 都兰县| 鲁甸县| 绿春县| 新竹县|