<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 用89C51驅(qū)動(dòng)nRf905收發(fā)C源代碼

          用89C51驅(qū)動(dòng)nRf905收發(fā)C源代碼

          作者: 時(shí)間:2016-12-01 來源:網(wǎng)絡(luò) 收藏
          #include
          #include

          #define uchar unsigned char
          #define uint unsigned int

          #define WC 0x00 // Write configuration register command
          #define RC 0x10 // Read configuration register command
          #define WTP 0x20 // Write TX Payload command
          #define RTP 0x21 // Read TX Payload command
          #define WTA 0x22 // Write TX Address command
          #define RTA 0x23 // Read TX Address command
          #define RRP 0x24 // Read RX Payload command
          /*******************************************************************************************/
          typedef struct RFConfig
          {
          uchar n;
          uchar buf[10];
          }RFConfig;

          code RFConfig RxTxConf =
          {
          10,
          0x01, 0x0c, 0x44, 0x20, 0x20, 0xcc, 0xcc, 0xcc,0xcc, 0x58
          };
          // The content of this struct is nRF905s initializedata.
          // CH_NO=1;433MHZ;Normal Opration,No Retrans;RX,TX Address is 4 Bytes
          // RX TX Payload Width is 32 Bytes;Disable Extern Clock;Fosc=16MHZ
          // 8 Bits CRC And enable
          /*******************************************************************************************/
          uchar data TxBuf[32];
          uchar data RxBuf[32];
          /*******************************************************************************************/
          uchar bdataDATA_BUF;
          sbit flag =DATA_BUF^7;
          sbitflag1 =DATA_BUF^0;
          /*******************************************************************************************/
          sbit TX_EN =P2^6;
          sbit TRX_CE =P2^5;
          sbit PWR_UP =P2^4;
          sbit MISO =P2^3;
          sbit MOSI =P2^2;
          sbit SCK =P2^1;
          sbit CSN =P2^0;

          sbit AM =P3^2;
          sbit DR =P3^3;
          sbit CD =P3^5;

          /*******************************************************************************************/
          void InitIO(void); // Initialize IO port
          void Inituart(void); // initialize 232 uart
          void Config905(void); // Config nRF905 module
          void SetTxMode(void); // Set nRF905 in Tx mode
          void SetRxMode(void); // Set nRF905 in Rx mode
          void TxPacket(void); // Send data by nRF905
          void RxPacket(void); // Recive data by nRF905
          void SpiWrite(uchar); // Write data to nRF905
          uchar SpiRead(void); // Readdatato nRF905
          void Delay(uchar n); // Delay 100us
          void Scankey(void); // Scan key
          void TxData (uchar x); // Send key_value to CRT display
          /*******************************************************************************************/
          //function main();
          /*******************************************************************************************/
          void main(void)
          {
          InitIO(); // Initialize IO port
          Inituart(); // initialize 232 uart
          Config905(); // Config nRF905 module
          SetTxMode(); // Set Tx Mode
          TxPacket(); // Transmit Tx bufferdata
          Delay(500); // delay for ledlight
          P0=0xff; // led close
          SetRxMode(); // Set nRF905 in Rx mode
          while(1) // circulation
          {
          Scankey(); // Scan key
          if (DR) // If recive data ready...
          RxPacket(); // ... recivedata
          }
          }
          /*******************************************************************************************/
          //function InitIO();
          /*******************************************************************************************/
          void InitIO(void)
          {
          P0=0x0f; // ledlight
          CSN=1; // Spi disable
          SCK=0; // Spi clocklineinit high
          DR=1; // Init DR for input
          AM=1; // Init AM for input
          PWR_UP=1; // nRF905 power on
          TRX_CE=0; // Set nRF905 in standby mode
          TX_EN=0; // set radio in Rx mode
          }
          /*******************************************************************************************/
          //function Inituart();
          /*******************************************************************************************/
          void Inituart(void)
          {
          TMOD = 0x20; //timer1 working mode 1
          TL1 = 0xfd; //f7=9600 for 16mhz Fosc,and ...
          TH1 = 0xfd; //...fd=19200 for 11.0592mhz Fosc
          SCON = 0xd8; //uart mode 3,ren==1
          PCON = 0x80; //smod=0
          TR1 = 1; //start timer1
          }
          /*******************************************************************************************/
          //function Config905();
          /*******************************************************************************************/
          void Config905(void)
          {
          uchar i;
          CSN=0; // Spi enable for write a spi command
          SpiWrite(WC); // Write config command
          for (i=0;i {
          SpiWrite(RxTxConf.buf[i]);
          }
          CSN=1; // Disable Spi
          }
          /*******************************************************************************************/
          //function Delay100us();Delay 100us
          /*******************************************************************************************/
          void Delay(uchar n)
          {
          uint i;
          while(n--)
          for(i=0;i<80;i++);
          }

          上一頁 1 2 下一頁

          關(guān)鍵詞: 89C51nRf905收

          評(píng)論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();