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

📄 jieshou.lst

📁 基于NRF905无线收发模块的无线计分系统程序
💻 LST
字号:
C51 COMPILER V7.06   JIESHOU                                                               04/11/2008 00:21:58 PAGE 1   


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

stmt level    source

   1          #include <reg52.h>
   2          #include <ABSACC.h>
   3          #include <intrins.h>
   4          #include <stdio.h>
   5          #define uint unsigned int                     //0 ~ 255
   6          #define uchar unsigned char
   7          //--------------------------------------------------------------------------------------------------------
             -----------
   8          #define BYTE_BIT0       0x01
   9          #define BYTE_BIT1       0x02
  10          #define BYTE_BIT2       0x04
  11          #define BYTE_BIT3       0x08
  12          #define BYTE_BIT4       0x10
  13          #define BYTE_BIT5       0x20
  14          #define BYTE_BIT6       0x40
  15          #define BYTE_BIT7       0x80
  16          bdata unsigned  char DATA_BUF;
  17          #define DATA7   ((DATA_BUF&BYTE_BIT7) != 0)
  18          #define DATA0   ((DATA_BUF&BYTE_BIT0) != 0)
  19          sbit    flag    =DATA_BUF^7;
  20          sbit    flag1   =DATA_BUF^0;
  21          //--------------------------------------------------------------------------------------------------------
             --------
  22          #define TxRxBuf_Len 4
  23          unsigned char TxRxBuffer[TxRxBuf_Len];
  24          //--------------------------------------------NRF905端口设置----------------------------------------------
             --------------
  25          sbit    TXEN=P1^0;
  26          sbit    TRX_CE=P3^2;
  27          sbit    PWR=P1^1;
  28          sbit    MISO=P1^6;
  29          sbit    MOSI=P1^5;
  30          sbit    SCK=P1^7;
  31          sbit    CSN=P1^3;
  32          sbit    AM=P1^4;
  33          sbit    DR=P3^3;
  34          sbit    CD=P1^2;
  35          //--------------------------------------------计数变量----------------------------------------------------
             ---------
  36          uchar count1;
  37          uchar count2;
  38          //--------------------------------------------数码管位选--------------------------------------------------
             -------
  39          sbit    led1=P2^1;
  40          sbit    led0=P2^0;
  41          sbit    led2=P2^2;
  42          sbit    led3=P2^3;
  43          //--------------------------------------------------------------------------------------------------------
             -------
  44          uchar seg[10]={0xC0,0xCF,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};         //0~~9段码
  45          //-----------------------------------------------NRF905寄存器配置-----------------------------------------
             -------
  46          unsigned char idata RFConf[11]=
  47          {
  48            0x00,                             //配置命令//
C51 COMPILER V7.06   JIESHOU                                                               04/11/2008 00:21:58 PAGE 2   

  49            0x4c,
  50            0x0c,
  51            0x44,0x04,0x04,
  52            0xcc,0xcc,0xcc,0xcc,
  53            0x58,                            //CRC充许,8位CRC校验,外部时钟信号不使能,16M晶振
  54          };
  55          //---------------------------------------------------NRF905控制命令---------------------------------------
             ----------------
  56          #define WC              0x00
  57          #define RC              0x10
  58          #define WTP             0x20
  59          #define RTP             0x21
  60          #define WTA             0x22
  61          #define RTA             0x23
  62          #define RRP             0x24
  63          //---------------------------------------------------------------延时-------------------------------------
             ----
  64          void Delay(uchar n)
  65          {
  66   1              uint k;
  67   1              while(n--)
  68   1              for(k=0;k<8;k++);
  69   1      }
  70          void delay1(uint i)
  71          {
  72   1              for(;i>0;i--);   
  73   1      }
  74          //-------------------------------------------------------NRF905 SPI读函数---------------------------------
             -----------------
  75          unsigned char SpiRead(void)
  76          {
  77   1              unsigned char j;
  78   1              for (j=0;j<8;j++)
  79   1              {
  80   2              DATA_BUF=DATA_BUF<<1;
  81   2                      SCK=1;
  82   2                      if (MISO)       //读取最高位,保存至最末尾,通过左移位完成整个字节
  83   2                      {
  84   3                              DATA_BUF|=BYTE_BIT0;
  85   3                      }
  86   2                      else
  87   2                      {
  88   3                              DATA_BUF&=~BYTE_BIT0;
  89   3                      }
  90   2                      SCK=0;
  91   2               }
  92   1               return DATA_BUF;
  93   1      }
  94          //-------------------------------------------------------NRF905 SPI写函数---------------------------------
             ------------------------
  95          void SpiWrite(unsigned char send)
  96          {
  97   1              unsigned char i;
  98   1              DATA_BUF=send;
  99   1              for (i=0;i<8;i++)
 100   1              {
 101   2                      if (DATA7)      //总是发送最高位
 102   2                      {
 103   3                              MOSI=1;
 104   3                      }
 105   2                      else
 106   2                      {
C51 COMPILER V7.06   JIESHOU                                                               04/11/2008 00:21:58 PAGE 3   

 107   3                              MOSI=0;
 108   3                      }
 109   2                      SCK=1;
 110   2                      DATA_BUF=DATA_BUF<<1;
 111   2                      SCK=0;
 112   2              }
 113   1      }
 114          //------------------------------------------初始化nRF905--------------------------------------------------
             --------
 115          void nRF905Init(void)
 116          {
 117   1          CSN=1;                                              // Spi  disable
 118   1              SCK=0;                                          // Spi clock line init low
 119   1              DR=0;                                           // Init DR for input
 120   1              AM=0;                                           // Init AM for input
 121   1              CD=0;                                           // Init CD for input
 122   1              PWR=1;                                  // nRF905 power on
 123   1              TRX_CE=0;                                       // Set nRF905 in standby mode
 124   1              TXEN=0;                                 // set radio in Rx mode
 125   1      }
 126          //------------------------------------------初始化寄存器--------------------------------------------------
             --------
 127          void Config905(void)
 128          {
 129   1              uchar i;
 130   1              CSN=0;                                          // Spi enable for write a spi command
 131   1              //SpiWrite(WC);                         // Write config command写放配置命令
 132   1              for (i=0;i<11;i++)      // Write configration words  写放配置字
 133   1              {
 134   2                 SpiWrite(RFConf[i]);
 135   2              }
 136   1              CSN=1;                                  // Disable Spi
 137   1      }
 138          //--------------------------------------------------设置接收状态------------------------------------------
             ------------
 139          void SetRxMode(void)
 140          {
 141   1              TXEN=0;
 142   1              TRX_CE=1;
 143   1              Delay(1);                                       // delay for mode change(>=650us)
 144   1      }
 145          //---------------------------------------------------接收状态判断-----------------------------------------
             ----------
 146          unsigned char CheckDR(void)             //检查是否有新数据传入 Data Ready
 147          {
 148   1              if (DR=1&&TRX_CE==1 && TXEN==0)
 149   1              {
 150   2             // Delay(50)  ;
 151   2                      return 1;
 152   2              }
 153   1              else
 154   1              {
 155   2                      return 0;
 156   2              }
 157   1      }
 158          //-----------------------------------------------------读取接收缓冲区数据---------------------------------
             --------------
 159          void RxPacket(void)                                                     //读数据
 160          {
 161   1              uchar i;
 162   1          Delay(1);
 163   1      //      TRX_CE=0;                                       // Set nRF905 in standby mode
C51 COMPILER V7.06   JIESHOU                                                               04/11/2008 00:21:58 PAGE 4   

 164   1          Delay(100);
 165   1          TRX_CE=0;
 166   1              CSN=0;                                          // Spi enable for write a spi command
 167   1          Delay(1);
 168   1              SpiWrite(RRP);
 169   1              for (i = 0 ;i < 4 ;i++)
 170   1              {  
 171   2                      TxRxBuffer[i]=SpiRead();                // Read data and save to buffer        
 172   2              }
 173   1              CSN=1;
 174   1          Delay(10);
 175   1              TRX_CE=1;                                                       
 176   1      }
 177          //-------------------------------------------------------接收数据-----------------------------------------
             --------
 178          void  RX(void)
 179          {
 180   1                SetRxMode();                  // Set nRF905 in Rx mode
 181   1                        //Delay(10000);
 182   1                while (CheckDR()==0);
 183   1               //Delay(10000);
 184   1                      Delay(10);
 185   1                        RxPacket();
 186   1               //Delay(10000);                        // Recive data by nRF905
 187   1                       Delay(10);
 188   1      }
 189          //------------------------------------------------------主函数--------------------------------------------
             --------
 190          void main(void)
 191          {
 192   1              nRF905Init();
 193   1              Config905();
 194   1                      P0=0x00;
 195   1              while(1)
 196   1              {
 197   2                      RX();
 198   2                      Delay(10);
 199   2                      CSN=0;   
 200   2                      if(TxRxBuffer[0])
 201   2                      {       
 202   3                      if(TxRxBuffer[0]==0x29)
 203   3                      {
 204   4                      count1=count1+2;
 205   4                      }
 206   3              
 207   3                      if(TxRxBuffer[0]==0x30)
 208   3                       { 
 209   4                              count2=count2+3;        
 210   4                       }
 211   3              }
 212   2                      P0=seg[count1/10];
 213   2                      led0=1;led1=1;led2=1;led3=0;
 214   2                      Delay(10);
 215   2                      led3=1;
 216   2                      P0=seg[count1%10];
 217   2                      led2=0;
 218   2                      Delay(10);
 219   2                      led2=1;
 220   2                      P0=seg[count2/10];
 221   2                      led1=0;
 222   2                      Delay(10);
 223   2                      led1=1;
C51 COMPILER V7.06   JIESHOU                                                               04/11/2008 00:21:58 PAGE 5   

 224   2                      P0=seg[count2%10];
 225   2                      led0=0;
 226   2                      Delay(10);
 227   2                      led0=1; 
 228   2                      }
 229   1                      CSN=1;
 230   1                      Delay(1);
 231   1      }
 232          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    377    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     17    ----
   IDATA SIZE       =     11    ----
   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 + -