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

📄 code.lst

📁 nRF905无线FSK芯片在51单片机上工作的代码
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.50   CODE                                                                  06/25/2007 15:17:12 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE CODE
OBJECT MODULE PLACED IN CODE.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE CODE.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          /*******************************************************************************************
   2          科创四第15小组FSK通信控制程序
   3          /*******************************************************************************************/
   4          #include <reg51.h>
   5          #include <intrins.h>
   6          #include <absacc.h>
   7          #include "set.h"
   8          
   9          #define SB 8 //sent bytes
  10          
  11          sbit retest=P2^0;
  12          int trsec;
  13          uchar jj=0;
  14          uchar r_flag=1;// flag of receiving
  15          uchar retrieving_flag=0;
  16          
  17          code RFConfig RxTxConf =
  18          {
  19           10,
  20           0x01,
  21           0x2c, 
  22           0x44, 
  23           0x08, 
  24           0x08, 
  25           0xcc, 0xcc, 0xcc,0xcc,    // 4 bytes address
  26           0x5c 
  27          };
  28          // The content of this struct is nRF905's initialize data.初始化数据
  29          // CH_NO=1;433MHZ;Normal Opration,No Retrans;RX,TX Address is 4 Bytes
  30          // RX TX Payload Width is SB Bytes;Disable Extern Clock;Fosc=16MHZ
  31          // 8 Bits CRC And enable
  32          
  33          //四个按键对应的动作
  34          Key1()//
  35          {
  36   1                trsec = 410;
  37   1      }
  38          Key2()//
  39          {         uchar i,flag=1;
  40   1      
  41   1       CSN=0;PB8255=PB;
  42   1              SpiWrite(RC);
  43   1        for (i=0;i<10;i++) // Write configration words  写放配置字
  44   1       {
  45   2        temp.buf[i]=SpiRead();
  46   2       }
  47   1       CSN=1; PB8255=PB;
  48   1       for(i=0;i<10;i++)
  49   1       {
  50   2              if ( temp.buf[i] == RxTxConf.buf[i]) flag++;
  51   2       }
  52   1       sec_dis=flag;
  53   1      }
  54          Key3()//
  55          {  
C51 COMPILER V7.50   CODE                                                                  06/25/2007 15:17:12 PAGE 2   

  56   1                      int i;
  57   1                      for(i=0;i<SB;i++)
  58   1                      TxBuf[i]=i+1;
  59   1                      SetTxMode(); // Set Tx Mode
  60   1                      for (i=0;i<SB;i++) TxData(TxBuf[i]);
  61   1                      Delay(100);
  62   1                      
  63   1              TxPacket();    // Transmit Tx buffer data
  64   1                      SetRxMode();
  65   1         
  66   1      }
  67          Key4()//
  68          
  69          {          
  70   1                      trsec   = 0;  SetRxMode();
  71   1      }
  72          
  73          /**** T0时钟中断服务程序
  74                  在本例中,每5ms被执行一次
  75          *****/
  76          
  77          timer0() interrupt 1 using 0         
  78          {
  79   1      //EA=0;
  80   1              int i;
  81   1              /* 重新对计数器赋初值,并启动定时计数 */
  82   1              TH0=V_TH0;
  83   1          TL0=V_TL0;
  84   1          TR0=1;
  85   1          
  86   1          if(p_counter<30) p_counter++;
  87   1      
  88   1              /* 检测到按键被按下(0)时,相应的指示灯亮(0) */
  89   1              if (KEY1==0)
  90   1              {if (p_counter==30)  {p_counter=0;Key1();} }
  91   1              if (KEY2==0) 
  92   1              {if (p_counter==30)  {p_counter=0;Key2();} }
  93   1              if (KEY3==0) 
  94   1          {if (p_counter==30)  {p_counter=0;Key3();} }
  95   1              if (KEY4==0) 
  96   1              {if (p_counter==30)  {p_counter=0;Key4();} }
  97   1                                      
  98   1                      //the next section is about display
  99   1              Display();
 100   1      
 101   1      //      if(r_flag>0) r_flag--;
 102   1      
 103   1      /*      if(trsec>0)
 104   1              {
 105   1                      if (trsec%400==0)
 106   1                      { SetTxMode();
 107   1                      for(i=0;i<SB;i++)
 108   1                      TxBuf[i]=trsec/400;
 109   1                      TxPacket();
 110   1                      SetRxMode();
 111   1                      }
 112   1                      trsec--;
 113   1              }  */
 114   1      
 115   1      
 116   1              if(trsec>0 && (!retrieving_flag))
 117   1              {
C51 COMPILER V7.50   CODE                                                                  06/25/2007 15:17:12 PAGE 3   

 118   2                      if (trsec%300==0)
 119   2                      { 
 120   3                              SetTxMode();
 121   3                              for(i=0;i<SB;i++)
 122   3                              TxBuf[i]=jj;
 123   3                              jj++;
 124   3                              if(jj>15) jj=0;
 125   3                              TxPacket();
 126   3                              SetRxMode();
 127   3                      }
 128   2                      trsec--;
 129   2                      if (trsec==0) trsec=320;
 130   2              }
 131   1                      // EA=1;
 132   1      }
 133          
 134          /*******************************************************************************************/
 135          void main()
 136          {
 137   1      
 138   1          SCON=0x50;  //模式1
 139   1          TMOD=0x21;  //定时模式2
 140   1          IE=0x90;
 141   1      
 142   1          //=====9600=======设置串口通讯寄存器
 143   1          PCON=0x00;   //波特率9600BPS,晶振11.0592MHZ
 144   1          TH1=0xFD;  //
 145   1          TL1=0xFD;  //计数器初值
 146   1              TH0=V_TH0;        //5ms         键盘显示中断
 147   1          TL0=V_TL0;
 148   1      
 149   1      
 150   1              // 8255初始化 
 151   1          RST8255=0;
 152   1              COM8255=0x81;
 153   1          //================NRF905初始化
 154   1       CSN=1;      // Spi  disable      
 155   1       SCK=0;      // Spi clock line init high
 156   1       DR=1;      // Init DR for input
 157   1       AM=1; 
 158   1      // TEST=1;
 159   1            // Init AM for input
 160   1       PWR_UP=1;     // nRF905 power on
 161   1       TRX_CE=0;     // Set nRF905 in standby mode
 162   1       TX_EN=0;     // set radio in Rx mode 
 163   1       ///////////////////////////////////////////
 164   1          TI = 0;//串行中断标志位清零
 165   1          TR1 = 1;//打开计数器1 
 166   1              TR0 = 1;//开计数器0
 167   1              ET0=1;            //允许计数器T0中断
 168   1              PB8255=PB;
 169   1      
 170   1      
 171   1      
 172   1              trsec=0;
 173   1       //================
 174   1       Config905();    // Config nRF905 module
 175   1      
 176   1       
 177   1       SetRxMode();    // Set nRF905 in Rx mode
 178   1       retest=0; 
 179   1      while(1)
C51 COMPILER V7.50   CODE                                                                  06/25/2007 15:17:12 PAGE 4   

⌨️ 快捷键说明

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