PC機之間串口通信的實現(xiàn)一、實驗目的 1.熟悉微機接口實驗裝置的結(jié)構(gòu)和使用方法。 2.掌握通信接口芯片8251和8250的功能和使用方法。 3.學會串行通信程序的編制方法。
二、實驗內(nèi)容與要求 1.基本要求主機接收開關量輸入的數(shù)據(jù)(二進制或十六進制),從鍵盤上按“傳輸”鍵(可自行定義),就將該數(shù)據(jù)通過8251A傳輸出去。終端接收后在顯示器上顯示數(shù)據(jù)。具體操作說明如下:(1)出現(xiàn)提示信息“start with R in the board!”,通過調(diào)整乒乓開關的狀態(tài),設置8位數(shù)據(jù);(2)在小鍵盤上按“R”鍵,系統(tǒng)將此時乒乓開關的狀態(tài)讀入計算機I中,并顯示出來,同時顯示經(jīng)串行通訊后,計算機II接收到的數(shù)據(jù);(3)完成后,系統(tǒng)提示“do you want to send another data? Y/N”,根據(jù)用戶需要,在鍵盤按下“Y”鍵,則重復步驟(1),進行另一數(shù)據(jù)的通訊;在鍵盤按除“Y”鍵外的任意鍵,將退出本程序。2.提高要求 能夠進行出錯處理,例如采用奇偶校驗,出錯重傳或者采用接收方回傳和發(fā)送方確認來保證發(fā)送和接收正確。
三、設計報告要求 1.設計目的和內(nèi)容 2.總體設計 3.硬件設計:原理圖(接線圖)及簡要說明 4.軟件設計框圖及程序清單5.設計結(jié)果和體會(包括遇到的問題及解決的方法)
四、8251A通用串行輸入/輸出接口芯片由于CPU與接口之間按并行方式傳輸,接口與外設之間按串行方式傳輸,因此,在串行接口中,必須要有“接收移位寄存器”(串→并)和“發(fā)送移位寄存器”(并→串)。能夠完成上述“串←→并”轉(zhuǎn)換功能的電路,通常稱為“通用異步收發(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個停止位。串行數(shù)據(jù)以起始位開始,接著是最低有效數(shù)據(jù)位,最高有效位的后面是奇/偶校驗位,然后是停止位。按位發(fā)送的數(shù)據(jù)是以發(fā)送時鐘TXC的下降沿同步的,也就是說這些數(shù)據(jù)總是在發(fā)送時鐘TXC的下降沿從8251A發(fā)出。數(shù)據(jù)傳輸?shù)牟ㄌ芈嗜Q于編程時指定的波特率因子,為發(fā)送器時鐘頻率的1、1/16或1/64。當波特率指定為16時,數(shù)據(jù)傳輸?shù)牟ㄌ芈示褪前l(fā)送器時鐘頻率的1/16。CPU通過數(shù)據(jù)總線將數(shù)據(jù)送到8251A的數(shù)據(jù)輸出緩沖寄存器以后,再傳輸?shù)桨l(fā)送緩沖器,經(jīng)移位寄存器移位,將并行數(shù)據(jù)變?yōu)榇袛?shù)據(jù),從TxD端送往外部設備。在8251A接收字符時,命令寄存器的接收允許位RxE(Receiver Enable)必須為1。8251A通過檢測RxD引腳上的低電平來準備接收字符,在沒有字符傳送時RxD端為高電平。8251A不斷地檢測RxD引腳,從RxD端上檢測到低電平以后,便認為是串行數(shù)據(jù)的起始位,并且啟動接收控制電路中的一個計數(shù)器來進行計數(shù),計數(shù)器的頻率等于接收器時鐘頻率。計數(shù)器是作為接收器采樣定時,當計數(shù)到相當于半個數(shù)位的傳輸時間時再次對RxD端進行采樣,如果仍為低電平,則確認該數(shù)位是一個有效的起始位。若傳輸一個字符需要16個時鐘,那么就是要在計數(shù)8個時鐘后采樣到低電平。之后,8251A每隔一個數(shù)位的傳輸時間對RxD端采樣一次,依次確定串行數(shù)據(jù)位的值。串行數(shù)據(jù)位順序進入接收移位寄存器,通過校驗并除去停止位,變成并行數(shù)據(jù)以后通過內(nèi)部數(shù)據(jù)總線送入接收緩沖器,此時發(fā)出有效狀態(tài)的RxRDY信號通知CPU,通知CPU8251A已經(jīng)收到一個有效的數(shù)據(jù)。一個字符對應的數(shù)據(jù)可以是5~8位。如果一個字符對應的數(shù)據(jù)不到8位,8251A會在移位轉(zhuǎn)換成并行數(shù)據(jù)的時候,自動把他們的高位補成0。
五、系統(tǒng)總體設計方案根據(jù)系統(tǒng)設計的要求,對系統(tǒng)設計的總體方案進行論證分析如下:1.獲取8位開關量可使用實驗臺上的8255A可編程并行接口芯片,因為只要獲取8位數(shù)據(jù)量,只需使用基本輸入和8位數(shù)據(jù)線,所以將8255A工作在方式0,PA0-PA7接實驗臺上的8位開關量。2.當使用串口進行數(shù)據(jù)傳送時,雖然同步通信速度遠遠高于異步通信,可達500kbit/s,但由于其需要有一個時鐘來實現(xiàn)發(fā)送端和接收端之間的同步,硬件電路復雜,通常計算機之間的通信只采用異步通信。3.由于8251A本身沒有時鐘,需要外部提供,所以本設計中使用實驗臺上的8253芯片的計數(shù)器2來實現(xiàn)。4:顯示和鍵盤輸入均使用DOS功能調(diào)用來實現(xiàn)。設計思路框圖,如下圖所示:
六、硬件設計硬件電路主要分為8位開關量數(shù)據(jù)獲取電路,串行通信數(shù)據(jù)發(fā)送電路,串行通信數(shù)據(jù)接收電路三個部分。1.8位開關量數(shù)據(jù)獲取電路該電路主要是利用8255并行接口讀取8位乒乓開關的數(shù)據(jù)。此次設計在獲取8位開關數(shù)據(jù)量時采用8255令其工作在方式0,A口輸入8位數(shù)據(jù),CS#接實驗臺上CS1口,對應端口為280H-283H,PA0-PA7接8個開關。2.串行通信電路串行通信電路本設計中8253主要為8251充當頻率發(fā)生器,接線如下圖所示。
The Motorola MPC106 PCI bridge/memory controller provides a PowerPCªmicroprocessor common hardware reference platform (CHRPª) compliant bridgebetween the PowerPC microprocessor family and the Peripheral Component Interconnect(PCI) bus. In this document, the term Ô106Õ is used as an abbreviation for the phraseÔMPC106 PCI bridge/memory controllerÕ. This document contains pertinent physicalcharacteristics of the 106. For functional characteristics refer to theMPC106 PCI Bridge/Memory Controller UserÕs Manual.This document contains the following topics:Topic PageSection 1.1, ÒOverviewÓ 2Section 1.2, ÒFeaturesÓ 3Section 1.3, ÒGeneral ParametersÓ 5Section 1.4, ÒElectrical and Thermal CharacteristicsÓ 5Section 1.5, ÒPin AssignmentsÓ 17Section 1.6, ÒPinout Listings 18Section 1.7, ÒPackage DescriptionÓ 22Section 1.8, ÒSystem Design InformationÓ 24Section 1.9, ÒDocument Revision HistoryÓ 29Section 1.10, ÒOrdering InformationÓ 29
All inputs of the C16x family have Schmitt-Trigger input characteristics. These Schmitt-Triggers are intended to always provide proper internal low and high levels, even if anundefined voltage level (between TTL-VIL and TTL-VIH) is externally applied to the pin.The hysteresis of these inputs, however, is very small, and can not be properly used in anapplication to suppress signal noise, and to shape slow rising/falling input transitions.Thus, it must be taken care that rising/falling input signals pass the undefined area of theTTL-specification between VIL and VIH with a sufficient rise/fall time, as generally usualand specified for TTL components (e.g. 74LS series: gates 1V/us, clock inputs 20V/us).The effect of the implemented Schmitt-Trigger is that even if the input signal remains inthe undefined area, well defined low/high levels are generated internally. Note that allinput signals are evaluated at specific sample points (depending on the input and theperipheral function connected to it), at that signal transitions are detected if twoconsecutive samples show different levels. Thus, only the current level of an input signalat these sample points is relevant, that means, the necessary rise/fall times of the inputsignal is only dependant on the sample rate, that is the distance in time between twoconsecutive evaluation time points. If an input signal, for instance, is sampled throughsoftware every 10us, it is irrelevant, which input level would be seen between thesamples. Thus, it would be allowable for the signal to take 10us to pass through theundefined area. Due to the sample rate of 10us, it is assured that only one sample canoccur while the signal is within the undefined area, and no incorrect transition will bedetected. For inputs which are connected to a peripheral function, e.g. capture inputs, thesample rate is determined by the clock cycle of the peripheral unit. In the case of theCAPCOM unit this means a sample rate of 400ns @ 20MHz CPU clock. This requiresinput signals to pass through the undefined area within these 400ns in order to avoidmultiple capture events.For input signals, which do not provide the required rise/fall times, external circuitry mustbe used to shape the signal transitions.In the attached diagram, the effect of the sample rate is shown. The numbers 1 to 5 in thediagram represent possible sample points. Waveform a) shows the result if the inputsignal transition time through the undefined TTL-level area is less than the time distancebetween the sample points (sampling at 1, 2, 3, and 4). Waveform b) can be the result ifthe sampling is performed more than once within the undefined area (sampling at 1, 2, 5,3, and 4).Sample points:1. Evaluation of the signal clearly results in a low level2. Either a low or a high level can be sampled here. If low is sampled, no transition willbe detected. If the sample results in a high level, a transition is detected, and anappropriate action (e.g. capture) might take place.3. Evaluation here clearly results in a high level. If the previous sample 2) had alreadydetected a high, there is no change. If the previous sample 2) showed a low, atransition from low to high is detected now.