C51 COMPILER V8.08   NRFRECEIVE                                                            08/16/2014 10:01:24 PAGE 1   


C51 COMPILER V8.08, COMPILATION OF MODULE NRFRECEIVE
OBJECT MODULE PLACED IN NRFreceive.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE NRF\NRFreceive.c BROWSE DEBUG OBJECTEXTEND PRINT(.\NRFreceive.lst) OBJECT(N
                    -RFreceive.obj)

line level    source

   1          #include "reg52.h"      /*包含STC单片机头文件*/
   2          #include "QX51/qx51.h" /*包含qx51开发板头文件*/
   3          #include "DELAY/delay.h"/*包含delay延时函数文件*/
   4          #include "NRFreceive.h"//包涵NRF驱动
   5          
   6          uchar const TX_ADDRESS[TX_ADR_WIDTH]  = {0x34,0x43,0x10,0x10,0x01}; // Define a static TX address
   7          uchar rx_buf[TX_PLOAD_WIDTH];
   8          uchar tx_buf[TX_PLOAD_WIDTH];
   9          
  10          /**************************************************/
  11          uchar   bdata sta;
  12          sbit    RX_DR   =sta^6;
  13          sbit    TX_DS   =sta^5;
  14          sbit    MAX_RT  =sta^4; 
  15          /*************************************************/
  16           //NRF24L01+
  17          
  18          uchar SPI_RW(uchar dat)//写一字节并读出此地址的状态
  19           {
  20   1              uchar i;
  21   1              for(i=0;i<8;i++)
  22   1              {
  23   2                      SCK=0;
  24   2                      MOSI=(dat & 0x80);
  25   2                      dat<<=1;
  26   2                      SCK=1;
  27   2                      dat|=MISO;              
  28   2              }
  29   1              SCK=0;     //拉低时钟保持通信状态
  30   1              return dat;
  31   1       }
  32          uchar SPI_RW_Reg(uchar reg,value)//写一字节并读出此地址的状态
  33           {
  34   1              uchar status;
  35   1              CSN=0;
  36   1              status=SPI_RW(reg);
  37   1              SPI_RW(value);
  38   1              CSN=1;
  39   1              return status;
  40   1       }
  41          uchar SPI_Read(uchar reg)  //读一字节
  42          {
  43   1              uchar value;
  44   1              CSN=0;
  45   1              SPI_RW(reg);
  46   1              value=SPI_RW(0);
  47   1              CSN=1;
  48   1              return value;
  49   1      }
  50          uchar SPI_Read_Buf(uchar reg,uchar *pBuf,uchar uchars)//读多个字节并读出此地址的状态
  51          {
  52   1              uchar status,i;
  53   1              CSN=0;
  54   1              status=SPI_RW(reg);
C51 COMPILER V8.08   NRFRECEIVE                                                            08/16/2014 10:01:24 PAGE 2   

  55   1              for(i=0;i<uchars;i++)
  56   1              pBuf[i]=SPI_RW(0);
  57   1              CSN=1;
  58   1              return status;  
  59   1      }
  60          uchar SPI_write_Buf(uchar reg,uchar *pBuf,uchar uchars)//写多个字节并读出此地址的状态
  61          {
  62   1              uchar status,i;
  63   1              CSN=0;
  64   1              status=SPI_RW(reg);
  65   1              for(i=0;i<uchars;i++)
  66   1              SPI_RW(*pBuf++);
  67   1              CSN=1;
  68   1              return status;
  69   1      }/*
  70          void nrf24l01_TXBUF(uchar *tx_buf) //发送tx_buf中的数据
  71          {
  72                  CE=0;//停止射频工作
  73                  SPI_write_Buf(0x20+10,0x01,5);//写本机地址
  74                  SPI_write_Buf(0x20+10,0x01,5);//装载接收端O通道地址
  75                  SPI_write_Buf(0xa0,tx_buf,2);//装载要发送的数据
  76                  SPI_RW_Reg(0x20+0x00,0x0e);//IRQ收发完成中断响应16位CRC，发送模式
  77                  CE=1; //置高CE，激发数据发射
  78                  delay(1);
  79          } */
  80          void nrf24l01_init()
  81          {
  82   1              NRF_CE=0;
  83   1              CSN=1;
  84   1              SCK=0;
  85   1              IRQ=1;
  86   1              delay8us();
  87   1              delay8us();
  88   1      }
  89          void setRX_Mode()
  90          {
  91   1              NRF_CE=0;
  92   1              SPI_write_Buf(WRITE_REG + RX_ADDR_P0, TX_ADDRESS, TX_ADR_WIDTH); // 写接收地址到0通道
  93   1              SPI_RW_Reg(WRITE_REG + EN_AA, 0x00);      // Enable Auto.Ack:Pipe0
  94   1              SPI_RW_Reg(WRITE_REG + EN_RXADDR, 0x01);  // Enable Pipe0
  95   1              SPI_RW_Reg(WRITE_REG + RF_CH,40);        // Select 工作频段 channel 2.4G
  96   1              SPI_RW_Reg(WRITE_REG + RX_PW_P0, TX_PLOAD_WIDTH); // Select same RX payload width as TX Payload width
  97   1              SPI_RW_Reg(WRITE_REG + RF_SETUP, 0x07);   // TX_PWR:0dBm, Datarate:2Mbps, LNA:HCURR
  98   1              SPI_RW_Reg(WRITE_REG + CONFIG, 0x0f);     //IRQ中断响应16位CRC校验，接收模式
  99   1      
 100   1              NRF_CE = 1; // Set CE pin high to enable RX device
 101   1              delay_ms(1);
 102   1      }
 103          uchar nRF24L01_RxPacket(uchar *rx_buf)
 104          {
 105   1              uchar flag=0;
 106   1              sta=SPI_Read(STATUS);   // read register STATUS's value
 107   1              if(RX_DR)                               // if receive data ready (RX_DR) interrupt
 108   1              {
 109   2                      SPI_Read_Buf(RD_RX_PLOAD,rx_buf,TX_PLOAD_WIDTH);// read receive payload from RX_FIFO buffer
 110   2                      flag=1;
 111   2                      SPI_RW_Reg(WRITE_REG+STATUS,0xff);//清空状态寄存器
 112   2              }               
 113   1              return flag;
 114   1      }


C51 COMPILER V8.08   NRFRECEIVE                                                            08/16/2014 10:01:24 PAGE 3   

MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    283    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     26      13
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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