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

📄 jieshou.lst

📁 利用NRF905无线通信模块进行RS232通信
💻 LST
字号:
C51 COMPILER V7.06   JIESHOU                                                               04/11/2008 00:43:45 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 32
  23          unsigned char TxRxBuffer[TxRxBuf_Len];
  24          //--------------------------------------------------------------------------------------------------------
             --------
  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          //------------------------------------------------NRF905寄存器配置----------------------------------------
             -------
  36          unsigned char idata RFConf[11]=
  37          {
  38            0x00,                             //配置命令//
  39            0x4c,
  40            0x0c,
  41            0x44,0x04,0x04,
  42            0xcc,0xcc,0xcc,0xcc,
  43            0x58,                            //CRC充许,8位CRC校验,外部时钟信号不使能,16M晶振
  44          };
  45          //--------------------------------------------------------------------------------------------------------
             ------
  46          #define WC              0x00
  47          #define RC              0x10
  48          #define WTP             0x20
  49          #define RTP             0x21
  50          #define WTA             0x22
  51          #define RTA             0x23
C51 COMPILER V7.06   JIESHOU                                                               04/11/2008 00:43:45 PAGE 2   

  52          #define RRP             0x24
  53          //-----------------------------------------------延时-----------------------------------------------------
             --------
  54          void Delay(uchar n)
  55          {
  56   1              uint k;
  57   1              while(n--)
  58   1              for(k=0;k<8;k++);
  59   1      }
  60          //-----------------------------------------------SPI读----------------------------------------------------
             -------------
  61          unsigned char SpiRead(void)
  62          {
  63   1              unsigned char j;
  64   1              for (j=0;j<8;j++)
  65   1              {
  66   2              DATA_BUF=DATA_BUF<<1;
  67   2                      SCK=1;
  68   2                      if (MISO)       //读取最高位,保存至最末尾,通过左移位完成整个字节
  69   2                      {
  70   3                              DATA_BUF|=BYTE_BIT0;
  71   3                      }
  72   2                      else
  73   2                      {
  74   3                              DATA_BUF&=~BYTE_BIT0;
  75   3                      }
  76   2                      SCK=0;
  77   2               }
  78   1               return DATA_BUF;
  79   1      }
  80          //---------------------------------------------------SPI写------------------------------------------------
             ---------
  81          void SpiWrite(unsigned char send)
  82          {
  83   1              unsigned char i;
  84   1              DATA_BUF=send;
  85   1              for (i=0;i<8;i++)
  86   1              {
  87   2                      if (DATA7)      //总是发送最高位
  88   2                      {
  89   3                              MOSI=1;
  90   3                      }
  91   2                      else
  92   2                      {
  93   3                              MOSI=0;
  94   3                      }
  95   2                      SCK=1;
  96   2                      DATA_BUF=DATA_BUF<<1;
  97   2                      SCK=0;
  98   2              }
  99   1      }
 100          //----------------------------------------------初始化nRF905----------------------------------------------
             ---------------
 101          void nRF905Init(void)
 102          {
 103   1          CSN=1;                                              // Spi  disable
 104   1              SCK=0;                                          // Spi clock line init low
 105   1              DR=0;                                           // Init DR for input
 106   1              AM=0;                                           // Init AM for input
 107   1              CD=0;                                           // Init CD for input
 108   1              PWR=1;                                  // nRF905 power on
 109   1              TRX_CE=0;                                       // Set nRF905 in standby mode
C51 COMPILER V7.06   JIESHOU                                                               04/11/2008 00:43:45 PAGE 3   

 110   1              TXEN=0;                                 // set radio in Rx mode
 111   1      }
 112          //----------------------------------------------初始化寄存器----------------------------------------------
             ---------------
 113          void Config905(void)
 114          {
 115   1              uchar i;
 116   1              CSN=0;                                          // Spi enable for write a spi command
 117   1              //SpiWrite(WC);                         // Write config command写放配置命令
 118   1              for (i=0;i<11;i++)      // Write configration words  写放配置字
 119   1              {
 120   2                 SpiWrite(RFConf[i]);
 121   2              }
 122   1              CSN=1;                                  // Disable Spi
 123   1      }
 124          //-----------------------------------------------设置接收模式---------------------------------------------
             -----------------
 125          void SetRxMode(void)
 126          {
 127   1              TXEN=0;
 128   1              TRX_CE=1;
 129   1              Delay(1);                                       // delay for mode change(>=650us)
 130   1      }
 131          //-----------------------------------------------判断接收状态---------------------------------------------
             ----------------------
 132          unsigned char CheckDR(void)             //检查是否有新数据传入 Data Ready
 133          {
 134   1              if (DR=1&&TRX_CE==1 && TXEN==0)
 135   1              {
 136   2             // Delay(50)  ;
 137   2                      return 1;
 138   2              }
 139   1              else
 140   1              {
 141   2                      return 0;
 142   2              }
 143   1      }
 144          //--------------------------------------------读数据------------------------------------------------------
             -----------------
 145          void RxPacket(void)                                                     //读数据
 146          {
 147   1              uchar i;
 148   1          Delay(1);
 149   1      //      TRX_CE=0;                                       // Set nRF905 in standby mode
 150   1          Delay(100);
 151   1          TRX_CE=0;
 152   1              CSN=0;                                          // Spi enable for write a spi command
 153   1          Delay(1);
 154   1              SpiWrite(RRP);
 155   1              for (i = 0 ;i < 4 ;i++)
 156   1              {    
 157   2                      TxRxBuffer[i]=SpiRead();                // Read data and save to buffe       
 158   2              }
 159   1              CSN=1;
 160   1                Delay(10);
 161   1              TRX_CE=1;                                                       
 162   1      }
 163          //--------------------------------------------------接收数据----------------------------------------------
             ----------------
 164          void  RX(void)
 165          {
 166   1                SetRxMode();                  // Set nRF905 in Rx mode
C51 COMPILER V7.06   JIESHOU                                                               04/11/2008 00:43:45 PAGE 4   

 167   1                        //Delay(10000);
 168   1                while (CheckDR()==0);
 169   1               //Delay(10000);
 170   1                      Delay(10);
 171   1                        RxPacket();
 172   1               //Delay(10000);                        // Recive data by nRF905
 173   1                       Delay(10);
 174   1      }
 175          //--------------------------------------------------串口初始化--------------------------------------------
             ---------------
 176          void StartUART( void )
 177          {                                                       //波特率4800
 178   1           SCON = 0x50;
 179   1           TMOD = 0x20;
 180   1           TH1 = 0xFA;
 181   1           TL1 = 0xFA;
 182   1           PCON = 0x00;
 183   1           TR1 = 1;
 184   1      }
 185          //--------------------------------------------------串口接收----------------------------------------------
             --------------
 186          void R_S_Byte(uchar R_Byte)
 187          {       
 188   1               SBUF = R_Byte;  
 189   1           while( TI == 0 );                          //查询法
 190   1               TI = 0;
 191   1           
 192   1      }
 193          //--------------------------------------------------------------------------------------------------------
             -----------------
 194          void main(void)
 195          {
 196   1              StartUART();
 197   1              nRF905Init();
 198   1              Config905();
 199   1              while(1)
 200   1              {
 201   2                      char i;
 202   2                      RX();
 203   2                      Delay(10);
 204   2                      CSN=0;  
 205   2                      for(i=0;i<4;i++)
 206   2                      {
 207   3                      R_S_Byte(TxRxBuffer[i]);
 208   3                      Delay(200);
 209   3                      Delay(200);
 210   3                      Delay(200);
 211   3                      }
 212   2                      CSN=1;
 213   2                      Delay(1);
 214   2              }
 215   1      }
 216          
 217          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    316    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     33       1
C51 COMPILER V7.06   JIESHOU                                                               04/11/2008 00:43:45 PAGE 5   

   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 + -