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

📄 9e5quick.lst

📁 nRF9e5的收发程序
💻 LST
字号:
C51 COMPILER V7.50   9E5QUICK                                                              12/04/2006 14:53:53 PAGE 1   


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

line level    source

   1          /*===============================================================================================
   2           *
   3           * Copyright (C) 2004 
   4           *
   5           * This file is distributed in the hope that it will be useful, but WITHOUT
   6           * WARRANTY OF ANY KIND.
   7           *
   8           * Author(s):
   9           *
  10           * DESCRIPTION: for nRF9E5
  11           *
  12           *  nRF9E5/nRF24E1 range demo. Select receiver by shorting P03 and P05 and transmitter by shorting
  13           *  P05 and P06. Uncomment/comment the appropriate #define below to select nRF9E5 or nRF24E1.
  14           *
  15           *  The transmitter continously send one byte packets. Each time the receiver receives a packet the
  16           *  P00 pin is set low (LED1 is turned on on the 9E5 eval board). At the same time a 20ms timer is
  17           *  started and if a new packets is not received before the 20ms time-out the P00 pin is set high
  18           *  (LED1 is turned off). If a new packet is received before the time-out a new 20ms time-out period
  19           *  is started.
  20           *
  21           *  Please remember to turn off the RS232 switch on the receiver and transmitter boards. On the
  22           *  nRF9E5 board turn off all dip-switches on the transmitter and turn on only the LED1 switch on
  23           *  the receiver.
  24           *
  25           * COMPILER:
  26           *  
  27           *  This program has been tested with Keil C51 V7.09
  28           *
  29           * $Revision: 1 $
  30           *
  31           *==================================================================================================
  32          */
  33          // Comment out the following line for nRF24E1
  34          
  35          #include <reg9e5.h>
  36          #define POWER      3                // 0=min power...3 = max power
  37          #define HFREQ      0                // 0=433MHz, 1=868/915MHz
  38          #define CHANNEL  351                // Channel number: f(MHz) = (422.4+CHANNEL/10)*(1+HFREQ) 
  39          
  40          #define TIMEOUT    20               // 20ms time-out on LED
  41          #define ON          1
  42          #define OFF         0
  43          
  44          static volatile unsigned char timer;
  45          static volatile unsigned char t0lrel, t0hrel;
  46          
  47          unsigned char bdata KeyValue;
  48          sbit  L0 = KeyValue^4;
  49          sbit  L1 = KeyValue^5;
  50          sbit  L2 = KeyValue^6;
  51          
  52          sbit    S0      =P0^5;
  53          sbit    S1      =P0^6;
  54          sbit    IO18b2  =P0^7;
  55          
C51 COMPILER V7.50   9E5QUICK                                                              12/04/2006 14:53:53 PAGE 2   

  56          sbit    LED0    =P0^0;
  57          sbit    LED1    =P0^3;
  58          sbit    LED2    =P0^4;
  59          
  60          void Delay100us(volatile unsigned char n)
  61          {
  62   1          unsigned char i;
  63   1          while(n--)
  64   1              for(i=0;i<35;i++)
  65   1                  ;
  66   1      }
  67          
  68          void Delayms(volatile unsigned char n)
  69          {
  70   1          unsigned char i;
  71   1          while(n--)
  72   1              for(i=0;i<10;i++)
  73   1              Delay100us(10);
  74   1      }
  75          
  76          void PutChar(char c)
  77          {
  78   1          while(!TI)
  79   1              ;
  80   1          TI = 0;
  81   1          SBUF = c;
  82   1      }
  83          
  84          void PutString(const char *s)
  85          {
  86   1          while(*s != 0)
  87   1              PutChar(*s++);
  88   1      }
  89          
  90          unsigned char SpiReadWrite(unsigned char b)
  91          {
  92   1          EXIF &= ~0x20;                  // Clear SPI interrupt
  93   1          SPI_DATA = b;                   // Move byte to send to SPI data register
  94   1          while((EXIF & 0x20) == 0x00)    // Wait until SPI hs finished transmitting
  95   1              ;
  96   1          return SPI_DATA;
  97   1      }
  98          
  99          void ReceivePacket()
 100          //unsigned char ReceivePacket()
 101          {
 102   1          unsigned char b;
 103   1      
 104   1          TRX_CE = 1;
 105   1          if(DR)
 106   1          {    
 107   2              RACSN = 0;
 108   2              SpiReadWrite(RRP);
 109   2              b = SpiReadWrite(0);
 110   2              RACSN = 1;
 111   2              TRX_CE = 0;
 112   2              KeyValue=b;
 113   2              PutChar(b);
 114   2              if(L0)  {  LED0=0;      }
 115   2              if(L1)  {  LED1=0;      }       
 116   2              if(L2)  {  LED2=0;      }
 117   2              Delayms(10);
C51 COMPILER V7.50   9E5QUICK                                                              12/04/2006 14:53:53 PAGE 3   

 118   2              LED0=1;                         // LED OFF
 119   2              LED1=1;
 120   2              LED2=1;
 121   2      
 122   2          }
 123   1      
 124   1      //    return b;
 125   1      
 126   1      }
 127          
 128          void TransmitPacket(unsigned char b)
 129          {
 130   1      
 131   1          RACSN=0;                    // Spi enable for write a spi command   
 132   1          SpiReadWrite(WTA);          // Write address command
 133   1          SpiReadWrite(0xE7);
 134   1          SpiReadWrite(0xE7);
 135   1          SpiReadWrite(0xE7);
 136   1          SpiReadWrite(0xE7);
 137   1          RACSN=1;                    // Spi disable                                          
 138   1          Delay100us(1);            
 139   1      
 140   1          RACSN = 0;
 141   1          SpiReadWrite(WTP);
 142   1          SpiReadWrite(b);
 143   1          RACSN = 1;
 144   1          TRX_CE = 1;
 145   1          Delay100us(10);
 146   1          
 147   1          TRX_CE = 0;
 148   1          while(DR == 0)
 149   1              ;
 150   1      }
 151          
 152          void ScanKey()
 153          {    
 154   1          KeyValue=0x00;
 155   1          
 156   1          if(S0==0)  
 157   1          {   
 158   2              L0=1;
 159   2              LED0=0;
 160   2              Delayms(10);
 161   2              LED0=1;
 162   2           }
 163   1          if(S1==0)  
 164   1          {
 165   2              L1=1; 
 166   2              LED1=0;
 167   2              Delayms(10);
 168   2              LED1=1;         
 169   2          }
 170   1      /*
 171   1          if(S2==0)
 172   1          {
 173   1              L2=1;
 174   1              LED2=0;
 175   1              Delayms(10);
 176   1              LED2=1;
 177   1          }   
 178   1      */    
 179   1          if(KeyValue!=0x00)
C51 COMPILER V7.50   9E5QUICK                                                              12/04/2006 14:53:53 PAGE 4   

 180   1          {
 181   2       //     PutChar(KeyValue);
 182   2              TXEN = 1;
 183   2              TransmitPacket(KeyValue);
 184   2              TXEN=0;
 185   2      //      Delayms(10);
 186   2      //      LED0=1;
 187   2      //      LED1=1;
 188   2      //      LED2=1;
 189   2          }    
 190   1      }
 191          /*
 192          void Led(unsigned char on)
 193          {
 194              if (on)
 195              {
 196                  P0 &= ~0x01;
 197                  timer = 0;  
 198                  TR0 = 1;                    // Start Timer0
 199              } else
 200                  P0 |= 0x01;
 201          }
 202          */
 203          void InitTimer(void)
 204          {
 205   1          TR0 = 0;
 206   1          TMOD &= ~0x03;
 207   1          TMOD |= 0x01;                   // mode 1
 208   1          CKCON |= 0x08;                  // T0M = 1 (/4 timer clock)
 209   1          t0lrel = 0x60;                  // 1KHz tick...
 210   1          t0hrel = 0xF0;                  // ... = 65536-16e6/(4*1e3) = F060h
 211   1          TF0 = 0;                        // Clear any pending Timer0 interrupts
 212   1          ET0 = 1;                        // Enable Timer0 interrupt
 213   1      }
 214          
 215          void Timer0ISR (void) interrupt 1
 216          {
 217   1          TF0 = 0;                        // Clear Timer0 interrupt
 218   1          TH0 = t0hrel;                   // Reload Timer0 high byte
 219   1          TL0 = t0lrel;                   // Reload Timer0 low byte
 220   1          timer++;
 221   1          if (timer == TIMEOUT)
 222   1          {
 223   2      //        P0 |= 0x01;                 // Led off
 224   2              TR0 = 0;                    // Stop timer
 225   2          }
 226   1      }
 227          /*
 228          void Receiver(void)
 229          {
 230          //    unsigned char b;
 231              unsigned char bo, err;
 232          
 233          
 234              TXEN = 0;
 235              
 236              bo = err = 0;
 237              for(;;)
 238              {
 239          //      b = ReceivePacket();
 240                  Led(ON);
 241              }
C51 COMPILER V7.50   9E5QUICK                                                              12/04/2006 14:53:53 PAGE 5   

 242          }
 243          
 244          void Transmitter(void)
 245          {
 246              unsigned char b;
 247              
 248              TXEN = 1;
 249          
 250              b = 0;
 251              for(;;)
 252              {
 253                  TransmitPacket(b++);        // Transmit data
 254              }
 255          }
 256          */
 257          void Init(void)
 258          {
 259   1          unsigned char tmp;
 260   1      
 261   1          TH1 = 243;                      // 19200@16MHz (when T1M=1 and SMOD=1)
 262   1          CKCON |= 0x10;                  // T1M=1 (/4 timer clock)
 263   1          PCON = 0x80;                    // SMOD=1 (double baud rate)
 264   1          SCON = 0x52;                    // Serial mode1, enable receiver
 265   1          TMOD = 0x20;                    // Timer1 8bit auto reload 
 266   1          TR1 = 1;                        // Start timer1
 267   1      
 268   1          P0_ALT |= 0x06;                 // Select alternate functions on pins P0.1 and P0.2   
 269   1          P0_DIR = 0x62;                  // P0.0 out,P0.1 input(RXD),P0.2 P0.3 P0.4 output,P0.5 P0.6 P0.7 input
 270   1                                          // 11100010
 271   1      //      P0_ALT |= 0x00;
 272   1      //      P0_DIR=0xaa;
 273   1      
 274   1      
 275   1          SPICLK = 1;
 276   1          SPI_CTRL = 0x02;                // Connect internal SPI controller to Radio
 277   1      
 278   1          LED0 = 1;
 279   1          LED1 = 1;
 280   1          LED2 = 1;    
 281   1      
 282   1          // Switch to 16MHz clock:
 283   1          RACSN = 0;
 284   1          SpiReadWrite(RRC | 0x09);
 285   1      //    tmp = SpiReadWrite(0) | 0x04;
 286   1          tmp = SpiReadWrite(0) | 0x0C;
 287   1          RACSN = 1;
 288   1      
 289   1          RACSN = 0;
 290   1          SpiReadWrite(WRC | 0x09);
 291   1          SpiReadWrite(tmp);
 292   1          RACSN = 1;
 293   1      
 294   1          // Configure Radio:
 295   1          RACSN = 0;
 296   1          SpiReadWrite(WRC | 0x03);       // Write to RF config address 3 (RX payload)
 297   1          SpiReadWrite(0x01);             // One byte RX payload
 298   1          SpiReadWrite(0x01);             // One byte TX payload
 299   1          RACSN = 1;
 300   1      
 301   1          RACSN = 0;
 302   1          SpiReadWrite(RRC | 0x01);       // Read RF config address 1
 303   1          tmp = SpiReadWrite(0) & 0xf0;   // Clear the power and frequency setting bits
C51 COMPILER V7.50   9E5QUICK                                                              12/04/2006 14:53:53 PAGE 6   

 304   1          RACSN = 1;
 305   1      
 306   1          RACSN = 0;
 307   1          SpiReadWrite(WRC);              // Write RF config address 0
 308   1          SpiReadWrite(CHANNEL & 0xff);   // CHANNEL bit7..0
 309   1          // Change power defined by POWER above, to 433 or 868/915MHz defined by HFREQ and
 310   1          // bit8 of CHANNEL:
 311   1          SpiReadWrite(tmp | (POWER<<2) | (HFREQ << 1) | ((CHANNEL >> 8) & 0x01));
 312   1          
 313   1          SpiReadWrite(0x44);             //2004.11.13
 314   1          SpiReadWrite(0x01);             // One byte RX payload
 315   1          SpiReadWrite(0x01);             // One byte TX payload
 316   1          SpiReadWrite(0xE7); 
 317   1          SpiReadWrite(0xE7); 
 318   1          SpiReadWrite(0xE7); 
 319   1          SpiReadWrite(0xE7); 
 320   1          
 321   1          RACSN = 1;
 322   1      
 323   1          InitTimer();
 324   1          EA = 1;
 325   1      }
 326          
 327          void main(void)
 328          {
 329   1          Init();
 330   1      
 331   1          LED0 = 0;
 332   1          Delayms(10);
 333   1      
 334   1          
 335   1          LED1 = 0;
 336   1          Delayms(10);   
 337   1          
 338   1          LED2 = 0;
 339   1          Delayms(10);   
 340   1      
 341   1      
 342   1          LED0 = 1;           //off led
 343   1          LED1 = 1;
 344   1          LED2 = 1;    
 345   1      
 346   1          while(1)
 347   1          {
 348   2              ScanKey();
 349   2              ReceivePacket();                                
 350   2          }
 351   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    497    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      4       5
   IDATA SIZE       =   ----    ----
   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 + -