找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1096|回复: 0
打印 上一主题 下一主题
收起左侧

51单片机用M1101S的通信收发C程序

[复制链接]
跳转到指定楼层
楼主
ID:420702 发表于 2020-11-8 13:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本程序不使用中断,直接在主函数运行。引脚可直接修改。

单片机源程序如下:
  1. #include <reg52.h>

  2. #include <intrins.h>
  3. #define                INT8U                unsigned char
  4. #define                INT16U                unsigned int

  5. #define         WRITE_BURST             0x40                                                //连续写入
  6. #define         READ_SINGLE             0x80                                                //读
  7. #define         READ_BURST              0xC0                                                //连续读
  8. #define         BYTES_IN_RXFIFO     0x7F                                                  //接收缓冲区的有效字节数
  9. #define         CRC_OK              0x80                                                 //CRC校验通过位标志
  10. //*****************************************************************************************
  11. sbit         GDO0        =P1^3;
  12. sbit         GDO2        =P3^2;
  13. sbit        MISO        =P1^6;
  14. sbit        MOSI        =P1^5;
  15. sbit        SCK        =P1^7;
  16. sbit        CSN        =P1^2;
  17. //*****************************************************************************************
  18. sbit    LED2    =P3^4;
  19. sbit    LED1    =P3^5;
  20. sbit    KEY1    =P3^6;
  21. sbit    KEY2    =P3^7;
  22. //*****************************************************************************************
  23. sbit        led3=P2^3;
  24. sbit        led2=P2^2;
  25. sbit        led1=P2^1;
  26. sbit        led0=P2^0;
  27. //*****************************************************************************************
  28. INT8U PaTabel[8] = {0x60 ,0x60 ,0x60 ,0x60 ,0x60 ,0x60 ,0x60 ,0x60};
  29. //*****************************************************************************************
  30. void SpiInit(void);
  31. void CpuInit(void);
  32. void RESET_CC1100(void);
  33. void POWER_UP_RESET_CC1100(void);
  34. void halSpiWriteReg(INT8U addr, INT8U value);
  35. void halSpiWriteBurstReg(INT8U addr, INT8U *buffer, INT8U count);
  36. void halSpiStrobe(INT8U strobe);
  37. INT8U halSpiReadReg(INT8U addr);
  38. void halSpiReadBurstReg(INT8U addr, INT8U *buffer, INT8U count);
  39. INT8U halSpiReadStatus(INT8U addr);
  40. void halRfWriteRfSettings(void);
  41. void halRfSendPacket(INT8U *txBuffer, INT8U size);
  42. INT8U halRfReceivePacket(INT8U *rxBuffer, INT8U *length);  
  43. //*****************************************************************************************
  44. // CC1100 STROBE, CONTROL AND STATUS REGSITER
  45. #define CCxxx0_IOCFG2       0x00        // GDO2 output pin configuration
  46. #define CCxxx0_IOCFG1       0x01        // GDO1 output pin configuration
  47. #define CCxxx0_IOCFG0       0x02        // GDO0 output pin configuration
  48. #define CCxxx0_FIFOTHR      0x03        // RX FIFO and TX FIFO thresholds
  49. #define CCxxx0_SYNC1        0x04        // Sync word, high INT8U
  50. #define CCxxx0_SYNC0        0x05        // Sync word, low INT8U
  51. #define CCxxx0_PKTLEN       0x06        // Packet length
  52. #define CCxxx0_PKTCTRL1     0x07        // Packet automation control
  53. #define CCxxx0_PKTCTRL0     0x08        // Packet automation control
  54. #define CCxxx0_ADDR         0x09        // Device address
  55. #define CCxxx0_CHANNR       0x0A        // Channel number
  56. #define CCxxx0_FSCTRL1      0x0B        // Frequency synthesizer control
  57. #define CCxxx0_FSCTRL0      0x0C        // Frequency synthesizer control
  58. #define CCxxx0_FREQ2        0x0D        // Frequency control word, high INT8U
  59. #define CCxxx0_FREQ1        0x0E        // Frequency control word, middle INT8U
  60. #define CCxxx0_FREQ0        0x0F        // Frequency control word, low INT8U
  61. #define CCxxx0_MDMCFG4      0x10        // Modem configuration
  62. #define CCxxx0_MDMCFG3      0x11        // Modem configuration
  63. #define CCxxx0_MDMCFG2      0x12        // Modem configuration
  64. #define CCxxx0_MDMCFG1      0x13        // Modem configuration
  65. #define CCxxx0_MDMCFG0      0x14        // Modem configuration
  66. #define CCxxx0_DEVIATN      0x15        // Modem deviation setting
  67. #define CCxxx0_MCSM2        0x16        // Main Radio Control State Machine configuration
  68. #define CCxxx0_MCSM1        0x17        // Main Radio Control State Machine configuration
  69. #define CCxxx0_MCSM0        0x18        // Main Radio Control State Machine configuration
  70. #define CCxxx0_FOCCFG       0x19        // Frequency Offset Compensation configuration
  71. #define CCxxx0_BSCFG        0x1A        // Bit Synchronization configuration
  72. #define CCxxx0_AGCCTRL2     0x1B        // AGC control
  73. #define CCxxx0_AGCCTRL1     0x1C        // AGC control
  74. #define CCxxx0_AGCCTRL0     0x1D        // AGC control
  75. #define CCxxx0_WOREVT1      0x1E        // High INT8U Event 0 timeout
  76. #define CCxxx0_WOREVT0      0x1F        // Low INT8U Event 0 timeout
  77. #define CCxxx0_WORCTRL      0x20        // Wake On Radio control
  78. #define CCxxx0_FREND1       0x21        // Front end RX configuration
  79. #define CCxxx0_FREND0       0x22        // Front end TX configuration
  80. #define CCxxx0_FSCAL3       0x23        // Frequency synthesizer calibration
  81. #define CCxxx0_FSCAL2       0x24        // Frequency synthesizer calibration
  82. #define CCxxx0_FSCAL1       0x25        // Frequency synthesizer calibration
  83. #define CCxxx0_FSCAL0       0x26        // Frequency synthesizer calibration
  84. #define CCxxx0_RCCTRL1      0x27        // RC oscillator configuration
  85. #define CCxxx0_RCCTRL0      0x28        // RC oscillator configuration
  86. #define CCxxx0_FSTEST       0x29        // Frequency synthesizer calibration control
  87. #define CCxxx0_PTEST        0x2A        // Production test
  88. #define CCxxx0_AGCTEST      0x2B        // AGC test
  89. #define CCxxx0_TEST2        0x2C        // Various test settings
  90. #define CCxxx0_TEST1        0x2D        // Various test settings
  91. #define CCxxx0_TEST0        0x2E        // Various test settings

  92. // Strobe commands
  93. #define CCxxx0_SRES         0x30        // Reset chip.
  94. #define CCxxx0_SFSTXON      0x31        // Enable and calibrate frequency synthesizer (if MCSM0.FS_AUTOCAL=1).
  95.                                         // If in RX/TX: Go to a wait state where only the synthesizer is
  96.                                         // running (for quick RX / TX turnaround).
  97. #define CCxxx0_SXOFF        0x32        // Turn off crystal oscillator.
  98. #define CCxxx0_SCAL         0x33        // Calibrate frequency synthesizer and turn it off
  99.                                         // (enables quick start).
  100. #define CCxxx0_SRX          0x34        // Enable RX. Perform calibration first if coming from IDLE and
  101.                                         // MCSM0.FS_AUTOCAL=1.
  102. #define CCxxx0_STX          0x35        // In IDLE state: Enable TX. Perform calibration first if
  103.                                         // MCSM0.FS_AUTOCAL=1. If in RX state and CCA is enabled:
  104.                                         // Only go to TX if channel is clear.
  105. #define CCxxx0_SIDLE        0x36        // Exit RX / TX, turn off frequency synthesizer and exit
  106.                                         // Wake-On-Radio mode if applicable.
  107. #define CCxxx0_SAFC         0x37        // Perform AFC adjustment of the frequency synthesizer
  108. #define CCxxx0_SWOR         0x38        // Start automatic RX polling sequence (Wake-on-Radio)
  109. #define CCxxx0_SPWD         0x39        // Enter power down mode when CSn goes high.
  110. #define CCxxx0_SFRX         0x3A        // Flush the RX FIFO buffer.
  111. #define CCxxx0_SFTX         0x3B        // Flush the TX FIFO buffer.
  112. #define CCxxx0_SWORRST      0x3C        // Reset real time clock.
  113. #define CCxxx0_SNOP         0x3D        // No operation. May be used to pad strobe commands to two
  114.                                         // INT8Us for simpler software.

  115. #define CCxxx0_PARTNUM      0x30
  116. #define CCxxx0_VERSION      0x31
  117. #define CCxxx0_FREQEST      0x32
  118. #define CCxxx0_LQI          0x33
  119. #define CCxxx0_RSSI         0x34
  120. #define CCxxx0_MARCSTATE    0x35
  121. #define CCxxx0_WORTIME1     0x36
  122. #define CCxxx0_WORTIME0     0x37
  123. #define CCxxx0_PKTSTATUS    0x38
  124. #define CCxxx0_VCO_VC_DAC   0x39
  125. #define CCxxx0_TXBYTES      0x3A
  126. #define CCxxx0_RXBYTES      0x3B

  127. #define CCxxx0_PATABLE      0x3E
  128. #define CCxxx0_TXFIFO       0x3F
  129. #define CCxxx0_RXFIFO       0x3F

  130. // RF_SETTINGS is a data structure which contains all relevant CCxxx0 registers
  131. typedef struct S_RF_SETTINGS
  132. {
  133.     INT8U FSCTRL2;   //自已加的
  134.     INT8U FSCTRL1;   // Frequency synthesizer control.
  135.     INT8U FSCTRL0;   // Frequency synthesizer control.
  136.     INT8U FREQ2;     // Frequency control word, high INT8U.
  137.     INT8U FREQ1;     // Frequency control word, middle INT8U.
  138.     INT8U FREQ0;     // Frequency control word, low INT8U.
  139.     INT8U MDMCFG4;   // Modem configuration.
  140.     INT8U MDMCFG3;   // Modem configuration.
  141.     INT8U MDMCFG2;   // Modem configuration.
  142.     INT8U MDMCFG1;   // Modem configuration.
  143.     INT8U MDMCFG0;   // Modem configuration.
  144.     INT8U CHANNR;    // Channel number.
  145.     INT8U DEVIATN;   // Modem deviation setting (when FSK modulation is enabled).
  146.     INT8U FREND1;    // Front end RX configuration.
  147.     INT8U FREND0;    // Front end RX configuration.
  148.     INT8U MCSM0;     // Main Radio Control State Machine configuration.
  149.     INT8U FOCCFG;    // Frequency Offset Compensation Configuration.
  150.     INT8U BSCFG;     // Bit synchronization Configuration.
  151.     INT8U AGCCTRL2;  // AGC control.
  152.     INT8U AGCCTRL1;  // AGC control.
  153.     INT8U AGCCTRL0;  // AGC control.
  154.     INT8U FSCAL3;    // Frequency synthesizer calibration.
  155.     INT8U FSCAL2;    // Frequency synthesizer calibration.
  156.     INT8U FSCAL1;    // Frequency synthesizer calibration.
  157.     INT8U FSCAL0;    // Frequency synthesizer calibration.
  158.     INT8U FSTEST;    // Frequency synthesizer calibration control
  159.     INT8U TEST2;     // Various test settings.
  160.     INT8U TEST1;     // Various test settings.
  161.     INT8U TEST0;     // Various test settings.
  162.     INT8U IOCFG2;    // GDO2 output pin configuration
  163.     INT8U IOCFG0;    // GDO0 output pin configuration
  164.     INT8U PKTCTRL1;  // Packet automation control.
  165.     INT8U PKTCTRL0;  // Packet automation control.
  166.     INT8U ADDR;      // Device address.
  167.     INT8U PKTLEN;    // Packet length.
  168. } RF_SETTINGS;

  169. /////////////////////////////////////////////////////////////////
  170. const RF_SETTINGS rfSettings =
  171. {
  172.         0x00,
  173.     0x08,   // FSCTRL1   Frequency synthesizer control.
  174.     0x00,   // FSCTRL0   Frequency synthesizer control.
  175.     0x10,   // FREQ2     Frequency control word, high byte.
  176.     0xA7,   // FREQ1     Frequency control word, middle byte.
  177.     0x62,   // FREQ0     Frequency control word, low byte.
  178.     0x5B,   // MDMCFG4   Modem configuration.
  179.     0xF8,   // MDMCFG3   Modem configuration.
  180.     0x03,   // MDMCFG2   Modem configuration.
  181.     0x22,   // MDMCFG1   Modem configuration.
  182.     0xF8,   // MDMCFG0   Modem configuration.

  183.     0x00,   // CHANNR    Channel number.
  184.     0x47,   // DEVIATN   Modem deviation setting (when FSK modulation is enabled).
  185.     0xB6,   // FREND1    Front end RX configuration.
  186.     0x10,   // FREND0    Front end RX configuration.
  187.     0x18,   // MCSM0     Main Radio Control State Machine configuration.
  188.     0x1D,   // FOCCFG    Frequency Offset Compensation Configuration.
  189.     0x1C,   // BSCFG     Bit synchronization Configuration.
  190.     0xC7,   // AGCCTRL2  AGC control.
  191.     0x00,   // AGCCTRL1  AGC control.
  192.     0xB2,   // AGCCTRL0  AGC control.

  193.     0xEA,   // FSCAL3    Frequency synthesizer calibration.
  194.     0x2A,   // FSCAL2    Frequency synthesizer calibration.
  195.     0x00,   // FSCAL1    Frequency synthesizer calibration.
  196.     0x11,   // FSCAL0    Frequency synthesizer calibration.
  197.     0x59,   // FSTEST    Frequency synthesizer calibration.
  198.     0x81,   // TEST2     Various test settings.
  199.     0x35,   // TEST1     Various test settings.
  200.     0x09,   // TEST0     Various test settings.
  201.     0x0B,   // IOCFG2    GDO2 output pin configuration.
  202.     0x06,   // IOCFG0D   GDO0 output pin configuration. Refer to SmartRF?Studio User Manual for detailed pseudo register explanation.

  203.     0x04,   // PKTCTRL1  Packet automation control.
  204.     0x05,   // PKTCTRL0  Packet automation control.
  205.     0x00,   // ADDR      Device address.
  206.     0x0c    // PKTLEN    Packet length.
  207. };
  208. //*****************************************************************************************
  209. //函数名:delay(unsigned int s)
  210. //输入:时间
  211. //输出:无
  212. //功能描述:普通廷时,内部用
  213. //*****************************************************************************************               
  214. static void delay(unsigned int s)
  215. {
  216.         unsigned int i;
  217.         for(i=0; i<s; i++);
  218.         for(i=0; i<s; i++);
  219. }


  220. void halWait(INT16U timeout) {
  221.     do {
  222.         _nop_();
  223.                 _nop_();
  224.                 _nop_();
  225.                 _nop_();
  226.                 _nop_();
  227.                 _nop_();
  228.                 _nop_();
  229.                 _nop_();
  230.                 _nop_();
  231.                 _nop_();
  232.                 _nop_();
  233.                 _nop_();
  234.                 _nop_();
  235.                 _nop_();
  236.                 _nop_();
  237.     } while (--timeout);
  238. }


  239. void SpiInit(void)
  240. {
  241.         CSN=0;
  242.         SCK=0;
  243.         CSN=1;
  244. }

  245. /*****************************************************************************************
  246. //函数名:CpuInit()
  247. //输入:无
  248. //输出:无
  249. //功能描述:SPI初始化程序
  250. /*****************************************************************************************/
  251. void CpuInit(void)
  252. {
  253.         SpiInit();
  254.         delay(5000);
  255. }
  256.        

  257. //*****************************************************************************************
  258. //函数名:SpisendByte(INT8U dat)
  259. //输入:发送的数据
  260. //输出:无
  261. //功能描述:SPI发送一个字节
  262. //*****************************************************************************************
  263. INT8U SpiTxRxByte(INT8U dat)
  264. {
  265.         INT8U i,temp;
  266.         temp = 0;
  267.        
  268.         SCK = 0;
  269.         for(i=0; i<8; i++)
  270.         {
  271.                 if(dat & 0x80)
  272.                 {
  273.                         MOSI = 1;
  274.                 }
  275.                 else MOSI = 0;
  276.                 dat <<= 1;

  277.                 SCK = 1;
  278.                 _nop_();
  279.                 _nop_();

  280.                 temp <<= 1;
  281.                 if(MISO)temp++;
  282.                 SCK = 0;
  283.                 _nop_();
  284.                 _nop_();       
  285.         }
  286.         return temp;
  287. }

  288. //*****************************************************************************************
  289. //函数名:void RESET_CC1100(void)
  290. //输入:无
  291. //输出:无
  292. //功能描述:复位CC1100
  293. //*****************************************************************************************
  294. void RESET_CC1100(void)
  295. {
  296.         CSN = 0;
  297.         while (MISO);
  298.     SpiTxRxByte(CCxxx0_SRES);                 //写入复位命令
  299.         while (MISO);
  300.     CSN = 1;
  301. }

  302. //*****************************************************************************************
  303. //函数名:void POWER_UP_RESET_CC1100(void)
  304. //输入:无
  305. //输出:无
  306. //功能描述:上电复位CC1100
  307. //*****************************************************************************************
  308. void POWER_UP_RESET_CC1100(void)
  309. {
  310.         CSN = 1;
  311.         halWait(1);
  312.         CSN = 0;
  313.         halWait(1);
  314.         CSN = 1;
  315.         halWait(41);
  316.         RESET_CC1100();                   //复位CC1100
  317. }

  318. //*****************************************************************************************
  319. //函数名:void halSpiWriteReg(INT8U addr, INT8U value)
  320. //输入:地址和配置字
  321. //输出:无
  322. //功能描述:SPI写寄存器
  323. //*****************************************************************************************
  324. void halSpiWriteReg(INT8U addr, INT8U value)
  325. {
  326.     CSN = 0;
  327.     while (MISO);
  328.     SpiTxRxByte(addr);                //写地址
  329.     SpiTxRxByte(value);                //写入配置
  330.     CSN = 1;
  331. }

  332. //*****************************************************************************************
  333. //函数名:void halSpiWriteBurstReg(INT8U addr, INT8U *buffer, INT8U count)
  334. //输入:地址,写入缓冲区,写入个数
  335. //输出:无
  336. //功能描述:SPI连续写配置寄存器
  337. //*****************************************************************************************
  338. void halSpiWriteBurstReg(INT8U addr, INT8U *buffer, INT8U count)
  339. {
  340.     INT8U i, temp;
  341.         temp = addr | WRITE_BURST;
  342.     CSN = 0;
  343.     while (MISO);
  344.     SpiTxRxByte(temp);
  345.     for (i = 0; i < count; i++)
  346.         {
  347.         SpiTxRxByte(buffer[i]);
  348.     }
  349.     CSN = 1;
  350. }

  351. //*****************************************************************************************
  352. //函数名:void halSpiStrobe(INT8U strobe)
  353. //输入:命令
  354. //输出:无
  355. //功能描述:SPI写命令
  356. //*****************************************************************************************
  357. void halSpiStrobe(INT8U strobe)
  358. {
  359.     CSN = 0;
  360.     while (MISO);
  361.     SpiTxRxByte(strobe);                //写入命令
  362.     CSN = 1;
  363. }





  364. //*****************************************************************************************
  365. //函数名:INT8U halSpiReadReg(INT8U addr)
  366. //输入:地址
  367. //输出:该寄存器的配置字
  368. //功能描述:SPI读寄存器
  369. //*****************************************************************************************
  370. INT8U halSpiReadReg(INT8U addr)
  371. {
  372.         INT8U temp, value;
  373.     temp = addr|READ_SINGLE;//读寄存器命令
  374.         CSN = 0;
  375.         while (MISO);
  376.         SpiTxRxByte(temp);
  377.         value = SpiTxRxByte(0);
  378.         CSN = 1;
  379.         return value;
  380. }


  381. //*****************************************************************************************
  382. //函数名:void halSpiReadBurstReg(INT8U addr, INT8U *buffer, INT8U count)
  383. //输入:地址,读出数据后暂存的缓冲区,读出配置个数
  384. //输出:无
  385. //功能描述:SPI连续写配置寄存器
  386. //*****************************************************************************************
  387. void halSpiReadBurstReg(INT8U addr, INT8U *buffer, INT8U count)
  388. {
  389.     INT8U i,temp;
  390.         temp = addr | READ_BURST;                //写入要读的配置寄存器地址和读命令
  391.     CSN = 0;
  392.     while (MISO);
  393.         SpiTxRxByte(temp);   
  394.     for (i = 0; i < count; i++)
  395.         {
  396.         buffer[i] = SpiTxRxByte(0);
  397.     }
  398.     CSN = 1;
  399. }


  400. //*****************************************************************************************
  401. //函数名:INT8U halSpiReadReg(INT8U addr)
  402. //输入:地址
  403. //输出:该状态寄存器当前值
  404. //功能描述:SPI读状态寄存器
  405. //*****************************************************************************************
  406. INT8U halSpiReadStatus(INT8U addr)
  407. {
  408.     INT8U value,temp;
  409.         temp = addr | READ_BURST;                //写入要读的状态寄存器的地址同时写入读命令
  410.     CSN = 0;
  411.     while (MISO);
  412.     SpiTxRxByte(temp);
  413.         value = SpiTxRxByte(0);
  414.         CSN = 1;
  415.         return value;
  416. }
  417. //*****************************************************************************************
  418. //函数名:void halRfWriteRfSettings(RF_SETTINGS *pRfSettings)
  419. //输入:无
  420. //输出:无
  421. //功能描述:配置CC1100的寄存器
  422. //*****************************************************************************************
  423. void halRfWriteRfSettings(void)
  424. {

  425.         halSpiWriteReg(CCxxx0_FSCTRL0,  rfSettings.FSCTRL2);//自已加的
  426.     // Write register settings
  427.     halSpiWriteReg(CCxxx0_FSCTRL1,  rfSettings.FSCTRL1);
  428.     halSpiWriteReg(CCxxx0_FSCTRL0,  rfSettings.FSCTRL0);
  429.     halSpiWriteReg(CCxxx0_FREQ2,    rfSettings.FREQ2);
  430.     halSpiWriteReg(CCxxx0_FREQ1,    rfSettings.FREQ1);
  431.     halSpiWriteReg(CCxxx0_FREQ0,    rfSettings.FREQ0);
  432.     halSpiWriteReg(CCxxx0_MDMCFG4,  rfSettings.MDMCFG4);
  433.     halSpiWriteReg(CCxxx0_MDMCFG3,  rfSettings.MDMCFG3);
  434.     halSpiWriteReg(CCxxx0_MDMCFG2,  rfSettings.MDMCFG2);
  435.     halSpiWriteReg(CCxxx0_MDMCFG1,  rfSettings.MDMCFG1);
  436.     halSpiWriteReg(CCxxx0_MDMCFG0,  rfSettings.MDMCFG0);
  437.     halSpiWriteReg(CCxxx0_CHANNR,   rfSettings.CHANNR);
  438.     halSpiWriteReg(CCxxx0_DEVIATN,  rfSettings.DEVIATN);
  439.     halSpiWriteReg(CCxxx0_FREND1,   rfSettings.FREND1);
  440.     halSpiWriteReg(CCxxx0_FREND0,   rfSettings.FREND0);
  441.     halSpiWriteReg(CCxxx0_MCSM0 ,   rfSettings.MCSM0 );
  442.     halSpiWriteReg(CCxxx0_FOCCFG,   rfSettings.FOCCFG);
  443.     halSpiWriteReg(CCxxx0_BSCFG,    rfSettings.BSCFG);
  444.     halSpiWriteReg(CCxxx0_AGCCTRL2, rfSettings.AGCCTRL2);
  445.         halSpiWriteReg(CCxxx0_AGCCTRL1, rfSettings.AGCCTRL1);
  446.     halSpiWriteReg(CCxxx0_AGCCTRL0, rfSettings.AGCCTRL0);
  447.     halSpiWriteReg(CCxxx0_FSCAL3,   rfSettings.FSCAL3);
  448.         halSpiWriteReg(CCxxx0_FSCAL2,   rfSettings.FSCAL2);
  449.         halSpiWriteReg(CCxxx0_FSCAL1,   rfSettings.FSCAL1);
  450.     halSpiWriteReg(CCxxx0_FSCAL0,   rfSettings.FSCAL0);
  451.     halSpiWriteReg(CCxxx0_FSTEST,   rfSettings.FSTEST);
  452.     halSpiWriteReg(CCxxx0_TEST2,    rfSettings.TEST2);
  453.     halSpiWriteReg(CCxxx0_TEST1,    rfSettings.TEST1);
  454.     halSpiWriteReg(CCxxx0_TEST0,    rfSettings.TEST0);
  455.     halSpiWriteReg(CCxxx0_IOCFG2,   rfSettings.IOCFG2);
  456.     halSpiWriteReg(CCxxx0_IOCFG0,   rfSettings.IOCFG0);   
  457.     halSpiWriteReg(CCxxx0_PKTCTRL1, rfSettings.PKTCTRL1);
  458.     halSpiWriteReg(CCxxx0_PKTCTRL0, rfSettings.PKTCTRL0);
  459.     halSpiWriteReg(CCxxx0_ADDR,     rfSettings.ADDR);
  460.     halSpiWriteReg(CCxxx0_PKTLEN,   rfSettings.PKTLEN);
  461. }

  462. //*****************************************************************************************
  463. //函数名:void halRfSendPacket(INT8U *txBuffer, INT8U size)
  464. //输入:发送的缓冲区,发送数据个数
  465. //输出:无
  466. //功能描述:CC1100发送一组数据
  467. //*****************************************************************************************

  468. void halRfSendPacket(INT8U *txBuffer, INT8U size)
  469. {
  470.         halSpiWriteReg(CCxxx0_TXFIFO, size);
  471.     halSpiWriteBurstReg(CCxxx0_TXFIFO, txBuffer, size);        //写入要发送的数据

  472.     halSpiStrobe(CCxxx0_STX);                //进入发送模式发送数据

  473.     // Wait for GDO0 to be set -> sync transmitted
  474.     while (!GDO0);
  475.     // Wait for GDO0 to be cleared -> end of packet
  476.     while (GDO0);
  477.         halSpiStrobe(CCxxx0_SFTX);
  478. }

  479. ……………………

  480. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有程序51hei提供下载:
1100 无线收发.zip (53.36 KB, 下载次数: 6)


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表