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

📄 t905.lst

📁 无线遥控主机程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.50   T905                                                                  03/10/2006 10:18:41 PAGE 1   


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

line 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  0x6
  34          #define  SEND_LEN_RF     0xc
  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.50   T905                                                                  03/10/2006 10:18:41 PAGE 2   

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

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

 180   1      }
 181          /*******************************************************************************************/
 182          //function SpiWrite();
 183          /*******************************************************************************************/
 184          void SpiWrite(uchar  byte)
 185          {
 186   1              uchar i;        
 187   1              DATA_BUF=byte;                          // Put function's parameter into a bdata variable               
 188   1              for (i=0;i<8;i++)                       // Setup byte circulation bits
 189   1              {       
 190   2                      
 191   2                      if (flag)                       // Put DATA_BUF.7 on data line
 192   2                              MOSI=1;
 193   2                      else
 194   2                              MOSI=0;
 195   2                      SCK=1;                          // Set clock line high
 196   2                      DATA_BUF=DATA_BUF<<1;           // Shift DATA_BUF
 197   2                      SCK=0;                          // Set clock line low 
 198   2              }       
 199   1      }
 200          /*******************************************************************************************/
 201          //function SpiRead();
 202          /*******************************************************************************************/
 203          uchar SpiRead(void)
 204          {
 205   1              uchar i;        
 206   1              for (i=0;i<8;i++)                       // Setup byte circulation bits
 207   1              {       
 208   2                      DATA_BUF=DATA_BUF<<1;           // Right shift DATA_BUF
 209   2                      SCK=1;                          // Set clock line high
 210   2                      if (MISO)
 211   2                              flag1=1;                // Read data
 212   2                      else
 213   2                              flag1=0;
 214   2                                                              
 215   2                      
 216   2                      SCK=0;                          // Set clock line low
 217   2              }
 218   1              return DATA_BUF;                        // Return function parameter
 219   1      }
 220          /*******************************************************************************************/
 221          //function TxPacket();
 222          /*******************************************************************************************/
 223          void TxPacket(void)
 224          {
 225   1              uchar i;
 226   1              //Config905();                          
 227   1              CSN=0;                                  // Spi enable for write a spi command   
 228   1              SpiWrite(WTP);                          // Write payload command
 229   1              for (i=0;i<SEND_LEN_RF;i++)
 230   1              {
 231   2                  
 232   2                      SpiWrite(Rs232RxBuf[i]);                // Write 32 bytes Tx data
 233   2            
 234   2              }
 235   1              CSN=1;                                  // Spi disable                                          
 236   1              Delay(1);
 237   1              CSN=0;                                  // Spi enable for write a spi command   
 238   1              SpiWrite(WTA);                          // Write address command
 239   1              for (i=0;i<4;i++)                       // Write 4 bytes address
 240   1              {
 241   2                      SpiWrite(RxTxConf.buf[i+5]);
C51 COMPILER V7.50   T905                                                                  03/10/2006 10:18:41 PAGE 5   

 242   2              }       
 243   1              CSN=1;                                  // Spi disable
 244   1              TRX_CE=1;                               // Set TRX_CE high,start Tx data transmission
 245   1              Delay(1);                               // while (DR!=1);
 246   1              TRX_CE=0;                               // Set TRX_CE low
 247   1      }
 248          
 249          /*
 250          void TxPacket_special(void)
 251          {
 252                  uchar i;
 253                  //Config905();                          
 254                  CSN=0;                                  // Spi enable for write a spi command   
 255                  SpiWrite(WTP);             // Write payload command
 256                  for (i=0;i<7;i++)
 257                  {
 258                      
 259                          SpiWrite(Rs232RxBuf[rs232rxpoint_tail]);                // Write 32 bytes Tx data
 260                  rs232rxpoint_tail++;
 261                          if(     rs232rxpoint_tail>RXBUFF_LEN)rs232rxpoint_tail=0;
 262          
 263                  }
 264          
 265                    SpiWrite(0);

⌨️ 快捷键说明

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