⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.lst

📁 cc1100模块51单片机参考程序,个人觉得挺好用.
💻 LST
📖 第 1 页 / 共 3 页
字号:
 440   1          halSpiWriteReg(CCxxx0_PKTLEN,   rfSettings.PKTLEN);
 441   1      }
 442          
 443          
 444          
 445          
 446          
 447          
 448          //*****************************************************************************************
 449          //函数名:void halRfSendPacket(INT8U *txBuffer, INT8U size)
 450          //输入:发送的缓冲区,发送数据个数
 451          //输出:无
 452          //功能描述:CC1100发送一组数据
 453          //*****************************************************************************************
 454          void halRfSendPacket(INT8U *txBuffer, INT8U size) 
 455          {
 456   1              halSpiWriteReg(CCxxx0_TXFIFO, size);
 457   1          halSpiWriteBurstReg(CCxxx0_TXFIFO, txBuffer, size); //写入要发送的数据
 458   1      
 459   1          halSpiStrobe(CCxxx0_STX);           //进入发送模式发送数据
 460   1      
 461   1          // Wait for GDO0 to be set -> sync transmitted
 462   1          while (!GDO1);
 463   1      
 464   1          // Wait for GDO0 to be cleared -> end of packet
 465   1          while (GDO1);
 466   1              halSpiStrobe(CCxxx0_SFTX);
 467   1      }
 468          
 469          
 470          
 471          INT8U halRfReceivePacket(INT8U *rxBuffer, INT8U *length) 
 472          {
 473   1          INT8U status[2];
 474   1          INT8U packetLength;
 475   1      
 476   1          halSpiStrobe(CCxxx0_SRX);           //进入接收状态
 477   1          while (!GDO1);
 478   1          while (GDO1);
 479   1          if ((halSpiReadStatus(CCxxx0_RXBYTES) & BYTES_IN_RXFIFO)) //如果接的字节数不为0
 480   1              {
 481   2              packetLength = halSpiReadReg(CCxxx0_RXFIFO);//读出第一个字节,此字节为该帧数据长度
 482   2              if (packetLength <= *length)            //如果所要的有效数据长度小于等于接收到的数据包的长度
 483   2                      {
 484   3                  halSpiReadBurstReg(CCxxx0_RXFIFO, rxBuffer, packetLength); //读出所有接收到的数据
 485   3                  *length = packetLength;                             //把接收数据长度的修改为当前数据的长度
 486   3              
 487   3                  // Read the 2 appended status bytes (status[0] = RSSI, status[1] = LQI)
C51 COMPILER V7.50   MAIN                                                                  11/26/2006 22:02:37 PAGE 9   

 488   3                  halSpiReadBurstReg(CCxxx0_RXFIFO, status, 2);       //读出CRC校验位
 489   3                  return (status[1] & CRC_OK);                        //如果校验成功返回接收成功
 490   3              }
 491   2                       else 
 492   2                      {
 493   3                  *length = packetLength;
 494   3                  halSpiStrobe(CCxxx0_SFRX);          //清洗接收缓冲区
 495   3                  return 0;
 496   3              }
 497   2          } 
 498   1              else
 499   1              return 0;
 500   1      }
 501          
 502          /******************************************************************************************
 503          *******************************************************************************************
 504          ************************************中断服务程序*********************************************
 505          *******************************************************************************************
 506          ******************************************************************************************/
 507          /*void Timer0ISR(void) interrupt 1
 508          {
 509                  EA = 0;
 510                  TH0+=TIMER0H;
 511                  TL0+=TIMER0L;
 512                  TimerCount++;
 513                  timer[0]++;
 514                  timer[1]++;
 515                  EA = 1;
 516          }
 517          */
 518          
 519          
 520          void Set(void)
 521          {
 522   1      //CCxxx0_FREQ2 = 0x10
 523   1      halSpiWriteReg(CCxxx0_FREQ2,0x10);
 524   1      halSpiWriteReg(CCxxx0_FREQ1,0xA7);
 525   1      
 526   1      halSpiWriteReg(CCxxx0_FREQ0,0x62);
 527   1      
 528   1      halSpiWriteReg(CCxxx0_FSCTRL1,0x06);
 529   1      
 530   1      halSpiWriteReg(CCxxx0_FSCTRL0,0x00);
 531   1      
 532   1      halSpiWriteReg(CCxxx0_MDMCFG4,0xC8);
 533   1      
 534   1      halSpiWriteReg(CCxxx0_MDMCFG3,0x93);
 535   1      
 536   1      halSpiWriteReg(CCxxx0_MDMCFG2,0x1B);
 537   1      
 538   1      halSpiWriteReg(CCxxx0_MDMCFG1,0x22);
 539   1      
 540   1      halSpiWriteReg(CCxxx0_MDMCFG0,0xF8);
 541   1      
 542   1      halSpiWriteReg(CCxxx0_CHANNR,0x01);
 543   1      
 544   1      halSpiWriteReg(CCxxx0_DEVIATN,0x34);
 545   1      
 546   1      halSpiWriteReg(CCxxx0_FREND0,0x17);
 547   1      
 548   1      halSpiWriteReg(CCxxx0_FREND1,0x56);
 549   1      halSpiWriteReg(CCxxx0_MCSM0,0x18);
C51 COMPILER V7.50   MAIN                                                                  11/26/2006 22:02:37 PAGE 10  

 550   1      halSpiWriteReg(CCxxx0_FOCCFG,0x16);
 551   1      halSpiWriteReg(CCxxx0_BSCFG,0x6C);
 552   1      
 553   1      halSpiWriteReg(CCxxx0_AGCCTRL2,0x43);
 554   1      halSpiWriteReg(CCxxx0_AGCCTRL1,0x40);
 555   1      halSpiWriteReg(CCxxx0_AGCCTRL0,0x91);
 556   1      halSpiWriteReg(CCxxx0_FSCAL3,0xA9);
 557   1      halSpiWriteReg(CCxxx0_FSCAL2,0x2A);
 558   1      halSpiWriteReg(CCxxx0_FSCAL1,0x00);
 559   1      halSpiWriteReg(CCxxx0_FSCAL0,0x11);
 560   1      //halSpiWriteReg(CCxxx0_FSTEST,0x59);
 561   1      //halSpiWriteReg(CCxxx0_TEST2,0x81);
 562   1      //halSpiWriteReg(CCxxx0_TEST1,0x35);
 563   1      //halSpiWriteReg(CCxxx0_TEST0,0x09);
 564   1      
 565   1      halSpiWriteReg(CCxxx0_MDMCFG1,0x20);
 566   1      
 567   1      halSpiWriteReg(CCxxx0_MDMCFG2,0x03);
 568   1      
 569   1      halSpiWriteReg(CCxxx0_PKTCTRL0,0x05);
 570   1      
 571   1      //halSpiWriteReg(CCxxx0_IOCFG0,0x06);
 572   1      
 573   1      //halSpiWriteReg(CCxxx0_PKTLEN,0x20);
 574   1      
 575   1      
 576   1      
 577   1      halSpiWriteReg(CCxxx0_PKTCTRL1,0x05);
 578   1         
 579   1      
 580   1      halSpiWriteReg(CCxxx0_ADDR,0x01);
 581   1      
 582   1      
 583   1      }
 584          /******************************************************************************************
 585          *******************************************************************************************
 586          ******************************************主程序*******************************************
 587          *******************************************************************************************
 588          ******************************************************************************************/
 589          main(void)
 590          {
 591   1              INT8U leng;
 592   1              INT8U arrTx[4];
 593   1              INT8U arrRx[4];
 594   1              CpuInit();
 595   1              POWER_UP_RESET_CC1100();
 596   1              halRfWriteRfSettings();
 597   1              halSpiWriteBurstReg(CCxxx0_PATABLE, PaTabel, 8);
 598   1      //      Set();
 599   1              LED1 = 0;
 600   1              LED2 = 0;
 601   1              delay(30000);
 602   1              LED1 = 1;
 603   1              LED2 = 1;
 604   1              delay(30000);
 605   1              arrTx[0] = 0xBB;
 606   1              arrTx[1] = 0xAA;
 607   1              arrTx[2] = 0x55;
 608   1              arrTx[3] = 0x09;
 609   1              leng = 3;
 610   1              while(1)
 611   1              {
C51 COMPILER V7.50   MAIN                                                                  11/26/2006 22:02:37 PAGE 11  

 612   2                      if(!KEY1)
 613   2                      {
 614   3                              delay(50);
 615   3                              if(!KEY1)
 616   3                              {
 617   4                                      while(1)
 618   4                                      {
 619   5                                              halRfSendPacket(arrTx,4);
 620   5                                              LED2 = 0;
 621   5                                              delay(10000);
 622   5                                              LED2 = 1;
 623   5                                              delay(10000);
 624   5                                      }
 625   4                              }
 626   3                      }
 627   2                      if(!KEY2)
 628   2                      {
 629   3                              delay(50);
 630   3                              if(!KEY2)
 631   3                              {
 632   4                                      while(1)
 633   4                                      {
 634   5                                              if(halRfReceivePacket(arrRx,&leng))
 635   5                                              {
 636   6                                                      LED1 = 0;
 637   6                                                      delay(10000);
 638   6                                                      LED1 = 1;
 639   6                                                      halSpiStrobe(CCxxx0_SFRX);
 640   6      //                                              SendCh(arrRx[0]);
 641   6      //                                              SendCh(arrRx[1]);
 642   6      //                                              SendCh(arrRx[2]);
 643   6      //                                              SendCh(arrRx[3]);
 644   6                                              }
 645   5                                      }
 646   4                              }
 647   3                      }
 648   2              }
 649   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1167    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     47      32
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -