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

📄 radio.lst

📁 基于nRF9E5的无线通讯程序,该程序使用LM35做温度检测,并通过915M无线频率向外发射.适合做无线通讯的应用.
💻 LST
字号:
C51 COMPILER V7.50   RADIO                                                                 05/14/2006 13:37:20 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE RADIO
OBJECT MODULE PLACED IN radio.OBJ
COMPILER INVOKED BY: C:\Program Files\Keil\C51\BIN\C51.EXE radio.c OPTIMIZE(9,SPEED) 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           *
  20           * $Revision: 6 $
  21           *
  22           *==================================================================================================
  23          */
  24          #include <Nordic\reg9e5.h>
  25          #include "util.h"
  26          #include "radio.h"
  27          
  28          #define HFREQ 1     // 0=433MHz, 1=868/915MHz    19/08/2004 set 915mhz
  29          #define POWER 3     // 0=min power...3 = max power
  30          unsigned char TransmitPacket1(unsigned char *pBuf,unsigned char *pBuf1);
  31          unsigned char ReceivePacket1(unsigned char *pBuf,unsigned char *pBuf1);
  32          static void SwitchChannelAA(void);
  33          const unsigned char code rnd_tab[256] =
  34          {
  35              // This table contains four each of the numbers 2 to 65 (0x02-0x41) randomly distributed.
  36              // If you need longer random cycles than this you could use an 8-bit pseudo random generator
  37              // and use it to index this table.
  38              0x28, 0x29, 0x38, 0x07, 0x19, 0x17, 0x2F, 0x1F, 0x14, 0x16, 0x1F, 0x06, 0x38, 0x1B, 0x3B, 0x33,
  39              0x33, 0x2F, 0x37, 0x1A, 0x32, 0x15, 0x19, 0x34, 0x1B, 0x2D, 0x13, 0x02, 0x3F, 0x18, 0x10, 0x10,
  40              0x0A, 0x1D, 0x0D, 0x37, 0x3D, 0x0B, 0x2A, 0x25, 0x1F, 0x20, 0x41, 0x21, 0x2F, 0x2A, 0x36, 0x09,
  41              0x1C, 0x2C, 0x0F, 0x1E, 0x39, 0x03, 0x06, 0x03, 0x2B, 0x0A, 0x1D, 0x02, 0x24, 0x3A, 0x32, 0x10,
  42              0x16, 0x16, 0x13, 0x12, 0x20, 0x06, 0x13, 0x1F, 0x0D, 0x41, 0x1E, 0x08, 0x3D, 0x31, 0x09, 0x16,
  43              0x23, 0x12, 0x2D, 0x12, 0x31, 0x1C, 0x36, 0x0B, 0x11, 0x21, 0x37, 0x13, 0x38, 0x41, 0x0B, 0x32,
  44              0x1B, 0x33, 0x20, 0x29, 0x0E, 0x05, 0x41, 0x1E, 0x05, 0x0C, 0x38, 0x1D, 0x20, 0x2F, 0x29, 0x39,
  45              0x3D, 0x04, 0x26, 0x10, 0x12, 0x36, 0x3B, 0x08, 0x3D, 0x3C, 0x1A, 0x24, 0x08, 0x07, 0x35, 0x15,
  46              0x2A, 0x40, 0x2C, 0x11, 0x31, 0x28, 0x2A, 0x1E, 0x02, 0x07, 0x19, 0x32, 0x28, 0x39, 0x1A, 0x28,
  47              0x19, 0x22, 0x03, 0x21, 0x39, 0x09, 0x03, 0x0F, 0x3E, 0x2D, 0x0D, 0x37, 0x18, 0x3E, 0x09, 0x25,
  48              0x26, 0x11, 0x36, 0x1A, 0x18, 0x25, 0x3E, 0x29, 0x08, 0x3C, 0x2B, 0x33, 0x02, 0x0A, 0x05, 0x0A,
  49              0x1C, 0x2C, 0x07, 0x23, 0x3E, 0x1B, 0x3F, 0x2E, 0x3B, 0x31, 0x2B, 0x24, 0x35, 0x26, 0x1D, 0x2E,
  50              0x11, 0x3C, 0x15, 0x2B, 0x15, 0x24, 0x2C, 0x27, 0x0D, 0x34, 0x14, 0x23, 0x21, 0x04, 0x3A, 0x27,
  51              0x0F, 0x40, 0x27, 0x0B, 0x30, 0x2E, 0x17, 0x25, 0x3C, 0x34, 0x40, 0x34, 0x0C, 0x2D, 0x30, 0x18,
  52              0x40, 0x0F, 0x22, 0x26, 0x27, 0x3F, 0x30, 0x22, 0x30, 0x3F, 0x23, 0x14, 0x3A, 0x14, 0x3B, 0x0C,
  53              0x06, 0x04, 0x05, 0x3A, 0x35, 0x0E, 0x0E, 0x0C, 0x17, 0x1C, 0x35, 0x0E, 0x04, 0x2E, 0x17, 0x22
  54          };
  55          
C51 COMPILER V7.50   RADIO                                                                 05/14/2006 13:37:20 PAGE 2   

  56          static unsigned char seq, hopIdx, nBytes,PXX;
  57          static unsigned rxTout, txTout;
  58          
  59          static void SwitchChannel(void)
  60          {
  61   1          RACSN = 0;
  62   1          SpiReadWrite(CC | (POWER << 2) | (HFREQ << 1));
  63   1          SpiReadWrite(rnd_tab[hopIdx]);
  64   1          RACSN = 1;
  65   1      }
  66          
  67          static void TransmitBytes(unsigned char *pBuf, unsigned char msgid)
  68          {
  69   1          // Transmit one packet with the format specified in the header of this file:
  70   1          unsigned char i;
  71   1          PXX=pBuf[19];
  72   1          SwitchChannelAA();
  73   1          TXEN = 1;
  74   1          RACSN = 0;
  75   1          SpiReadWrite(WTP);
  76   1          SpiReadWrite(msgid);
  77   1          for (i=0;i<nBytes;i++)
  78   1          {
  79   2              SpiReadWrite(pBuf[i]);
  80   2          }
  81   1          RACSN = 1;
  82   1          TRX_CE = 1;
  83   1          Delay100us(1);
  84   1          TRX_CE = 0;
  85   1          while(DR == 0)
  86   1              ;
  87   1      }
  88          
  89          static void SendAck(unsigned char msgid)
  90          {
  91   1          // Send a one byte acknowledge
  92   1          SwitchChannel();
  93   1          TXEN = 1;
  94   1          RACSN = 0;
  95   1          SpiReadWrite(WTP);
  96   1          SpiReadWrite(msgid);
  97   1          RACSN = 1;
  98   1          TRX_CE = 1;
  99   1          Delay100us(1);
 100   1          TRX_CE = 0;
 101   1          while(DR == 0)
 102   1              ;
 103   1      }
 104          
 105          static unsigned char ReceiveBytes(unsigned char *pBuf)
 106          {
 107   1          unsigned char i, cmd;
 108   1      
 109   1          SwitchChannel();
 110   1          TXEN = 0;
 111   1          TRX_CE = 1;
 112   1          ResetTimer(1);
 113   1          while(DR == 0)
 114   1          {
 115   2              if ((rxTout != 0) && (GetTimer(1) > rxTout))
 116   2              {
 117   3                  TRX_CE = 0;
C51 COMPILER V7.50   RADIO                                                                 05/14/2006 13:37:20 PAGE 3   

 118   3                  return 0;
 119   3              }
 120   2          }
 121   1          TRX_CE = 0;
 122   1          RACSN = 0;
 123   1          SpiReadWrite(RRP);
 124   1          cmd = SpiReadWrite(0);
 125   1          i = 0;
 126   1          while(DR)
 127   1          {
 128   2              pBuf[i++] = SpiReadWrite(0);
 129   2              if (i == nBytes)                        // Play safe
 130   2                  break;
 131   2          }
 132   1          RACSN = 1;
 133   1          return cmd;
 134   1      }
 135          
 136          static unsigned char WaitAck(void)
 137          {
 138   1          unsigned char ack;
 139   1      
 140   1          SwitchChannel();
 141   1          TXEN = 0;
 142   1          TRX_CE = 1;
 143   1      
 144   1          ResetTimer(0);
 145   1          while(DR == 0)
 146   1          {
 147   2              if (GetTimer(0) > 20)                    // 3ms time-out
 148   2              {
 149   3                  TRX_CE = 0;
 150   3                  return 0;
 151   3              }
 152   2          }
 153   1          TRX_CE = 0;
 154   1          RACSN = 0;
 155   1          SpiReadWrite(RRP);
 156   1          ack = SpiReadWrite(0);
 157   1          RACSN = 1;    
 158   1          return ack;
 159   1      }
 160          
 161          unsigned char TransmitPacket(unsigned char *pBuf)
 162          {
 163   1          unsigned int i;
 164   1          unsigned char cmdt, cmdr, j;
 165   1      
 166   1          seq++;
 167   1          cmdt = 0x10 | (seq & 0x0f);
 168   1          cmdr = 0;
 169   1          ResetTimer(1);
 170   1          for(;;)
 171   1          {
 172   2              for (i=0;i<3;i++)
 173   2              {
 174   3                  // Repeat two times on all channels if no ACK is received
 175   3                  for (j=0;j<2;j++)
 176   3                  {
 177   4                      TransmitBytes(pBuf, cmdt);
 178   4                      cmdr = WaitAck();
 179   4                      //if ((cmdr != 0) && ((cmdr & 0x0f) == (cmdt & 0x0f)))
C51 COMPILER V7.50   RADIO                                                                 05/14/2006 13:37:20 PAGE 4   

 180   4                       if (cmdr != 0) 
 181   4                      {
 182   5                       //   hopIdx++;        not hop 19/08/2004
 183   5                          return 1;
 184   5                      }
 185   4                  }
 186   3                 // hopIdx++;  not hop 19/08/2004
 187   3                  if ((txTout != 0) && (GetTimer(1) > txTout))
 188   3                      return 0;
 189   3              }
 190   2          }
 191   1          return 0;
 192   1      }
 193          
 194          unsigned char ReceivePacket(unsigned char *pBuf)
 195          {
 196   1          unsigned char cmd;
 197   1          while(1)
 198   1          {
 199   2              cmd = ReceiveBytes(pBuf);
 200   2              if (cmd == 0)
 201   2                  return 0;
 202   2              cmd = (cmd & 0x0f) | 0x20;
 203   2              SendAck(cmd);
 204   2                        Delay100us(1);
 205   2                SendAck(cmd);
 206   2                Delay100us(10);
 207   2                SendAck(0X20);
 208   2             // hopIdx++;     not hop 19/08/2004
 209   2              if ((cmd & 0x0f) != seq)
 210   2              {
 211   3                  seq = cmd & 0x0f;
 212   3                  break;
 213   3              }
 214   2          }
 215   1          return 1;
 216   1      }
 217          
 218          //void ReceiverTimeout(unsigned tOut)
 219          //{
 220              // Set the receiver timeout in ms.
 221              // 1ms = min timeout, 65536ms is max, 0 means wait forever
 222          //    rxTout = tOut;
 223          //}
 224          
 225          //void TransmitterTimeout(unsigned tOut)
 226          //{
 227              // Set the transmitter timeout in ms.
 228              // 1ms is min timeout, 65536ms is max, 0 means wait forever
 229          //    txTout = tOut;
 230          //}
 231          
 232          static void InitAddress(unsigned char spiAddr, unsigned char *pAddr)
 233          {
 234   1          unsigned char i;
 235   1          RACSN = 0;
 236   1          SpiReadWrite(spiAddr);
 237   1          for(i=0;i<4;i++)
 238   1              SpiReadWrite(pAddr[i]);
 239   1          RACSN = 1;
 240   1      }
 241          
C51 COMPILER V7.50   RADIO                                                                 05/14/2006 13:37:20 PAGE 5   

 242          static void InitCommon(unsigned char nRx, unsigned char nTx)
 243          {
 244   1          hopIdx = 0;                                 // Start at index #0 in the channel table above
 245   1          RACSN = 0;
 246   1          SpiReadWrite(WRC | 0x03);                   // Write to RF config address 3 (RX payload)
 247   1          SpiReadWrite(nRx);
 248   1          SpiReadWrite(nTx);
 249   1          RACSN = 1;
 250   1      }
 251          
 252          void InitReceiver(unsigned char n, unsigned char *pAddr)
 253          {
 254   1          seq = 15;
 255   1          rxTout = 3000;                              // Default 3s timeout
 256   1          nBytes = n;                                 // Number of data bytes (0-25)
 257   1          InitCommon(n+1, 1);
 258   1          if (pAddr != 0)
 259   1              InitAddress(WRC | 0x05, pAddr);         // Configure RX address
 260   1      }
 261          
 262          void InitTransmitter(unsigned char n, unsigned char *pAddr)
 263          {
 264   1          seq = 0;
 265   1          txTout = 3000;                              // Default 3s timeout
 266   1          nBytes = n;                                 // Number of data bytes (0-25)
 267   1          InitCommon(1, n+1);
 268   1          if (pAddr != 0)
 269   1              InitAddress(WTA, pAddr);                // Configure TX address
 270   1      }
 271          //----------------------------SEND BRODCAST  get ID--------------------------------
 272          static void SwitchChannelAA(void)
 273          {
 274   1          RACSN = 0;
 275   1          SpiReadWrite(CC | (PXX << 2) | (HFREQ << 1));
 276   1          SpiReadWrite(rnd_tab[hopIdx]);
 277   1          RACSN = 1;
 278   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    652    ----
   CONSTANT SIZE    =    256    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      8      35
   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 + -