C51 COMPILER V8.18   NRF2401                                                               06/05/2009 10:43:05 PAGE 1   


C51 COMPILER V8.18, COMPILATION OF MODULE NRF2401
OBJECT MODULE PLACED IN nRF2401.OBJ
COMPILER INVOKED BY: D:\keil\C51\BIN\C51.EXE nRF2401.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          /**********************************************************************************/
   2          /**********************************************************************************/
   3          /*
   4          #include <regx52.h>
   5          #include <stdio.h>
   6          #include <string.h>
   7          #include <math.h>
   8          #include <intrins.h>
   9          #include <ABSACC.H>
  10          #include "format.h"
  11          #include "serial.h"
  12          #include "delay.h" */
  13          #include <aduc845.h>
  14           #include <intrins.h>
  15          
  16          /**********************************************************************************/
  17          //#define uchar unsigned char 
  18          //#define uint  unsigned int
  19          
  20          #define Fclk    3686400
  21          #define BitRate 19200
  22          #define BRR             (Fclk/(16*Bitrate))-1  //BRR=11
  23          
  24          #define timerdiv        1
  25          #define timerval        256-(Fclk/timerdiv)/100000                      // timeout each 10us TIMERAL=219.
  26          
  27          #define nRF2401_ON              PWR_UP = 1
  28          #define nRF2401_OFF             PWR_UP = 0
  29          #define CE_HIGH                 CE = 1
  30          #define CE_LOW                  CE = 0
  31          //extern UINT8 ChangMode;
  32          /**********************************************************************************/
  33          
  34          unsigned char code nRF2401AddrLen = 4;          //
  35          unsigned char code nRF2401Addr1[5] = { 0x33, 0x33, 0x33, 0x33, 0x33  };         //
  36          unsigned char code nRF2401Addr2[5] = { 0x33, 0x33, 0x33, 0x33, 0x33  };         //
  37          
  38          unsigned char code CH1DataLen = 25;     //Addr1Len + CH1DataLen + CRCLen <= 32Byte
  39          unsigned char code CH2DataLen = 25;     //every package data must match the Len, shorter or longer can not be 
             -sent
  40          
  41          bit RX2_EN = 0;
  42          
  43          //uchar RXData[26];
  44          
  45          //#define RCV_FIFO_LEN 25                    /* size of serial receiving buffer      */
  46          //unsigned char xdata RcvFifo[ RCV_FIFO_LEN ] = {0, 0};
  47          //unsigned char xdata *pRcvFifoWr = RcvFifo;  //最后由中断进入接收缓冲区的字节位置
  48          //unsigned char xdata *pRcvFifoRd = RcvFifo;  //最后取走的字节位置
  49          //bit RcvFifoSign = 0;      //接收缓冲区非空标志   有=1
  50          //bit RcvFifoFul = 0;       //输入缓冲区满标志  满=1
  51          
  52          //unsigned char RcvDataLen = 0; // RXMODE receive avail DataLen
  53          
  54          /**********************************************************************************/
C51 COMPILER V8.18   NRF2401                                                               06/05/2009 10:43:05 PAGE 2   

  55          
  56          // PIN CONFIG for S52
  57          sbit    CLK1    = P2^3;         // Clock TX/RX for Data Channel1 3-wire interface
  58          sbit    CS              = P2^2;         // Chip Select Activates Comfiguration Mode
  59          sbit    Data    = P2^4;         // RX Data Channel1/TX Data Input/3-wire interface
  60          sbit    CE              = P2^1;         // Chip Enalbe Activates RX or TX mode
  61          //sbit  Clk2    = P2^4;         // Clock for RX Data Channel2
  62          //sbit  Dout2   = P2^3;         // RX Data Channel2
  63          
  64          //sbit  DR2             = P3^3;         // RX Data Ready at Data Channel2(ShockBurst only)
  65          //sbit  DR1             = P3^3;         // RX Data Ready at Data Channel1(ShockBurst only)
  66          sbit    PWR_UP  = P2^0;         // nRF24011
  67          
  68          /**********************************************************************************/
  69          
  70          
  71          /******************************** MAIN  START ******************************/
  72          /*void main1(void)
  73          {       
  74                  Delay25us(20000);
  75                  UART_Init();
  76                  
  77                  //init_io();
  78                  //nRF2401_ON;
  79                  nRF2401_Init();
  80                  //CE_HIGH;
  81                  SetRXMode();
  82              //P0=0xff;
  83                  
  84          //      putstring("Test nRF2401...\r\n");
  85                  Delay25us(20000);
  86                  
  87                  //Timer1_Init();                 // 发送方
  88                  
  89                  EXInt0_Init();                   // 接收方
  90          
  91                  //IRQ_Priority();
  92                          
  93                  while(1)
  94                  {               
  95                          while( RcvFifoSign )
  96                          {
  97                                  UART_SendByte(GetRcvFifo());
  98                          }       
  99                  }                                       
 100          }*/
 101          /*************************************Rmain      END *******************************/
 102           void SPI_SendByte( unsigned char ch )
 103          {
 104   1              unsigned char i;
 105   1      
 106   1              for ( i = 0; i < 8; i++ )
 107   1              {
 108   2                      if ( ch & 0x80 )
 109   2                              Data = 1;
 110   2                      else
 111   2                              Data = 0;
 112   2                              
 113   2                      ch <<= 1;       
 114   2                      _nop_();
 115   2                      CLK1 = 1;
 116   2                      _nop_();        
C51 COMPILER V8.18   NRF2401                                                               06/05/2009 10:43:05 PAGE 3   

 117   2                      _nop_();                // wait one clk cycle
 118   2                      CLK1 = 0;
 119   2              }
 120   1      }
 121          
 122          /************************************* InitnRF2401 START ******************************/                
 123          void nRF2401_Init(void)
 124          {
 125   1              unsigned char i;
 126   1      
 127   1              nRF2401_ON;     
 128   1      
 129   1              CE = 0;                                         //Disable CE
 130   1              CS = 1;                                         //Enable CS--confige mode
 131   1              
 132   1              SPI_SendByte( CH2DataLen << 3 );        // DATA2_W, 119:112
 133   1              
 134   1              SPI_SendByte( CH1DataLen << 3 );        // DATA1_W, 111:104
 135   1              
 136   1              for( i = 5; i > 0; i-- )                // 103:64
 137   1              {
 138   2                      SPI_SendByte( nRF2401Addr2[i-1] );      
 139   2              }
 140   1              
 141   1              for( i = 5; i > 0; i-- )                // 63:24
 142   1              {
 143   2                      SPI_SendByte( nRF2401Addr1[i-1] );      
 144   2              }
 145   1              
 146   1              SPI_SendByte( ( nRF2401AddrLen << 5 ) | 3 );    //  23:18, ADDR_W both RX channels; 17bit, CRC_Len; 16bit, C
             -RC_EN
 147   1      
 148   1              // RX2_EN; ShockBrust Mode; Datarate(Bit5) 250K,
 149   1              if( RX2_EN == 1 )
 150   1                      SPI_SendByte( 0x80 | 0x4f );    // Number of receiver(Bit7), shock Mode(Bit6), Datarate(Bit5) 250K, crystal
             -(Bit4-Bit2), RF Power(Bit1-Bit0)
 151   1              else
 152   1                      SPI_SendByte( 0x4f );
 153   1              
 154   1              SPI_SendByte( 0x05 );   // Bit7-Bit1, Channel1 Frequency; Bit0, RX/TX mode(Bit0)
 155   1              
 156   1              CS = 0;                                 // Disable CS--standby mode
 157   1              Data = 0;                               // Set Data low
 158   1      
 159   1              CE_HIGH;
 160   1      }
 161          
 162          
 163          /************************************* InitnRF2401 END *******************************/
 164          
 165          
 166          
 167          unsigned char SPI_RcvByte( void )
 168          {
 169   1              unsigned char i, ch = 0;
 170   1                CS = 0;
 171   1                CE_HIGH;      
 172   1              for ( i = 8; i > 0; i-- )
 173   1              {
 174   2                 
 175   2                      ch <<= 1;
 176   2                      CLK1=1;                 // set clock high
C51 COMPILER V8.18   NRF2401                                                               06/05/2009 10:43:05 PAGE 4   

 177   2                      _nop_();        
 178   2                      _nop_();
 179   2                      Data=1;                 // wait one clk cycle           
 180   2                      if( Data == 1 )
 181   2                              ch |= 1;
 182   2                              
 183   2                      CLK1 = 0;
 184   2              }
 185   1              
 186   1              return ch;      
 187   1      }
 188          
 189          
 190          /************************************* SetRXMode START ******************************/
 191          void SetRXMode()
 192          {
 193   1              CE = 0;                         // Set CE LOW
 194   1              CS = 1;                         // Set CS HIGH--confige mode
 195   1              
 196   1              Data = 1;                       // Set Data HIGH, Set RX mode           
 197   1              CLK1 = 1;                       // Make one SPIClock cycle
 198   1              _nop_();
 199   1              _nop_();
 200   1              CLK1 = 0;
 201   1              
 202   1              CS = 0;                         // Set CS LOW           
 203   1              CE = 1;                         // Set CE HIGH--active mode
 204   1      }
 205          /************************************* SetRXMode  END *******************************/
 206          
 207          
 208          /*void putRcvFifo( unsigned char ch )
 209          {
 210                  if( RcvFifoFul == 1 )
 211                          return;
 212                  
 213                  *( pRcvFifoWr++ ) = ch; 
 214                  RcvFifoSign = 1;
 215                          
 216                  if( pRcvFifoWr == RcvFifo + RCV_FIFO_LEN )
 217                          pRcvFifoWr =  RcvFifo;
 218                          
 219                  if( pRcvFifoWr == pRcvFifoRd )
 220                          RcvFifoFul = 1;
 221                          
 222          }
 223          
 224          unsigned char GetRcvFifo(void)
 225          {
 226                  unsigned char ch;
 227                  
 228          //      EX0 = 0;        // 关外部中断0，防止读FIFO过程中被写入
 229                  while ( !RcvFifoSign );     //缓冲区空等待
 230                  
 231                  ch = *( pRcvFifoRd++ );
 232                  RcvFifoFul = 0;
 233                  
 234                  if( pRcvFifoRd == RcvFifo + RCV_FIFO_LEN )
 235                          pRcvFifoRd = RcvFifo;
 236                  
 237                  if( pRcvFifoRd == pRcvFifoWr )
 238                          RcvFifoSign = 0;
C51 COMPILER V8.18   NRF2401                                                               06/05/2009 10:43:05 PAGE 5   

 239                  
 240          //      EX0 = 1;
 241                  return ( ch );        //取回数据
 242          }
 243          
 244          void EXInt0_Init(void)
 245          {
 246                  IT1 = 0;                // Low lever Triger
 247                  IE1 = 0;                // Clear EXInt0 flag
 248                  EX1 = 1;                // EX0 enable
 249                  EA = 1;
 250          } */
 251          
 252          /*void EXInt0_IRQ(void) interrupt 2
 253          {
 254          //      unsigned char pem;
 255                    IE1 = 0;
 256                  RcvDataLen = SPI_RcvByte();
 257                  
 258          //      if(RcvDataLen == 1)
 259          //      {
 260          //              tmp = SPI_RcvByte();
 261          //              if(tmp == 0x55) // DATA to Mouse
 262          //                      ChangMode = 0x55;
 263          //              else if(tmp == 0xAA)
 264          //                      ChangMode = 0xAA;               
 265          //      }
 266                  else    
 267                          while( DR1 == 0 )
 268                          {
 269                                  if( RcvDataLen )
 270                                  {
 271                                          RcvDataLen--;                   
 272                                          putRcvFifo(SPI_RcvByte());
 273                                  }
 274                                  else
 275                                  {
 276                                          SPI_RcvByte();
 277                                  }               
 278                          } 
 279          
 280           } */
 281          
 282          
 283          


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


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