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

📄 89lv51.lst

📁 基于NRF24L01的51开发板源程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.02   89LV51                                                                05/25/2009 10:15:16 PAGE 1   


C51 COMPILER V8.02, COMPILATION OF MODULE 89LV51
OBJECT MODULE PLACED IN 89lv51.OBJ
COMPILER INVOKED BY: C:\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

line level    source

   1          #include <reg51.h>
   2          #include <intrins.h>
   3          #include "api.h"
   4          /***************************************************/
   5          #define uchar unsigned char
   6          #define TX_ADR_WIDTH    5   // 5 bytes TX(RX) address width
   7          #define TX_PLOAD_WIDTH  20  // 20 bytes TX payload
   8          
   9          uchar const TX_ADDRESS[TX_ADR_WIDTH]  = {0x34,0x43,0x10,0x10,0x01}; // Define a static TX address
  10          
  11          uchar rx_buf[TX_PLOAD_WIDTH];
  12          uchar tx_buf[TX_PLOAD_WIDTH]; 
  13          uchar code as[]=" Receving Data:\0";
  14          uchar flag,b;
  15          /**************************************************/
  16          sbit CE =  P2^5;
  17          sbit CSN=  P2^0;
  18          sbit SCK=  P2^1;
  19          sbit MOSI= P2^2;
  20          sbit MISO= P2^3;
  21          sbit IRQ = P3^2;
  22          /**************************************************/
  23          uchar   bdata sta;
  24          sbit    RX_DR   =sta^6;
  25          sbit    TX_DS   =sta^5;
  26          sbit    MAX_RT  =sta^4;
  27          /**************************************************/
  28          
  29          /**************************************************
  30          Function: init_io();
  31          Description:
  32            flash led one time,chip enable(ready to TX or RX Mode),
  33            Spi disable,Spi clock line init high
  34          /**************************************************/
  35          void init_io(void)
  36          {
  37   1              P0=0x0f;                // led light
  38   1              CE=0;                   // chip enable
  39   1              CSN=1;                  // Spi disable  
  40   1              SCK=0;                  // Spi clock line init high
  41   1              P0=0xff;                // led close
  42   1      }
  43          /**************************************************/
  44          
  45          /**************************************************
  46          Function: Inituart();
  47          
  48          Description:
  49            set uart working mode 
  50          /**************************************************/
  51          void Inituart(void)
  52          {
  53   1              TMOD = 0x20;                            //timer1 working mode 1
  54   1              TL1 = 0xfd;                                     //f7=9600 for 16mhz Fosc,and ... 
C51 COMPILER V8.02   89LV51                                                                05/25/2009 10:15:16 PAGE 2   

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

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

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

⌨️ 快捷键说明

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