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

📄 radio.lst

📁 9E5无线单片机芯片的整个工程文件 已经在产品中使用
💻 LST
字号:
C51 COMPILER V7.08   RADIO                                                                 12/11/2005 15:43:14 PAGE 1   


C51 COMPILER V7.08, COMPILATION OF MODULE RADIO
OBJECT MODULE PLACED IN radio.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE radio.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          /*= radio.c ========================================================================================
   2           *
   3           * Copyright (C) 2004 Nordic Semiconductor
   4           *
   5           * This file is distributed in the hope that it will be useful, but WITHOUT WARRANTY OF ANY KIND.
   6           *
   7           * Author(s): Ole Saether
   8           *
   9           * DESCRIPTION:
  10           *
  11           *  Packet format:
  12           *
  13           *  [4 byte address][1 byte msg ID][0-25 bytes msg data][16 bit CRC]
  14           *
  15           *
  16           * COMPILER:
  17           *
  18           *   This program has been tested with Keil C51 V7.08
  19           *   01/06/2005 change to send 2time on one time
  20           *
  21           * $Revision: 6 $
  22           *
  23           *==================================================================================================
  24          */
  25          #include "reg9e5.h"
  26          #include "util.h"
  27          #include "radio.h"
  28          
  29          #define HFREQ 1     // 0=433MHz, 1=868/915MHz    19/08/2004 set 915mhz
  30          #define POWER 3     // 0=min power...3 = max power
  31          unsigned char TransmitPacket1(unsigned char *pBuf,unsigned char *pBuf1);
  32          unsigned char ReceivePacket1(unsigned char *pBuf,unsigned char *pBuf1);
  33          extern unsigned char idata buf[];
  34          const unsigned char code rnd_tab[256] =
  35          {
  36              // This table contains four each of the numbers 2 to 65 (0x02-0x41) randomly distributed.
  37              // If you need longer random cycles than this you could use an 8-bit pseudo random generator
  38              // and use it to index this table.
  39              0x28, 0x29, 0x38, 0x07, 0x19, 0x17, 0x2F, 0x1F, 0x14, 0x16, 0x1F, 0x06, 0x38, 0x1B, 0x3B, 0x33,
  40              0x33, 0x2F, 0x37, 0x1A, 0x32, 0x15, 0x19, 0x34, 0x1B, 0x2D, 0x13, 0x02, 0x3F, 0x18, 0x10, 0x10,
  41              0x0A, 0x1D, 0x0D, 0x37, 0x3D, 0x0B, 0x2A, 0x25, 0x1F, 0x20, 0x41, 0x21, 0x2F, 0x2A, 0x36, 0x09,
  42              0x1C, 0x2C, 0x0F, 0x1E, 0x39, 0x03, 0x06, 0x03, 0x2B, 0x0A, 0x1D, 0x02, 0x24, 0x3A, 0x32, 0x10,
  43              0x16, 0x16, 0x13, 0x12, 0x20, 0x06, 0x13, 0x1F, 0x0D, 0x41, 0x1E, 0x08, 0x3D, 0x31, 0x09, 0x16,
  44              0x23, 0x12, 0x2D, 0x12, 0x31, 0x1C, 0x36, 0x0B, 0x11, 0x21, 0x37, 0x13, 0x38, 0x41, 0x0B, 0x32,
  45              0x1B, 0x33, 0x20, 0x29, 0x0E, 0x05, 0x41, 0x1E, 0x05, 0x0C, 0x38, 0x1D, 0x20, 0x2F, 0x29, 0x39,
  46              0x3D, 0x04, 0x26, 0x10, 0x12, 0x36, 0x3B, 0x08, 0x3D, 0x3C, 0x1A, 0x24, 0x08, 0x07, 0x35, 0x15,
  47              0x2A, 0x40, 0x2C, 0x11, 0x31, 0x28, 0x2A, 0x1E, 0x02, 0x07, 0x19, 0x32, 0x28, 0x39, 0x1A, 0x28,
  48              0x19, 0x22, 0x03, 0x21, 0x39, 0x09, 0x03, 0x0F, 0x3E, 0x2D, 0x0D, 0x37, 0x18, 0x3E, 0x09, 0x25,
  49              0x26, 0x11, 0x36, 0x1A, 0x18, 0x25, 0x3E, 0x29, 0x08, 0x3C, 0x2B, 0x33, 0x02, 0x0A, 0x05, 0x0A,
  50              0x1C, 0x2C, 0x07, 0x23, 0x3E, 0x1B, 0x3F, 0x2E, 0x3B, 0x31, 0x2B, 0x24, 0x35, 0x26, 0x1D, 0x2E,
  51              0x11, 0x3C, 0x15, 0x2B, 0x15, 0x24, 0x2C, 0x27, 0x0D, 0x34, 0x14, 0x23, 0x21, 0x04, 0x3A, 0x27,
  52              0x0F, 0x40, 0x27, 0x0B, 0x30, 0x2E, 0x17, 0x25, 0x3C, 0x34, 0x40, 0x34, 0x0C, 0x2D, 0x30, 0x18,
  53              0x40, 0x0F, 0x22, 0x26, 0x27, 0x3F, 0x30, 0x22, 0x30, 0x3F, 0x23, 0x14, 0x3A, 0x14, 0x3B, 0x0C,
  54              0x06, 0x04, 0x05, 0x3A, 0x35, 0x0E, 0x0E, 0x0C, 0x17, 0x1C, 0x35, 0x0E, 0x04, 0x2E, 0x17, 0x22
  55          };
C51 COMPILER V7.08   RADIO                                                                 12/11/2005 15:43:14 PAGE 2   

  56          
  57           unsigned char seq, hopIdx, nBytes,PXX,ch;
  58          static unsigned rxTout, txTout;
  59          
  60          static void SwitchChannel(unsigned char iii)
  61          {
  62   1          RACSN = 0;
  63   1          SpiReadWrite(CC | 0x0e);
  64   1          SpiReadWrite(rnd_tab[iii]);
  65   1          RACSN = 1;
  66   1      }
  67              //
  68          static void TransmitBytes(unsigned char *pBuf)
  69          {
  70   1          // Transmit one packet with the format specified in the header of this file:
  71   1          unsigned char i;
  72   1          PXX=pBuf[19];
  73   1          SwitchChannel(0);;//在将程序写入到RX1和RX2的时候需要改变该函数的输入值
  74   1                            //在这里我们将RX2的频道放在2上,所以在向RX2写入程序的时候将其改为
  75   1                            //SwitchChannel(2);
  76   1          TXEN = 1;
  77   1          RACSN = 0;
  78   1          SpiReadWrite(WTP);
  79   1          //SpiReadWrite(msgid);
  80   1          for (i=0;i<nBytes;i++)
  81   1          {
  82   2             SpiReadWrite(pBuf[i]);
  83   2          }
  84   1          RACSN = 1;
  85   1          TRX_CE = 1;
  86   1          Delay100us(1);
  87   1          TRX_CE = 0;
  88   1          while(DR == 0)
  89   1              ;
  90   1      }
  91          static unsigned char ReceiveBytes(unsigned char *pBuf)
  92          {
  93   1          unsigned char i;
  94   1              while(1)
  95   1              {
  96   2              SwitchChannel(0);
  97   2              TXEN = 0;
  98   2                  TRX_CE = 1;
  99   2              ResetTimer(1);
 100   2                  while(DR == 0)
 101   2              {
 102   3                      if ((rxTout != 0) && (GetTimer(1) > rxTout))
 103   3                      {
 104   4                      TRX_CE = 0;
 105   4                          return 0;
 106   4                      }
 107   3              }
 108   2              TRX_CE = 0;
 109   2                  RACSN  = 0;
 110   2              SpiReadWrite(RRP);
 111   2                  i = 0;
 112   2              while(DR)
 113   2                  {
 114   3                      pBuf[i++] = SpiReadWrite(0);
 115   3                      if (i == nBytes)                        // Play safe
 116   3                  break;
 117   3                       }
C51 COMPILER V7.08   RADIO                                                                 12/11/2005 15:43:14 PAGE 3   

 118   2              RACSN = 1;
 119   2                      return 1;
 120   2              };
 121   1      }
 122          
 123          
 124          
 125          unsigned char TransmitPacket(unsigned char *pBuf)
 126          {
 127   1         // unsigned int i;
 128   1          ResetTimer(1);
 129   1          TransmitBytes(pBuf);
 130   1          if ((txTout != 0) && (GetTimer(1) > txTout))
 131   1          return 0;
 132   1      }
 133          
 134          unsigned char ReceivePacket(unsigned char *pBuf)
 135          {
 136   1          unsigned char cmd;
 137   1          while(1)
 138   1          {
 139   2              cmd = ReceiveBytes(pBuf);
 140   2              if (cmd == 0)
 141   2                  return 0;
 142   2                      else if(cmd == 1)
 143   2                              return 1;
 144   2          }   
 145   1      }
 146          
 147          static void InitAddress(unsigned char spiAddr, unsigned char *pAddr)
 148          {
 149   1          unsigned char i;
 150   1          RACSN = 0;
 151   1          SpiReadWrite(spiAddr);
 152   1          for(i=0;i<4;i++)
 153   1              SpiReadWrite(pAddr[i]);
 154   1          RACSN = 1;
 155   1      }
 156          
 157          static void InitCommon(unsigned char nRx, unsigned char nTx)
 158          {
 159   1          hopIdx = 0;                                 // Start at index #0 in the channel table above
 160   1          RACSN = 0;
 161   1          SpiReadWrite(WRC | 0x03);                   // Write to RF config address 3 (RX payload)
 162   1          SpiReadWrite(nRx);
 163   1          SpiReadWrite(nTx);
 164   1          RACSN = 1;
 165   1      }
 166          
 167          void InitReceiver(unsigned char n, unsigned char *pAddr)
 168          {
 169   1          seq = 15;
 170   1          rxTout = 50;                              // Default 3s timeout
 171   1          nBytes = n;                                 // Number of data bytes (0-25)
 172   1          InitCommon(n, 1);
 173   1          if (pAddr != 0)
 174   1              InitAddress(WRC | 0x05, pAddr);         // Configure RX address
 175   1      }
 176          
 177          void InitTransmitter(unsigned char n, unsigned char *pAddr)
 178          {
 179   1          seq = 0;
C51 COMPILER V7.08   RADIO                                                                 12/11/2005 15:43:14 PAGE 4   

 180   1         // txTout = 3000;                              // Default 3s timeout
 181   1          txTout = 300;                              // Default 3s timeout
 182   1          nBytes = n;                                 // Number of data bytes (0-25)
 183   1          InitCommon(0, n);
 184   1          if (pAddr != 0)
 185   1              InitAddress(WTA, pAddr);                // Configure TX address
 186   1      }
 187          //---------------------END RADIO----------------------------------------------------------


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