PC機之間串口通信的實現一、實驗目的 1.熟悉微機接口實驗裝置的結構和使用方法。 2.掌握通信接口芯片8251和8250的功能和使用方法。 3.學會串行通信程序的編制方法。
二、實驗內容與要求 1.基本要求主機接收開關量輸入的數據(二進制或十六進制),從鍵盤上按“傳輸”鍵(可自行定義),就將該數據通過8251A傳輸出去。終端接收后在顯示器上顯示數據。具體操作說明如下:(1)出現提示信息“start with R in the board!”,通過調整乒乓開關的狀態(tài),設置8位數據;(2)在小鍵盤上按“R”鍵,系統(tǒng)將此時乒乓開關的狀態(tài)讀入計算機I中,并顯示出來,同時顯示經串行通訊后,計算機II接收到的數據;(3)完成后,系統(tǒng)提示“do you want to send another data? Y/N”,根據用戶需要,在鍵盤按下“Y”鍵,則重復步驟(1),進行另一數據的通訊;在鍵盤按除“Y”鍵外的任意鍵,將退出本程序。2.提高要求 能夠進行出錯處理,例如采用奇偶校驗,出錯重傳或者采用接收方回傳和發(fā)送方確認來保證發(fā)送和接收正確。
三、設計報告要求 1.設計目的和內容 2.總體設計 3.硬件設計:原理圖(接線圖)及簡要說明 4.軟件設計框圖及程序清單5.設計結果和體會(包括遇到的問題及解決的方法)
四、8251A通用串行輸入/輸出接口芯片由于CPU與接口之間按并行方式傳輸,接口與外設之間按串行方式傳輸,因此,在串行接口中,必須要有“接收移位寄存器”(串→并)和“發(fā)送移位寄存器”(并→串)。能夠完成上述“串←→并”轉換功能的電路,通常稱為“通用異步收發(fā)器”(UART:Universal Asynchronous Receiver and Transmitter),典型的芯片有:Intel 8250/8251。8251A異步工作方式:如果8251A編程為異步方式,在需要發(fā)送字符時,必須首先設置TXEN和CTS#為有效狀態(tài),TXEN(Transmitter Enable)是允許發(fā)送信號,是命令寄存器中的一位;CTS#(Clear To Send)是由外設發(fā)來的對CPU請求發(fā)送信號的響應信號。然后就開始發(fā)送過程。在發(fā)送時,每當CPU送往發(fā)送緩沖器一個字符,發(fā)送器自動為這個字符加上1個起始位,并且按照編程要求加上奇/偶校驗位以及1個、1.5個或者2個停止位。串行數據以起始位開始,接著是最低有效數據位,最高有效位的后面是奇/偶校驗位,然后是停止位。按位發(fā)送的數據是以發(fā)送時鐘TXC的下降沿同步的,也就是說這些數據總是在發(fā)送時鐘TXC的下降沿從8251A發(fā)出。數據傳輸的波特率取決于編程時指定的波特率因子,為發(fā)送器時鐘頻率的1、1/16或1/64。當波特率指定為16時,數據傳輸的波特率就是發(fā)送器時鐘頻率的1/16。CPU通過數據總線將數據送到8251A的數據輸出緩沖寄存器以后,再傳輸到發(fā)送緩沖器,經移位寄存器移位,將并行數據變?yōu)榇袛祿?,從TxD端送往外部設備。在8251A接收字符時,命令寄存器的接收允許位RxE(Receiver Enable)必須為1。8251A通過檢測RxD引腳上的低電平來準備接收字符,在沒有字符傳送時RxD端為高電平。8251A不斷地檢測RxD引腳,從RxD端上檢測到低電平以后,便認為是串行數據的起始位,并且啟動接收控制電路中的一個計數器來進行計數,計數器的頻率等于接收器時鐘頻率。計數器是作為接收器采樣定時,當計數到相當于半個數位的傳輸時間時再次對RxD端進行采樣,如果仍為低電平,則確認該數位是一個有效的起始位。若傳輸一個字符需要16個時鐘,那么就是要在計數8個時鐘后采樣到低電平。之后,8251A每隔一個數位的傳輸時間對RxD端采樣一次,依次確定串行數據位的值。串行數據位順序進入接收移位寄存器,通過校驗并除去停止位,變成并行數據以后通過內部數據總線送入接收緩沖器,此時發(fā)出有效狀態(tài)的RxRDY信號通知CPU,通知CPU8251A已經收到一個有效的數據。一個字符對應的數據可以是5~8位。如果一個字符對應的數據不到8位,8251A會在移位轉換成并行數據的時候,自動把他們的高位補成0。
五、系統(tǒng)總體設計方案根據系統(tǒng)設計的要求,對系統(tǒng)設計的總體方案進行論證分析如下:1.獲取8位開關量可使用實驗臺上的8255A可編程并行接口芯片,因為只要獲取8位數據量,只需使用基本輸入和8位數據線,所以將8255A工作在方式0,PA0-PA7接實驗臺上的8位開關量。2.當使用串口進行數據傳送時,雖然同步通信速度遠遠高于異步通信,可達500kbit/s,但由于其需要有一個時鐘來實現發(fā)送端和接收端之間的同步,硬件電路復雜,通常計算機之間的通信只采用異步通信。3.由于8251A本身沒有時鐘,需要外部提供,所以本設計中使用實驗臺上的8253芯片的計數器2來實現。4:顯示和鍵盤輸入均使用DOS功能調用來實現。設計思路框圖,如下圖所示:
六、硬件設計硬件電路主要分為8位開關量數據獲取電路,串行通信數據發(fā)送電路,串行通信數據接收電路三個部分。1.8位開關量數據獲取電路該電路主要是利用8255并行接口讀取8位乒乓開關的數據。此次設計在獲取8位開關數據量時采用8255令其工作在方式0,A口輸入8位數據,CS#接實驗臺上CS1口,對應端口為280H-283H,PA0-PA7接8個開關。2.串行通信電路串行通信電路本設計中8253主要為8251充當頻率發(fā)生器,接線如下圖所示。
The μPSD32xx family, from ST, consists of Flash programmable system devices with a 8032 MicrocontrollerCore. Of these, the μPSD3234A and μPSD3254A are notable for having a complete implementationof the USB hardware directly on the chip, complying with the Universal Serial Bus Specification, Revision1.1.This application note describes a demonstration program that has been written for the DK3200 hardwaredemonstration kit (incorporating a μPSD3234A device). It gives the user an idea of how simple it is to workwith the device, using the HID class as a ready-made device driver for the USB connection.IN-APPLICATION-PROGRAMMING (IAP) AND IN-SYSTEM-PROGRAMMING (ISP)Since the μPSD contains two independent Flash memory arrays, the Micro Controller Unit (MCU) can executecode from one memory while erasing and programming the other. Product firmware updates in thefield can be reliably performed over any communication channel (such as CAN, Ethernet, UART, J1850)using this unique architecture. For In-Application-Programming (IAP), all code is updated through theMCU. The main advantage for the user is that the firmware can be updated remotely. The target applicationruns and takes care on its own program code and data memory.IAP is not the only method to program the firmware in μPSD devices. They can also be programmed usingIn-System-Programming (ISP). A IEEE1149.1-compliant JTAG interface is included on the μPSD. Withthis, the entire device can be rapidly programmed while soldered to the circuit board (Main Flash memory,Secondary Boot Flash memory, the PLD, and all configuration areas). This requires no MCU participation.The MCU is completely bypassed. So, the μPSD can be programmed or reprogrammed any time, anywhere, even when completely uncommitted.Both methods take place with the device in its normal hardware environment, soldered to a printed circuitboard. The IAP method cannot be used without previous use of ISP, because IAP utilizes a small amountof resident code to receive the service commands, and to perform the desired operations.