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

📄 main.lst

📁 nRF9e5的收发程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.50   MAIN                                                                  12/25/2006 16:42:51 PAGE 1   


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

line level    source

   1          /*===============================================================================================
   2           *
   3           * Copyright (C) 2004 
   4           *
   5           * This file is distributed in the hope that it will be useful, but WITHOUT
   6           * WARRANTY OF ANY KIND.
   7           *
   8           * Author(s):
   9           *
  10           * DESCRIPTION: for nRF9E5
  11           *
  12           *  nRF9E5/nRF24E1 range demo. Select receiver by shorting P03 and P05 and transmitter by shorting
  13           *  P05 and P06. Uncomment/comment the appropriate #define below to select nRF9E5 or nRF24E1.
  14           *
  15           *  The transmitter continously send one byte packets. Each time the receiver receives a packet the
  16           *  P00 pin is set low (LED1 is turned on on the 9E5 eval board). At the same time a 20ms timer is
  17           *  started and if a new packets is not received before the 20ms time-out the P00 pin is set high
  18           *  (LED1 is turned off). If a new packet is received before the time-out a new 20ms time-out period
  19           *  is started.
  20           *
  21           *  Please remember to turn off the RS232 switch on the receiver and transmitter boards. On the
  22           *  nRF9E5 board turn off all dip-switches on the transmitter and turn on only the LED1 switch on
  23           *  the receiver.
  24           *
  25           * COMPILER:
  26           *  
  27           *  This program has been tested with Keil C51 V7.09
  28           *
  29           * $Revision: 1 $
  30           *
  31           *==================================================================================================
  32          */
  33          // Comment out the following line for nRF24E1
  34          
  35          #include <reg9e5.h>
  36          #define POWER      3                // 0=min power...3 = max power
  37          #define HFREQ      0                // 0=433MHz, 1=868/915MHz
  38          #define CHANNEL  351                // Channel number: f(MHz) = (422.4+CHANNEL/10)*(1+HFREQ) 
  39          
  40          #define TIMEOUT    20               // 20ms time-out on LED
  41          #define ON          1
  42          #define OFF         0
  43          
  44          static volatile unsigned char timer;
  45          static volatile unsigned char t0lrel, t0hrel;
  46          
  47          unsigned char bdata KeyValue;
  48          sbit  L0 = KeyValue^4;
  49          sbit  L1 = KeyValue^5;
  50          sbit  L2 = KeyValue^6;
  51          
  52          sbit    S0      =P0^5;
  53          sbit    S1      =P0^6;
  54          sbit    IO18b2  =P0^7;
  55          
C51 COMPILER V7.50   MAIN                                                                  12/25/2006 16:42:51 PAGE 2   

  56          sbit    LED0    =P0^0;
  57          sbit    LED1    =P0^3;
  58          sbit    LED2    =P0^4;
  59          
  60          unsigned char text[]="The temperature is      ℃ \n ";
  61          
  62          void Delay8us(volatile unsigned char n)   //
  63          {
  64   1         
  65   1          while(n--);
  66   1              
  67   1      }
  68          void Delay100us(volatile unsigned char n)
  69          {
  70   1          unsigned char i;
  71   1          while(n--)
  72   1              for(i=0;i<33;i++)
  73   1                  ;
  74   1      }
  75          
  76          void Delayms(int n)
  77          {
  78   1          unsigned char i;
  79   1          while(n--)
  80   1              for(i=0;i<10;i++)
  81   1              Delay100us(1);
  82   1      }
  83          // init 18B20
  84          int init_1820()
  85          {
  86   1      
  87   1              int i;
  88   1      
  89   1      //      P0_ALT |= 0x06;                 // Select alternate functions on pins P0.1 and P0.2   
  90   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
  91   1              IO18b2 = 1;
  92   1              Delay100us(1);
  93   1              IO18b2 = 0;
  94   1              Delay100us(3);
  95   1              IO18b2 = 1;
  96   1      
  97   1              for(i=100;i > 0;i--)
  98   1              {
  99   2      //              P0_ALT |= 0x06;                 // Select alternate functions on pins P0.1 and P0.2   
 100   2      //      P0_DIR = 0xE2;              // P0.0 out,P0.1 input(RXD),P0.2 P0.3 P0.4 output,P0.5 P0.6 P0.7 input
 101   2                      if(IO18b2 == 0)
 102   2                      {
 103   3                              Delay100us(1);
 104   3      //                      printf ("      ");
 105   3                              return 1;
 106   3                      }
 107   2              }
 108   1      
 109   1              return 0;
 110   1      }
 111          //Write  18B20
 112          void Write_1820(unsigned char Wdata)
 113          {
 114   1              unsigned char i;
 115   1      
 116   1      //      P0_ALT |= 0x06;                 // Select alternate functions on pins P0.1 and P0.2   
 117   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
C51 COMPILER V7.50   MAIN                                                                  12/25/2006 16:42:51 PAGE 3   

 118   1              for(i=0;i < 8;i++)
 119   1              {
 120   2                      
 121   2                      IO18b2 = 0;
 122   2                      Delay8us(1);
 123   2                  
 124   2                      if(Wdata & 0x01)
 125   2                      {
 126   3                              IO18b2 = 1;
 127   3                      }
 128   2              
 129   2                      Delay8us(10);
 130   2      
 131   2                      IO18b2 = 1;
 132   2                      Delay8us(1);
 133   2                      Wdata = Wdata >> 1;
 134   2              }
 135   1      
 136   1      }
 137          //Read 18B20
 138          unsigned char Read_1820()
 139          {
 140   1              unsigned char i,temp,j;
 141   1              temp = 0x00;
 142   1              for(i=0;i <8;i++)
 143   1              {
 144   2      //              P0_ALT |= 0x06;                 // Select alternate functions on pins P0.1 and P0.2   
 145   2      //        P0_DIR = 0x62;                    // P0.0 out,P0.1 input(RXD),P0.2 P0.3 P0.4 output,P0.5 P0.6 P0.7 inpu
             -t
 146   2      
 147   2                      IO18b2 = 0;
 148   2                      Delay8us(1);
 149   2                      IO18b2 = 1;
 150   2      
 151   2      //              P0M1 = 0x08;     //push pull except RX
 152   2      //          P0M2 = 0x00;
 153   2                      for(j=0;j < 2;j++ );
 154   2      
 155   2      //              P0_ALT |= 0x06;                 // Select alternate functions on pins P0.1 and P0.2   
 156   2      //      P0_DIR = 0xE2;              // P0.0 out,P0.1 input(RXD),P0.2 P0.3 P0.4 output,P0.5 P0.6 P0.7 input
 157   2      
 158   2                      if(IO18b2 == 1)
 159   2                      {
 160   3                              temp = temp | 0x80; 
 161   3                      }
 162   2                      Delay8us(10);
 163   2      
 164   2      //              P0M1 = 0x00;     //push pull except RX
 165   2      //          P0M2 = 0x00;
 166   2      //              P0_ALT |= 0x06;                 // Select alternate functions on pins P0.1 and P0.2   
 167   2      //      P0_DIR = 0x62;              // P0.0 out,P0.1 input(RXD),P0.2 P0.3 P0.4 output,P0.5 P0.6 P0.7 input
 168   2                      IO18b2 = 1;
 169   2      
 170   2      //              P0_ALT |= 0x06;                 // Select alternate functions on pins P0.1 and P0.2   
 171   2      //      P0_DIR = 0xE2;              // P0.0 out,P0.1 input(RXD),P0.2 P0.3 P0.4 output,P0.5 P0.6 P0.7 input
 172   2      //              Delay10us(1);
 173   2                      while(!IO18b2);
 174   2                      if(i==7) 
 175   2                      {
 176   3                              return temp;
 177   3                      }
 178   2                      else
C51 COMPILER V7.50   MAIN                                                                  12/25/2006 16:42:51 PAGE 4   

 179   2                      {
 180   3                              temp = temp >> 1;
 181   3                      }
 182   2      
 183   2              }
 184   1      
 185   1      }
 186          //Get temp
 187          void Get_temperature()
 188          {
 189   1              unsigned char Send[4];
 190   1      
 191   1              init_1820();
 192   1              Delayms(1);
 193   1              Write_1820(0xCC);
 194   1              Delayms(1);
 195   1      
 196   1              Write_1820(0x44);
 197   1      
 198   1              Delayms(700);
 199   1      
 200   1              init_1820();
 201   1              Delayms(1);
 202   1      
 203   1              Write_1820(0xCC);
 204   1              Delayms(1);
 205   1      
 206   1              Write_1820(0xBE);
 207   1              Delayms(1);
 208   1      
 209   1              Send[0]=Read_1820();
 210   1              Send[1]=Read_1820();
 211   1      
 212   1      //      sendtoPC(Send[0]);
 213   1      //      sendtoPC(Send[1]);
 214   1      
 215   1      
 216   1              if(Send[1] > 0x0F)      text[20] = '-';
 217   1              else text[20] = '+';
 218   1      
 219   1              Send[1] = Send[1] & 0x07;
 220   1      
 221   1              if(text[20] == '+')
 222   1              {
 223   2      
 224   2                  Send[1] = Send[1] & 0x07;
 225   2              
 226   2                      Send[2] = (Send[1]*16) + ((float)Send[0]*0.0625);
 227   2              
 228   2                      text[21] = Send[2]/100 + 0x30;
 229   2              
 230   2                  text[22] = Send[2]/10 + 0x30;
 231   2              
 232   2                      text[23] = Send[2]%10 + 0x30;
 233   2              }
 234   1              else
 235   1              {
 236   2                              
 237   2                      Send[1] = Send[1] ^ 0xFF;
 238   2                      Send[2] = Send[2] ^ 0xFF;
 239   2      
 240   2                      Send[2] = (Send[1]*16) + ((float)Send[0]*0.0625);
C51 COMPILER V7.50   MAIN                                                                  12/25/2006 16:42:51 PAGE 5   

 241   2              
 242   2                      text[21] = Send[2]/100 + 0x30;
 243   2              
 244   2                  text[22] = Send[2]/10 + 0x30;
 245   2              
 246   2                      text[23] = Send[2]%10 + 0x30;
 247   2              }
 248   1      
 249   1      //      sendtoPC(Send[2]);
 250   1      }
 251          
 252          void PutChar(char c)
 253          {
 254   1          while(!TI)
 255   1              ;
 256   1          TI = 0;
 257   1          SBUF = c;
 258   1      }
 259          
 260          void PutString(const char *s)
 261          {
 262   1          while(*s != 0)
 263   1              PutChar(*s++);
 264   1      }
 265          
 266          unsigned char SpiReadWrite(unsigned char b)
 267          {
 268   1          EXIF &= ~0x20;                  // Clear SPI interrupt
 269   1          SPI_DATA = b;                   // Move byte to send to SPI data register

⌨️ 快捷键说明

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