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

📄 t905.lst

📁 无线遥控副机程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.01  T905                                                                   08/01/2006 10:05:32 PAGE 1   


C51 COMPILER V7.01, COMPILATION OF MODULE T905
OBJECT MODULE PLACED IN T905.OBJ
COMPILER INVOKED BY: C:\keil\C51\BIN\C51.EXE T905.c BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          /******************************************************************************************\ 
   2          ============================================================================================
   3          * T905.c
   4          *
   5          * This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTYT; 
   6          * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   7          *
   8          *
   9          * NOTES:
  10          * This program is for the nRF905 with 232 interface;
  11          * $write date: 2004.4.7;time 11:00$
  12          * $Revision: 1 $
  13          *
  14          /*******************************************************************************************/
  15          #include <reg51.h>
  16          #include <intrins.h>
  17          
  18          #define uchar unsigned char 
  19          #define uint  unsigned int
  20          
  21          #define WC              0x00                    // Write configuration register command
  22          #define RC              0x10                    // Read  configuration register command
  23          #define WTP             0x20                    // Write TX Payload  command
  24          #define RTP             0x21                    // Read  TX Payload  command
  25          #define WTA             0x22                    // Write TX Address  command
  26          #define RTA             0x23                    // Read  TX Address  command
  27          #define RRP             0x24                    // Read  RX Payload  command
  28          /*******************************************************************************************/
  29          
  30          
  31          #define  TXBUFF_LEN             20
  32          #define  RXBUFF_LEN                     20
  33          #define  RECEIVE_LEN_RF         0xc
  34          #define  SEND_LEN_RF            0x6
  35          
  36          
  37          typedef struct RFConfig
  38          {
  39                  uchar n;
  40                  uchar buf[10];
  41          }RFConfig;
  42          
  43          code RFConfig RxTxConf =
  44          {
  45                  10,
  46                  0x01, 0x0c, 0x44,RECEIVE_LEN_RF, SEND_LEN_RF, 0xcc, 0xcc, 0xcc,0xcc, 0x58       
  47          };
  48          // The content of this struct is nRF905's initialize data.
  49          // CH_NO=1;433MHZ;Normal Opration,No Retrans;RX,TX Address is 4 Bytes
  50          // RX TX Payload Width is 32 Bytes;Disable Extern Clock;Fosc=16MHZ
  51          // 8 Bits CRC And enable
  52          /*******************************************************************************************/
  53          uchar idata Rs232TxBuf[TXBUFF_LEN];
  54          uchar idata Rs232RxBuf[RXBUFF_LEN];
  55          
C51 COMPILER V7.01  T905                                                                   08/01/2006 10:05:32 PAGE 2   

  56          uchar idata rf_send_flag,rs232_send_flag;
  57          
  58          /*******************************************************************************************/
  59          uchar bdata DATA_BUF;
  60          sbit    flag    =DATA_BUF^7;
  61          sbit    flag1   =DATA_BUF^0;
  62          /*******************************************************************************************/
  63          sbit    TX_EN   =P1^1;
  64          sbit    TRX_CE  =P1^3;
  65          sbit    PWR_UP  =P1^2;
  66          sbit    MISO    =P1^6;
  67          sbit    MOSI    =P1^5;
  68          sbit    SCK             =P1^7;
  69          sbit    CSN             =P1^4;
  70          
  71          sbit    AM              =P3^2;
  72          sbit    DR              =P3^3;
  73          sbit    CD              =P3^4;
  74          
  75          /*******************************************************************************************/
  76          void InitIO(void);                                      // Initialize IO port
  77          void Inituart(void);                            // initialize 232 uart
  78          void Config905(void);                           // Config nRF905 module
  79          void SetTxMode(void);                           // Set nRF905 in Tx mode
  80          void SetRxMode(void);                           // Set nRF905 in Rx mode
  81          void TxPacket(void);                            // Send data by nRF905
  82          void RxPacket(void);                            // Recive data by nRF905
  83          void SpiWrite(uchar);                           // Write data to nRF905
  84          uchar SpiRead(void);                            // Read data to nRF905
  85          void Delay(uchar n);                            // Delay 100us
  86          void Scankey(void);                                     // Scan key
  87          void init_rxbuf(void);
  88          void rf_send_pakage(void);
  89          
  90          void TxPacket_special(void);
  91          void rs232_tx_pakage(void);
  92          
  93          /*******************************************************************************************/
  94          //function main();
  95          /*******************************************************************************************/
  96          
  97          #pragma rb (0)
  98          void main(void)
  99          {       
 100   1              InitIO();                                       // Initialize IO port
 101   1              init_rxbuf();
 102   1              Inituart();                                     // initialize 232 uart
 103   1              Config905();                            // Config nRF905 module
 104   1              SetTxMode();                            // Set Tx Mode
 105   1      //      TxPacket();                                     // Transmit Tx buffer data
 106   1              Delay(500);                                     // delay for led light  
 107   1              P0=0xff;                                        // led close
 108   1              SetRxMode();                            // Set nRF905 in Rx mode
 109   1              while(1)                                        // circulation
 110   1              {       
 111   2                      if((DR)&&(rs232_send_flag==0))  // If recive data ready... 
 112   2                      RxPacket();                             // ... recive data
 113   2                      rs232_tx_pakage();
 114   2               
 115   2                      rf_send_pakage();
 116   2                      Delay(5);       
 117   2                      //Scankey();                    // Scan key             
C51 COMPILER V7.01  T905                                                                   08/01/2006 10:05:32 PAGE 3   

 118   2              }       
 119   1      }
 120          
 121          /*******************************************************************************************/
 122          //function InitIO();
 123          /*******************************************************************************************/
 124          void InitIO(void)
 125          {
 126   1              P0=0x0f;                                        // led light
 127   1              CSN=1;                                          // Spi  disable                                         
 128   1              SCK=0;                                          // Spi clock line init high
 129   1              DR=1;                                           // Init DR for input
 130   1              AM=1;                                           // Init AM for input
 131   1              PWR_UP=1;                                       // nRF905 power on
 132   1              TRX_CE=0;                                       // Set nRF905 in standby mode
 133   1              TX_EN=0;                                        // set radio in Rx mode 
 134   1      }
 135          
 136          /*******************************************************************************************/
 137          //function Inituart();
 138          /*******************************************************************************************/
 139          void Inituart(void)
 140          {
 141   1              TMOD |= 0x20;                           // timer1 working mode 1
 142   1              TL1 = 0xfd;                                 // f7=9600 for 16mhz Fosc,and ... 
 143   1              TH1 = 0xfd;                                 // ...fd=19200 for 11.0592mhz Fosc
 144   1              SCON = 0x50;                            // uart mode 2,ren==1
 145   1              PCON = 0x0;                                 // smod=0
 146   1              ES=1;
 147   1              EA=1;
 148   1              TR1 = 1;  
 149   1      }
 150          
 151          /*******************************************************************************************/
 152          //function Config905();
 153          /*******************************************************************************************/
 154          void Config905(void)
 155          {
 156   1              uchar i;                                        
 157   1              CSN=0;                                          // Spi enable for write a spi command
 158   1              SpiWrite(WC);                           // Write config command
 159   1              for (i=0;i<RxTxConf.n;i++)      // Write configration words
 160   1              {
 161   2                      SpiWrite(RxTxConf.buf[i]);
 162   2              }
 163   1              CSN=1;                                          // Disable Spi
 164   1      }
 165          
 166          /*******************************************************************************************/
 167          //function Delay100us();Delay 100us
 168          /*******************************************************************************************/
 169          void Delay(uchar n)
 170          {
 171   1              uint i;
 172   1              while(n--)
 173   1              for(i=0;i<80;i++);      
 174   1      }
 175          
 176          /*******************************************************************************************/
 177          //function SpiWrite();
 178          /*******************************************************************************************/
 179          void SpiWrite(uchar  byte)
C51 COMPILER V7.01  T905                                                                   08/01/2006 10:05:32 PAGE 4   

 180          {
 181   1              uchar i;        
 182   1              DATA_BUF=byte;                          // Put function's parameter into a bdata variable               
 183   1              for (i=0;i<8;i++)                       // Setup byte circulation bits
 184   1              {                       
 185   2                      if(flag) MOSI=1;                // Put DATA_BUF.7 on data line                  
 186   2                      else     MOSI=0;
 187   2                      SCK=1;                                  // Set clock line high
 188   2                      DATA_BUF=DATA_BUF<<1;   // Shift DATA_BUF
 189   2                      SCK=0;                                  // Set clock line low 
 190   2              }       
 191   1      }
 192          /*******************************************************************************************/
 193          //function SpiRead();
 194          /*******************************************************************************************/
 195          uchar SpiRead(void)
 196          {
 197   1              uchar i;
 198   1                      
 199   1              for (i=0;i<8;i++)                       // Setup byte circulation bits
 200   1              {       
 201   2                      DATA_BUF=DATA_BUF<<1;   // Right shift DATA_BUF
 202   2                      SCK=1;                                  // Set clock line high
 203   2                      if (MISO)
 204   2                              flag1=1;                        // Read data
 205   2                      else
 206   2                              flag1=0;                
 207   2                      SCK=0;                                  // Set clock line low
 208   2              }
 209   1              return DATA_BUF;                        // Return function parameter
 210   1      }
 211          /*******************************************************************************************/
 212          //function TxPacket();
 213          /*******************************************************************************************/
 214          void TxPacket(void)
 215          {
 216   1              uchar i;
 217   1      
 218   1              //Config905();                          
 219   1              CSN=0;                                          // Spi enable for write a spi command   

⌨️ 快捷键说明

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