【正文】
SpiWrite(0x03)。SpiWrite(0x03)。 //接收發(fā)送有效數據長度為 3字節(jié) SpiWrite(0xE7)。SpiWrite(0xE7)。SpiWrite(0xE7)。SpiWrite(0xE7)。 //接收地址 SpiWrite(0xDE)。 CSN=1。 PWR_UP=1。 TRX_CE=1。 TX_EN=0。 Delay(1000)。 } void Wait_Rec_Packet(void) { if(DR) { TRX_CE=0。//如果數據準備好,則進入待機模式,以便 SPI 口操作 CSN=0。 SpiWrite(0x24)。//接收數據包 TxRxBuffer[0] = SpiRead()。 TxRxBuffer[1] = SpiRead()。 TxRxBuffer[2] = SpiRead()。 CSN=1。 while(DR)。 第 20 頁(共 23 頁) TRX_CE=1。 if((TxRxBuffer[0]==0x01)amp。amp。(TxRxBuffer[1]==0x02)) { TxRxBuffer[0]=0xff。 TxRxBuffer[1]=0xff。 success_flag=1。 if(TxRxBuffer[2]==0xa0) { led1=~led1。 } else if(TxRxBuffer[2]==0xa1) { led2=~led2。 } else if(TxRxBuffer[2]==0xa2) { led3=~led3。 } Ini_System()。 } } } void main(void) { Ini_System()。 PWR_UP=0。 DR=1。 led1=0。 led2=0。 led3=0。 success_flag=0。 TRX_CE=0。 Delay(1000)。 TX_EN=0。 TRX_CE=1。 第 21 頁(共 23 頁) PWR_UP=1。 while(1) { Wait_Rec_Packet()。 //等待接收完成 if(success_flag) { TX_EN=0。 TRX_CE=1。 PWR_UP=1。 Delay(5000)。 Delay(5000)。 success_flag=0。 Delay(10000)。 } } } 4 結束語 本文著重介紹了無線數據傳輸系統(tǒng)的基本原理及無線數據傳輸的編碼解碼設計。這種編碼方法在基于 AT89S51 單片機的無線數據傳輸設計中得到了應用。本設計非常簡便可靠地實現了單片機編碼、發(fā)送、接收、解碼的任務,完成了無線數據傳輸的功能,取得了良好的效果,應用前景廣闊。該系統(tǒng)適用于短距離的無線數據傳輸,也可以通過增 加發(fā)射功率或中繼的方式實現遠距離傳輸,可用于需要較長時間內對目標進行連續(xù)監(jiān)控的場合。當發(fā)射器的類型不同時只需對中斷處理程序的部分參數稍加改動即可 ,就可以適用于多種紅外遙控器信號的接收和解碼 ,極大地節(jié)約了硬件實現的資源開銷。所開發(fā)的系統(tǒng)具有較強的靈活性和實用性 ,為新型遙控器材的研制做了有益的探索 ,具有一定的參考和借鑒作用。本文所用的方法可以舉一反三,對不同類型的發(fā)射器的基本思路和方法是相同的,只需要根據具體波形修改其參數和表達式即可,能靈活應用。對其他型號的遙控編碼器及不同的硬件時鐘 ,只需修改部分參數 ,即 可適用。程序如果改為匯編語言編寫占用空間會比使用 C語言編寫更小 ,完全可應用于各類第 22 頁(共 23 頁) 單片機。它不僅降低了成本,同時也增加了無線數據傳輸接收的靈活性,對不同的無線數據傳輸模塊,不用更換系統(tǒng)硬件電路,只需要修改程序即可。經實驗測試 ,上述無線數據傳輸的信號的發(fā)送和接收方法沒有出現傳輸誤碼 ,可靠實用 ,在編碼解碼方面降低了硬件成本。按上述編碼方法 ,信號的傳輸速度可達20kbps。若在數據傳輸協議中 ,加上地址幀 (設備號識別 ) 和校驗幀 ,該方法在計算機系統(tǒng)中將有更廣泛的應用。 參 考 文 獻 [1] 張毅剛 .新編 MCS51 單片機應用設計(第三版) [M].哈爾濱:工業(yè)大學出版社, 2021 :231255 [2] 董巍巍,李釗,李建軍 .基于單片機的數據采集系統(tǒng)設計 [J].計算機與網絡, 2021( 5):36. [3] 馬青,童子權 .基于單片機的數據采集與近距離無線傳輸系統(tǒng) [J].中國科技信息, 2021( 10): 101103 [4] 清華大學通信教材編寫小組 .數據傳輸原理 [M].北京 :人民郵電出版社 ,1995: 4850. [5] 劉育峰,趙予銓,趙孟強,尹繼武 . 基于 AT89S51 的無線收發(fā)系統(tǒng)設計 [J].電子設計工程 . 2021( 1): 1518. [6] 侯婷,楊宏業(yè),李俊芬,孫作雷 . 無線數據傳輸終端的設計和實現 [J].微計算機信息 .2021 ( 23): 34 . [7]李洪濤,皇甫堪,王展,閆吉杰 . AT89S51 單片機在無線數據傳輸中的應用 [J].單片機與嵌入式系統(tǒng)應用 . 2021( 6): 2122. [8]金保華,張勇,崔光照 . 基于 nRF905 的無線數據多點跳傳通信系統(tǒng) [J].儀表技術與傳感器 .2021 年( 9): 4143. [9] 刁雪慧,徐德民,張福斌,高劍 . 無線傳感器網絡節(jié)點的設計 [J].機械與電 子 .2021( 5):2225 [10] 馬淑華,王鳳文,張美金 .單片機原理與接口技術 [M].北京:郵電大學出版社, 2021:164170. [11] 李群芳,張士軍,黃建 .單片微型計算機與接口技術(第 2 版) [M].北京:電子工業(yè)出版社, 2021: 216221. [12] 蔣博 . nRF905 的無線數據傳輸系統(tǒng) [J].工業(yè)儀表與自動化裝置 .2021 年( 3): 5960. [13] 郭天祥 .新概念 51 單片機 C 語言教程 [M].北京:電子工業(yè)出版社, 2021: 5596. 第 23 頁(共 23 頁) Wireless system design base on MCU Abstract: With the rapid development of today39。s society, People urgently hope exchange information anytime, anywhere without constraints of time. A variety of intelligent control system is also inseparable from the transmission of the data wireless data transmission is new transmission,and its different from the traditional wired transmission, the system does not require transmission cable and it cheap, simple be construction. Now, there are a lot of electrical products (such as domestic appliances) control are also using wireless data transmission,some electrical products function with wireless data transmission relatively simple, wireless data transmission signal receiving recognition are often used coding modulation matching decode electrical products with more of plex functions wireless data transmission, which wireless data transmission signal recognition and decoding with MCU, and its also use a variety of coding modulation. This project describes a wireless data transmission program base on AT89S51 MCU and nRF905 modules, and identification programming method MCU for reference. Keywords:AT89S51 Micro Controller Unit, nRF905 module, Wireless data transmission。