久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3821|回復: 1
收起左側

51單片機驅動si4432程序

[復制鏈接]
ID:82008 發表于 2015-6-4 14:17 | 顯示全部樓層 |閱讀模式
  1. #include "radio.h"
  2. #include"spi.h"
  3. #include"uart.h"
  4. #define TxGPIOSetting()   SpiWriteRegister(0x0E, 0x02)
  5. #define RxGPIOSetting()   SpiWriteRegister(0x0E, 0x01)
  6. #define IdleGPIOSetting() SpiWriteRegister(0x0E, 0x01)
  7. void RF_init(void)
  8. {
  9.         //Set the physical parameters
  10.         //Frequency:       433MHz
  11.         //Modulation type: GFSK
  12.         //CrytalTolerance: Rx,10ppm; Tx, 10ppm
  13.         //Data rate:       9.6Kbps/1.2Kbps
  14.         //AFC:             Enable
  15.         //Frequency deviation: 20KHz

  16.         //set the center frequency to 433 MHz
  17.         SpiWriteRegister(0x75, 0x53);                                                                                                                        //write data to the Frequency Band Select register            
  18.         SpiWriteRegister(0x76, 0x4B);                                                                                                                        //write data to the Nominal Carrier Frequency1 register
  19.         SpiWriteRegister(0x77, 0x00);                                                                                                                          //write data to the Nominal Carrier Frequency0 register

  20.         //set the desired TX data rate (1.2kbps)
  21.         SpiWriteRegister(0x6E, 0x09);                                                                                                                        //write data to the TXDataRate 1 register
  22.         SpiWriteRegister(0x6F, 0xD5);                                                                                                                        //write data to the TXDataRate 0 register
  23.         SpiWriteRegister(0x70, 0x2C);                                                                                                                        //write data to the Modulation Mode Control 1 register
  24.         SpiWriteRegister(0x58, 0x80);

  25.         //set the TX power to MAX. dBm
  26.         SpiWriteRegister(0x6D, 0x1F);                                                                                                                        //write data to the TX Power register

  27.         //set the Tx deviation register (+-20kHz)
  28.         SpiWriteRegister(0x72, 0x20);                                                                                                                        //write data to the Frequency Deviation register

  29.                                                                 /*set the modem parameters according to the exel calculator(parameters: 1.2 kbps, deviation: 20 kHz*/
  30.         SpiWriteRegister(0x1C, 0x2C);                                                                                                                        //write data to the IF Filter Bandwidth register               
  31.         SpiWriteRegister(0x20, 0x41);                                                                                                                        //write data to the Clock Recovery Oversampling Ratio register               
  32.         SpiWriteRegister(0x21, 0x60);                                                                                                                        //write data to the Clock Recovery Offset 2 register               
  33.         SpiWriteRegister(0x22, 0x27);                                                                                                                        //write data to the Clock Recovery Offset 1 register               
  34.         SpiWriteRegister(0x23, 0x52);                                                                                                                        //write data to the Clock Recovery Offset 0 register               
  35.         SpiWriteRegister(0x24, 0x00);                                                                                                                        //write data to the Clock Recovery Timing Loop Gain 1 register               
  36.         SpiWriteRegister(0x25, 0x04);                                                                                                                        //write data to the Clock Recovery Timing Loop Gain 0 register               
  37.         SpiWriteRegister(0x1D, 0x40);                                                                                                                        //write data to the AFC Loop Gearshift Override register               
  38.         SpiWriteRegister(0x1E, 0x0A);
  39.         SpiWriteRegister(0x2A, 0x0F);                                                                                                                        //write data to the AFC Limiter register               
  40.         SpiWriteRegister(0x1F, 0x03);
  41.         SpiWriteRegister(0x69, 0x60);
  42.        
  43.                                                         /*set the packet structure and the modulation type*/
  44.         //set the preamble length to 10bytes if the antenna diversity is used and set to 5bytes if not
  45.         SpiWriteRegister(0x34, 0x0C);                                                                                                                        //write data to the Preamble Length register
  46.         //set preamble detection threshold to 20bits
  47.         SpiWriteRegister(0x35, 0x2A);                                                                                                                         //write data to the Preamble Detection Control  register

  48.         //Disable header bytes; set variable packet length (the length of the payload is defined by the
  49.         //received packet length field of the packet); set the synch word to two bytes long
  50.         SpiWriteRegister(0x33, 0x02);                                                                                                                        //write data to the Header Control2 register   
  51.        
  52.         //Set the sync word pattern to 0x2DD4
  53.         SpiWriteRegister(0x36, 0x2D);                                                                                                                        //write data to the Sync Word 3 register
  54.         SpiWriteRegister(0x37, 0xD4);                                                                                                                        //write data to the Sync Word 2 register

  55.         //enable the TX & RX packet handler and CRC-16 (IBM) check
  56.         SpiWriteRegister(0x30, 0x8D);                                                                                                                        //write data to the Data Access Control register
  57.         //Disable the receive header filters
  58.            SpiWriteRegister(0x32, 0x00 );                                                                                                                        //write data to the Header Control1 register            

  59.         //enable FIFO mode and GFSK modulation
  60.         SpiWriteRegister(0x71, 0x63);                                                                                                                        //write data to the Modulation Mode Control 2 register

  61.                                                                                         /*set the GPIO's according the testcard type*/
  62.            SpiWriteRegister(0x0B, 0xCA);                                                                                                                        //Set GPIO0 output
  63.            SpiWriteRegister(0x0C, 0xCA);                                                                                                                        //Set GPIO1 output
  64.            SpiWriteRegister(0x0D, 0xCA);                                                                                                                //Set GPIO2 output Rx Data

  65.         //set  Crystal Oscillator Load Capacitance register
  66.         SpiWriteRegister(0x09, CRYSTAL_CAPACITANCE);                                                                                        //write data to the Crystal Oscillator Load Capacitance register
  67. }

  68. idata U8 ItStatus1,ItStatus2;

  69. //------------------------------------------------------------------------------------------------
  70. // Function Name :RFSetRxMode
  71. //
  72. // Return Value : None
  73. // Parameters   : None
  74. // Notes        : 設置模塊工作在接收狀態下,當一切準備好的時候,調用該函數可以讓模塊工作于接收模式下
  75. //
  76. //-----------------------------------------------------------------------------------------------
  77. void RFSetRxMode(void)
  78. {  
  79.         //read interrupt status registers to release all pending interrupts
  80.         ItStatus1 = SpiReadRegister(0x03);                                                                                                            //read the Interrupt Status1 register
  81.         ItStatus2 = SpiReadRegister(0x04);                                                                                                            //read the Interrupt Status2 register

  82.         //Set the Rx switcher,利用GPIO口控制模塊內部的天線開關。
  83.         RxGPIOSetting();

  84.         /*enable receiver chain*/
  85.         SpiWriteRegister(0x07, 0x05);  
  86. }

  87. //------------------------------------------------------------------------------------------------
  88. // Function Name :RFSetTxMode
  89. //
  90. // Return Value : None
  91. // Parameters   : None
  92. // Notes        : 設置模塊工作在接收狀態下,當一切準備好的時候,調用該函數可以讓模塊工作于發射狀態模式下
  93. //
  94. //-----------------------------------------------------------------------------------------------
  95. void RFSetTxMode(void)
  96. {
  97.         //Read interrupt status regsiters. It clear all pending interrupts and the nIRQ pin goes back to high.
  98.         ItStatus1 = SpiReadRegister(0x03);                                                                                                //read the Interrupt Status1 register
  99.         ItStatus2 = SpiReadRegister(0x04);                                                                                                //read the Interrupt Status2 register

  100.         //Set the Rx switcher,利用GPIO口控制模塊內部的天線開關。
  101.         TxGPIOSetting();

  102.         /*enable transmitter*/
  103.         //The radio forms the packet and send it automatically.
  104.         SpiWriteRegister(0x07, 0x09);
  105. }

  106. //------------------------------------------------------------------------------------------------
  107. // Function Name :RFSetIdleMode
  108. //
  109. // Return Value : None
  110. // Parameters   : None
  111. // Notes        : 設置模塊工作在空閑狀態下。當模塊不需要接收數據也不需要發射數據的時候可以調用該函數以便省電;
  112. //
  113. //-----------------------------------------------------------------------------------------------
  114. void RFSetIdleMode(void)
  115. {
  116.         //The radio will work in idle mode
  117.         SpiWriteRegister(0x07, 0x01);                                                                                                        //write 0x09 to the Operating Function Control 1 register

  118.         IdleGPIOSetting();
  119.        
  120.         //Read interrupt status regsiters. It clear all pending interrupts and the nIRQ pin goes back to high.
  121.         ItStatus1 = SpiReadRegister(0x03);                                                                                                //read the Interrupt Status1 register
  122.         ItStatus2 = SpiReadRegister(0x04);                                                                                                //read the Interrupt Status2 register
  123. }

  124. //------------------------------------------------------------------------------------------------
  125. // Function Name :RFFIFOSendData
  126. //
  127. // Return Value : None
  128. // Parameters   : uint8 length: the length of the content which will be sent out. This value should
  129. //                not more than 64bytes because the FIFO is 64bytes. If it is bigger than 64, the
  130. //                content should be sent out for more times according to the FIFO empty interrupt.
  131. //                uint8 *payload: point to the content.
  132. // Notes        : In FIFO mode, send out one packet data.
  133. //                調用該函數可以把數據寫入模塊的FIFO中并把數據發送出去;數據長度不能大于64個字節;
  134. //
  135. //-----------------------------------------------------------------------------------------------
  136. void RFFIFOSendData(U8 length, U8 *payload)
  137. {
  138.         U8 i;

  139.         RFSetIdleMode();
  140.         //turn on the Tx LED to show the packet transmission
  141.         //TxLEDOn();                                                                                                                                                        
  142.         /*SET THE CONTENT OF THE PACKET*/
  143.         //set the length of the payload.       
  144.         SpiWriteRegister(0x3E, length);

  145.         //fill the payload into the transmit FIFO
  146.         for(i = 0; i < length; i++)
  147.         {
  148.                 SpiWriteRegister(0x7F, payload[i]);       
  149.         }

  150.         //Disable all other interrupts and enable the packet sent interrupt only.
  151.         //This will be used for indicating the successfull packet transmission for the MCU
  152.         SpiWriteRegister(0x05, 0x04);                                                                                                        //write 0x04 to the Interrupt Enable 1 register       
  153.         SpiWriteRegister(0x06, 0x00);                                                                                                        //write 0x00 to the Interrupt Enable 2 register       

  154.         RFSetTxMode();

  155.         /*wait for the packet sent interrupt*/
  156.         //The MCU just needs to wait for the 'ipksent' interrupt.
  157.         //等待發射完成中斷的到來,如果中斷采用非查詢方式,則本程序到這里可以結束,但必須在中斷服務程序中讀取狀態寄存器0x03和0x04,以便釋放中斷
  158.         while(NIRQ == 1);
  159.         UART_Send_Str("已發送..............\n");//調試信息時候用
  160.         //read interrupt status registers to release the interrupt flags
  161.         ItStatus1 = SpiReadRegister(0x03);                                                                                                //read the Interrupt Status1 register
  162.         ItStatus2 = SpiReadRegister(0x04);                                                                                                //read the Interrupt Status2 register

  163.         //turn off the Tx LED
  164.         //TurnOffAllLEDs();
  165. }
復制代碼


51單片機驅動程序4432.rar

59.3 KB, 下載次數: 42, 下載積分: 黑幣 -5

回復

使用道具 舉報

ID:136504 發表于 2016-9-7 16:13 | 顯示全部樓層
HW3000 433M 國產第一家433無線模塊,完美替換si4432,4463.cc1101。
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 99免费在线观看 | av在线免费观看网址 | 久久亚洲国产精品 | 天天视频一区二区三区 | 成人h电影在线观看 | 国产视频久久久 | 成人欧美一区二区三区在线播放 | 亚洲高清在线视频 | 免费a网站 | 国产精品国产三级国产aⅴ浪潮 | 一区二区三区视频在线免费观看 | 欧美一级黄色片 | 国产黄色网址在线观看 | 99精品网 | 在线观看免费av网 | 国产在线视频一区二区董小宛性色 | 伊人色综合久久久天天蜜桃 | 欧美中文字幕一区二区 | 久久的色| 欧美视频成人 | h视频免费看| 国产91观看 | 亚洲人人舔人人 | 国产一区二区久久 | 91影院在线观看 | 欧产日产国产精品视频 | 久久精品久久久 | 欧美激情精品久久久久久变态 | 国产在线第一页 | 欧美一级黄带 | 国产成人精品亚洲日本在线观看 | 久久久久国产一区二区三区四区 | av官网在线| 超黄毛片 | 久久综合狠狠综合久久综合88 | 中文字幕免费 | 久久99国产精一区二区三区 | 欧美日韩国产一区二区三区 | 精品国产1区2区3区 一区二区手机在线 | 精品欧美乱码久久久久久 | 不卡一二三区 |