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

📄 main.lst

📁 nRF9e5的收发程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
 270   1          while((EXIF & 0x20) == 0x00)    // Wait until SPI hs finished transmitting
 271   1              ;
 272   1          return SPI_DATA;
 273   1      }
 274          
 275          void ReceivePacket()
 276          //unsigned char ReceivePacket()
 277          {
 278   1          unsigned char b;
 279   1      
 280   1          TRX_CE = 1;
 281   1          if(DR)
 282   1          {    
 283   2              RACSN = 0;
 284   2              SpiReadWrite(RRP);
 285   2              b = SpiReadWrite(0);
 286   2              RACSN = 1;
 287   2              TRX_CE = 0;
 288   2              KeyValue=b;
 289   2              PutChar(b);
 290   2              if(L0)  {  LED0=0;      }
 291   2              if(L1)  {  LED1=0;      }       
 292   2              if(L2)  {  LED2=0;      }
 293   2              Delayms(10);
 294   2              LED0=1;                         // LED OFF
 295   2              LED1=1;
 296   2              LED2=1;
 297   2      
 298   2          }
 299   1      
 300   1      //    return b;
 301   1      
 302   1      }
C51 COMPILER V7.50   MAIN                                                                  12/25/2006 16:42:51 PAGE 6   

 303          
 304          void TransmitPacket(unsigned char b)
 305          {
 306   1      
 307   1          RACSN=0;                    // Spi enable for write a spi command   
 308   1          SpiReadWrite(WTA);          // Write address command
 309   1          SpiReadWrite(0xE7);
 310   1          SpiReadWrite(0xE7);
 311   1          SpiReadWrite(0xE7);
 312   1          SpiReadWrite(0xE7);
 313   1          RACSN=1;                    // Spi disable                                          
 314   1          Delay100us(1);            
 315   1      
 316   1          RACSN = 0;
 317   1          SpiReadWrite(WTP);
 318   1          SpiReadWrite(b);
 319   1          RACSN = 1;
 320   1          TRX_CE = 1;
 321   1          Delay100us(10);
 322   1          
 323   1          TRX_CE = 0;
 324   1          while(DR == 0)
 325   1              ;
 326   1      }
 327          
 328          void ScanKey()
 329          {    
 330   1          KeyValue=0x00;
 331   1          
 332   1          if(S0==0)  
 333   1          {   
 334   2              L0=1;
 335   2              LED0=0;
 336   2              Delayms(10);
 337   2              LED0=1;
 338   2           }
 339   1          if(S1==0)  
 340   1          {
 341   2              L1=1; 
 342   2              LED1=0;
 343   2              Delayms(10);
 344   2              LED1=1;         
 345   2          }
 346   1      /*
 347   1          if(S2==0)
 348   1          {
 349   1              L2=1;
 350   1              LED2=0;
 351   1              Delayms(10);
 352   1              LED2=1;
 353   1          }   
 354   1      */    
 355   1          if(KeyValue!=0x00)
 356   1          {
 357   2       //     PutChar(KeyValue);
 358   2              TXEN = 1;
 359   2              TransmitPacket(KeyValue);
 360   2              TXEN=0;
 361   2      //      Delayms(10);
 362   2      //      LED0=1;
 363   2      //      LED1=1;
 364   2      //      LED2=1;
C51 COMPILER V7.50   MAIN                                                                  12/25/2006 16:42:51 PAGE 7   

 365   2          }    
 366   1      }
 367          /*
 368          void Led(unsigned char on)
 369          {
 370              if (on)
 371              {
 372                  P0 &= ~0x01;
 373                  timer = 0;  
 374                  TR0 = 1;                    // Start Timer0
 375              } else
 376                  P0 |= 0x01;
 377          }
 378          */
 379          void InitTimer(void)
 380          {
 381   1          TR0 = 0;
 382   1          TMOD &= ~0x03;
 383   1          TMOD |= 0x01;                   // mode 1
 384   1          CKCON |= 0x08;                  // T0M = 1 (/4 timer clock)
 385   1          t0lrel = 0x60;                  // 1KHz tick...
 386   1          t0hrel = 0xF0;                  // ... = 65536-16e6/(4*1e3) = F060h
 387   1          TF0 = 0;                        // Clear any pending Timer0 interrupts
 388   1          ET0 = 1;                        // Enable Timer0 interrupt
 389   1      }
 390          
 391          void Timer0ISR (void) interrupt 1
 392          {
 393   1          TF0 = 0;                        // Clear Timer0 interrupt
 394   1          TH0 = t0hrel;                   // Reload Timer0 high byte
 395   1          TL0 = t0lrel;                   // Reload Timer0 low byte
 396   1          timer++;
 397   1          if (timer == TIMEOUT)
 398   1          {
 399   2      //        P0 |= 0x01;                 // Led off
 400   2              TR0 = 0;                    // Stop timer
 401   2          }
 402   1      }
 403          /*
 404          void Receiver(void)
 405          {
 406          //    unsigned char b;
 407              unsigned char bo, err;
 408          
 409          
 410              TXEN = 0;
 411              
 412              bo = err = 0;
 413              for(;;)
 414              {
 415          //      b = ReceivePacket();
 416                  Led(ON);
 417              }
 418          }
 419          
 420          void Transmitter(void)
 421          {
 422              unsigned char b;
 423              
 424              TXEN = 1;
 425          
 426              b = 0;
C51 COMPILER V7.50   MAIN                                                                  12/25/2006 16:42:51 PAGE 8   

 427              for(;;)
 428              {
 429                  TransmitPacket(b++);        // Transmit data
 430              }
 431          }
 432          */
 433          void Init(void)
 434          {
 435   1          unsigned char tmp;
 436   1      
 437   1          TH1 = 243;                      // 19200@16MHz (when T1M=1 and SMOD=1)
 438   1          CKCON |= 0x10;                  // T1M=1 (/4 timer clock)
 439   1          PCON = 0x80;                    // SMOD=1 (double baud rate)
 440   1          SCON = 0x52;                    // Serial mode1, enable receiver
 441   1          TMOD = 0x20;                    // Timer1 8bit auto reload 
 442   1          TR1 = 1;                        // Start timer1
 443   1      
 444   1          P0_ALT |= 0x06;                 // Select alternate functions on pins P0.1 and P0.2   
 445   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
 446   1                                          // 11100010
 447   1      //      P0_ALT |= 0x00;
 448   1      //      P0_DIR=0xaa;
 449   1      
 450   1      
 451   1          SPICLK = 1;
 452   1          SPI_CTRL = 0x02;                // Connect internal SPI controller to Radio
 453   1      
 454   1          LED0 = 1;
 455   1          LED1 = 1;
 456   1          LED2 = 1;    
 457   1      
 458   1          // Switch to 16MHz clock:
 459   1          RACSN = 0;
 460   1          SpiReadWrite(RRC | 0x09);
 461   1      //    tmp = SpiReadWrite(0) | 0x04;
 462   1          tmp = SpiReadWrite(0) | 0x0C;
 463   1      
 464   1          RACSN = 1;
 465   1      
 466   1          RACSN = 0;
 467   1          SpiReadWrite(WRC | 0x09);
 468   1          SpiReadWrite(tmp);
 469   1          RACSN = 1;
 470   1      
 471   1          // Configure Radio:
 472   1          RACSN = 0;
 473   1          SpiReadWrite(WRC | 0x03);       // Write to RF config address 3 (RX payload)
 474   1          SpiReadWrite(0x01);             // One byte RX payload
 475   1          SpiReadWrite(0x01);             // One byte TX payload
 476   1          RACSN = 1;
 477   1      
 478   1          RACSN = 0;
 479   1          SpiReadWrite(RRC | 0x01);       // Read RF config address 1
 480   1          tmp = SpiReadWrite(0) & 0xf0;   // Clear the power and frequency setting bits
 481   1          RACSN = 1;
 482   1      
 483   1          RACSN = 0;
 484   1          SpiReadWrite(WRC);              // Write RF config address 0
 485   1          SpiReadWrite(CHANNEL & 0xff);   // CHANNEL bit7..0
 486   1          // Change power defined by POWER above, to 433 or 868/915MHz defined by HFREQ and
 487   1          // bit8 of CHANNEL:
 488   1          SpiReadWrite(tmp | (POWER<<2) | (HFREQ << 1) | ((CHANNEL >> 8) & 0x01));
C51 COMPILER V7.50   MAIN                                                                  12/25/2006 16:42:51 PAGE 9   

 489   1          
 490   1          SpiReadWrite(0x44);             //2004.11.13
 491   1          SpiReadWrite(0x01);             // One byte RX payload
 492   1          SpiReadWrite(0x01);             // One byte TX payload
 493   1          SpiReadWrite(0xE7); 
 494   1          SpiReadWrite(0xE7); 
 495   1          SpiReadWrite(0xE7); 
 496   1          SpiReadWrite(0xE7); 
 497   1          
 498   1          RACSN = 1;
 499   1      
 500   1          InitTimer();
 501   1          EA = 1;
 502   1      }
 503          
 504          void main(void)
 505          {
 506   1          Init();
 507   1      
 508   1          LED0 = 0;
 509   1          Delayms(10);
 510   1          
 511   1          LED1 = 0;
 512   1          Delayms(10);   
 513   1          
 514   1          LED2 = 0;
 515   1          Delayms(10);   
 516   1      
 517   1          LED0 = 1;           //off led
 518   1          LED1 = 1;
 519   1          LED2 = 1;    
 520   1      
 521   1          while(1)
 522   1          {
 523   2      //              Delay8us(1);
 524   2      //              IO18b2 = 1;
 525   2      //              Delay8us(1);
 526   2      //              IO18b2 = 0;
 527   2                      Get_temperature();
 528   2                      PutString(text);
 529   2                      ScanKey();
 530   2                      ReceivePacket();                                
 531   2          }
 532   1      }


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