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

📄 9e5quick.lst

📁 nRF9E5设计参考源代码
💻 LST
字号:
C51 COMPILER V7.08   9E5QUICK                                                              11/13/2004 15:19:38 PAGE 1   


C51 COMPILER V7.08, 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    S2      =P0^7;
  55          
C51 COMPILER V7.08   9E5QUICK                                                              11/13/2004 15:19:38 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.08   9E5QUICK                                                              11/13/2004 15:19:38 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          if(S2==0)
 171   1          {
 172   2              L2=1;
 173   2              LED2=0;
 174   2              Delayms(10);
 175   2              LED2=1;
 176   2          }   
 177   1          
 178   1          if(KeyValue!=0x00)
 179   1          {
C51 COMPILER V7.08   9E5QUICK                                                              11/13/2004 15:19:38 PAGE 4   

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

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

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


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