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

📄 2.4g+̤

📁 2.4G无线模块资料
💻 4G+̤
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.06   89LV51                                                                09/09/2010 14:47:46 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE 89LV51
OBJECT MODULE PLACED IN 89lv51.OBJ
COMPILER INVOKED BY: D:\Program Files\Keil\C51\BIN\C51.EXE 89lv51.c BROWSE INCDIR(D:\BAO\copy\24L01\新版24L01\source cod
                    -e new\24L01 source code\) DEBUG OBJECTEXTEND

stmt level    source

   1          #include <reg51.h>
   2          #include <intrins.h>
   3          #include "api.h"
   4          /*
   5          *This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTYT; 
   6          *
   7          *uart:9600BPS
   8          
   9          */
  10          /***************************************************/
  11          #define uchar unsigned char
  12          #define TX_ADR_WIDTH    5   // 5 bytes TX(RX) address width
  13          #define TX_PLOAD_WIDTH  20  // 20 bytes TX payload
  14          
  15          uchar const TX_ADDRESS[TX_ADR_WIDTH]  = {0x34,0x43,0x10,0x10,0x01}; // Define a static TX address
  16          
  17          uchar rx_buf[TX_PLOAD_WIDTH];
  18          uchar tx_buf[TX_PLOAD_WIDTH];
  19          uchar flag;
  20          /**************************************************/
  21          sbit CE =  P1^0;
  22          sbit CSN=  P1^1;
  23          sbit SCK=  P1^2;
  24          sbit MOSI= P1^3;
  25          sbit MISO= P1^4;
  26          sbit IRQ = P1^5;
  27          /**************************************************/
  28          uchar   bdata sta;
  29          sbit    RX_DR   =sta^6;
  30          sbit    TX_DS   =sta^5;
  31          sbit    MAX_RT  =sta^4;
  32          /**************************************************/
  33          
  34          /**************************************************
  35          Function: init_io();
  36          Description:
  37            flash led one time,chip enable(ready to TX or RX Mode),
  38            Spi disable,Spi clock line init high
  39          /**************************************************/
  40          #define KEY 0xaa
  41          void init_io(void)
  42          {
  43   1              P0=KEY;         // led light
  44   1              CE=0;                   // chip enable
  45   1              CSN=1;                  // Spi disable  
  46   1              SCK=0;                  // Spi clock line init high
  47   1              P0=0xff;                // led close
  48   1      }
  49          /**************************************************/
  50          
  51          /**************************************************
  52          Function: Inituart();
  53          
  54          Description:
C51 COMPILER V7.06   89LV51                                                                09/09/2010 14:47:46 PAGE 2   

  55            set uart working mode 
  56          /**************************************************/
  57          void Inituart(void)
  58          {
  59   1              TMOD = 0x20;                            //timer1 working mode 1
  60   1              TL1 = 0xfd;                                     //f7=9600 for 16mhz Fosc,and ... 
  61   1              TH1 = 0xfd;                                     //...fd=19200 for 11.0592mhz Fosc
  62   1              SCON = 0xd8;                            //uart mode 3,ren==1
  63   1              PCON = 0x80;                            //smod=0
  64   1              TR1 = 1;                                        //start timer1
  65   1      }
  66          /**************************************************/
  67          
  68          /**************************************************
  69          Function: init_int0();
  70          
  71          Description:
  72            enable int0 interrupt;
  73          /**************************************************/
  74          void init_int0(void)
  75          {
  76   1              EA=1;
  77   1              EX0=1;                                          // Enable int0 interrupt.
  78   1      }
  79          /**************************************************/
  80          
  81          /**************************************************
  82          Function: delay100();
  83          
  84          Description:
  85            delay 100ms
  86          /**************************************************
  87          void delay(uchar )
  88          {
  89                  uchar  x;
  90                  uchar  y;
  91                  for(x=0;x<100;x++)
  92                  {
  93                          for(y=0;y<100;y++)
  94                          _nop_();
  95                  }
  96          }
  97          
  98          /**************************************************/
  99          void delay_ms(unsigned int x)
 100          {
 101   1          unsigned int i,j;
 102   1          i=0;
 103   1          for(i=0;i<x;i++)
 104   1          {
 105   2             j=108;
 106   2                 ;
 107   2             while(j--);
 108   2          }
 109   1      }
 110          /**************************************************/
 111          
 112          /**************************************************
 113          Function: SPI_RW();
 114          
 115          Description:
 116            Writes one byte to nRF24L01, and return the byte read
C51 COMPILER V7.06   89LV51                                                                09/09/2010 14:47:46 PAGE 3   

 117            from nRF24L01 during write, according to SPI protocol
 118          /**************************************************/
 119          uchar SPI_RW(uchar byte)
 120          {
 121   1              uchar bit_ctr;
 122   1              for(bit_ctr=0;bit_ctr<8;bit_ctr++)   // output 8-bit
 123   1              {
 124   2                      MOSI = (byte & 0x80);         // output 'byte', MSB to MOSI
 125   2                      byte = (byte << 1);           // shift next bit into MSB..
 126   2                      SCK = 1;                      // Set SCK high..
 127   2                      byte |= MISO;                     // capture current MISO bit
 128   2                      SCK = 0;                          // ..then set SCK low again
 129   2              }
 130   1          return(byte);                         // return read byte
 131   1      }
 132          /**************************************************/
 133          
 134          /**************************************************
 135          Function: SPI_RW_Reg();
 136          
 137          Description:
 138            Writes value 'value' to register 'reg'
 139          /**************************************************/
 140          uchar SPI_RW_Reg(BYTE reg, BYTE value)
 141          {
 142   1              uchar status;
 143   1      
 144   1              CSN = 0;                   // CSN low, init SPI transaction
 145   1              status = SPI_RW(reg);      // select register
 146   1              SPI_RW(value);             // ..and write value to it..
 147   1              CSN = 1;                   // CSN high again
 148   1      
 149   1              return(status);            // return nRF24L01 status byte
 150   1      }
 151          /**************************************************/
 152          
 153          /**************************************************
 154          Function: SPI_Read();
 155          
 156          Description:
 157            Read one byte from nRF24L01 register, 'reg'
 158          /**************************************************/
 159          BYTE SPI_Read(BYTE reg)
 160          {
 161   1              BYTE reg_val;
 162   1      
 163   1              CSN = 0;                // CSN low, initialize SPI communication...
 164   1              SPI_RW(reg);            // Select register to read from..
 165   1              reg_val = SPI_RW(0);    // ..then read registervalue
 166   1              CSN = 1;                // CSN high, terminate SPI communication
 167   1      
 168   1              return(reg_val);        // return register value
 169   1      }
 170          /**************************************************/
 171          
 172          /**************************************************
 173          Function: SPI_Read_Buf();
 174          
 175          Description:
 176            Reads 'bytes' #of bytes from register 'reg'
 177            Typically used to read RX payload, Rx/Tx address
 178          /**************************************************/
C51 COMPILER V7.06   89LV51                                                                09/09/2010 14:47:46 PAGE 4   

 179          uchar SPI_Read_Buf(BYTE reg, BYTE *pBuf, BYTE bytes)
 180          {
 181   1              uchar status,byte_ctr;
 182   1      
 183   1              CSN = 0;                                // Set CSN low, init SPI tranaction
 184   1              status = SPI_RW(reg);                   // Select register to write to and read status byte
 185   1      
 186   1              for(byte_ctr=0;byte_ctr<bytes;byte_ctr++)
 187   1              pBuf[byte_ctr] = SPI_RW(0);    // Perform SPI_RW to read byte from nRF24L01
 188   1      
 189   1              CSN = 1;                           // Set CSN high again
 190   1      
 191   1              return(status);                    // return nRF24L01 status byte
 192   1      }
 193          /**************************************************/
 194          
 195          /**************************************************
 196          Function: SPI_Write_Buf();
 197          
 198          Description:
 199            Writes contents of buffer '*pBuf' to nRF24L01
 200            Typically used to write TX payload, Rx/Tx address
 201          /**************************************************/
 202          uchar SPI_Write_Buf(BYTE reg, BYTE *pBuf, BYTE bytes)
 203          {
 204   1              uchar status,byte_ctr;
 205   1      
 206   1              CSN = 0;                   // Set CSN low, init SPI tranaction
 207   1              status = SPI_RW(reg);    // Select register to write to and read status byte
 208   1              for(byte_ctr=0; byte_ctr<bytes; byte_ctr++) // then write all byte in buffer(*pBuf)
 209   1              SPI_RW(*pBuf++);
 210   1              CSN = 1;                 // Set CSN high again
 211   1              return(status);          // return nRF24L01 status byte
 212   1      }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -