PC機之間串口通信的實現一、實驗目的 1.熟悉微機接口實驗裝置的結構和使用方法。 2.掌握通信接口芯片8251和8250的功能和使用方法。 3.學會串行通信程序的編制方法。 二、實驗內容與要求 1.基本要求主機接收開關量輸入的數據(二進制或十六進制),從鍵盤上按“傳輸”鍵(可自行定義),就將該數據通過8251A傳輸出去。終端接收后在顯示器上顯示數據。具體操作說明如下:(1)出現提示信息“start with R in the board!”,通過調整乒乓開關的狀態,設置8位數據;(2)在小鍵盤上按“R”鍵,系統將此時乒乓開關的狀態讀入計算機I中,并顯示出來,同時顯示經串行通訊后,計算機II接收到的數據;(3)完成后,系統提示“do you want to send another data? Y/N”,根據用戶需要,在鍵盤按下“Y”鍵,則重復步驟(1),進行另一數據的通訊;在鍵盤按除“Y”鍵外的任意鍵,將退出本程序。2.提高要求 能夠進行出錯處理,例如采用奇偶校驗,出錯重傳或者采用接收方回傳和發送方確認來保證發送和接收正確。 三、設計報告要求 1.設計目的和內容 2.總體設計 3.硬件設計:原理圖(接線圖)及簡要說明 4.軟件設計框圖及程序清單5.設計結果和體會(包括遇到的問題及解決的方法) 四、8251A通用串行輸入/輸出接口芯片由于CPU與接口之間按并行方式傳輸,接口與外設之間按串行方式傳輸,因此,在串行接口中,必須要有“接收移位寄存器”(串→并)和“發送移位寄存器”(并→串)。能夠完成上述“串←→并”轉換功能的電路,通常稱為“通用異步收發器”(UART:Universal Asynchronous Receiver and Transmitter),典型的芯片有:Intel 8250/8251。8251A異步工作方式:如果8251A編程為異步方式,在需要發送字符時,必須首先設置TXEN和CTS#為有效狀態,TXEN(Transmitter Enable)是允許發送信號,是命令寄存器中的一位;CTS#(Clear To Send)是由外設發來的對CPU請求發送信號的響應信號。然后就開始發送過程。在發送時,每當CPU送往發送緩沖器一個字符,發送器自動為這個字符加上1個起始位,并且按照編程要求加上奇/偶校驗位以及1個、1.5個或者2個停止位。串行數據以起始位開始,接著是最低有效數據位,最高有效位的后面是奇/偶校驗位,然后是停止位。按位發送的數據是以發送時鐘TXC的下降沿同步的,也就是說這些數據總是在發送時鐘TXC的下降沿從8251A發出。數據傳輸的波特率取決于編程時指定的波特率因子,為發送器時鐘頻率的1、1/16或1/64。當波特率指定為16時,數據傳輸的波特率就是發送器時鐘頻率的1/16。CPU通過數據總線將數據送到8251A的數據輸出緩沖寄存器以后,再傳輸到發送緩沖器,經移位寄存器移位,將并行數據變為串行數據,從TxD端送往外部設備。在8251A接收字符時,命令寄存器的接收允許位RxE(Receiver Enable)必須為1。8251A通過檢測RxD引腳上的低電平來準備接收字符,在沒有字符傳送時RxD端為高電平。8251A不斷地檢測RxD引腳,從RxD端上檢測到低電平以后,便認為是串行數據的起始位,并且啟動接收控制電路中的一個計數器來進行計數,計數器的頻率等于接收器時鐘頻率。計數器是作為接收器采樣定時,當計數到相當于半個數位的傳輸時間時再次對RxD端進行采樣,如果仍為低電平,則確認該數位是一個有效的起始位。若傳輸一個字符需要16個時鐘,那么就是要在計數8個時鐘后采樣到低電平。之后,8251A每隔一個數位的傳輸時間對RxD端采樣一次,依次確定串行數據位的值。串行數據位順序進入接收移位寄存器,通過校驗并除去停止位,變成并行數據以后通過內部數據總線送入接收緩沖器,此時發出有效狀態的RxRDY信號通知CPU,通知CPU8251A已經收到一個有效的數據。一個字符對應的數據可以是5~8位。如果一個字符對應的數據不到8位,8251A會在移位轉換成并行數據的時候,自動把他們的高位補成0。 五、系統總體設計方案根據系統設計的要求,對系統設計的總體方案進行論證分析如下:1.獲取8位開關量可使用實驗臺上的8255A可編程并行接口芯片,因為只要獲取8位數據量,只需使用基本輸入和8位數據線,所以將8255A工作在方式0,PA0-PA7接實驗臺上的8位開關量。2.當使用串口進行數據傳送時,雖然同步通信速度遠遠高于異步通信,可達500kbit/s,但由于其需要有一個時鐘來實現發送端和接收端之間的同步,硬件電路復雜,通常計算機之間的通信只采用異步通信。3.由于8251A本身沒有時鐘,需要外部提供,所以本設計中使用實驗臺上的8253芯片的計數器2來實現。4:顯示和鍵盤輸入均使用DOS功能調用來實現。設計思路框圖,如下圖所示: 六、硬件設計硬件電路主要分為8位開關量數據獲取電路,串行通信數據發送電路,串行通信數據接收電路三個部分。1.8位開關量數據獲取電路該電路主要是利用8255并行接口讀取8位乒乓開關的數據。此次設計在獲取8位開關數據量時采用8255令其工作在方式0,A口輸入8位數據,CS#接實驗臺上CS1口,對應端口為280H-283H,PA0-PA7接8個開關。2.串行通信電路串行通信電路本設計中8253主要為8251充當頻率發生器,接線如下圖所示。
上傳時間: 2013-12-19
上傳用戶:小火車啦啦啦
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.
上傳時間: 2013-10-23
上傳用戶:copu
The 87LPC76X Microcontroller combines in a small package thebenefits of a high-performance microcontroller with on-boardhardware supporting the Inter-Integrated Circuit (I2C) bus interface.The 87LPC76X can be programmed both as an I2C bus master, aslave, or both. An overview of the I2C bus and description of the bussupport hardware in the 87LPC76X microcontrollers appears inapplication note AN464, Using the 87LPC76X Microcontroller as anI2C Bus Master. That application note includes a programmingexample, demonstrating a bus-master code. Here we show anexample of programming the microcontroller as an I2C slave.The code listing demonstrates communications routines for the87LPC76X as a slave on the I2C bus. It compliments the program inAN464 which demonstrates the 87LPC76X as an I2C bus master.One may demonstrate two 87LPC76X devices communicating witheach other on the I2C bus, using the AN464 code in one, and theprogram presented here in the other. The examples presented hereand in AN464 allow the 87LPC76X to be either a master or a slave,but not both. Switching between master and slave roles in amultimaster environment is described in application note AN435.The software for a slave on the bus is relatively simple, as theprocessor plays a relatively passive role. It does not initiate bustransfers on its own, but responds to a master initiating thecommunications. This is true whether the slave receives or transmitsdata—transmission takes place only as a response to a busmaster’s request. The slave does not have to worry about arbitrationor about devices which do not acknowledge their address. As theslave is not supposed to take control of the bus, we do not demandit to resolve bus exceptions or “hangups”. If the bus becomesinactive the processor simply withdraws, not interfering with themaster (or masters) on the bus which should (hopefully) try toresolve the situation.
上傳時間: 2013-11-19
上傳用戶:shirleyYim
本文介紹使用AT89C2051 制作的一種發音電路, 各種聲音通過編程實現, 靈活方便。原理圖如圖1 所示。圖1 發音電路原理該電路利用方波諧波成份豐富的特點,編程采用計時器延遲法發音, 即每個音的半周期計時中斷一次, 而使輸出P110 (或其他IöO 口) 反相, 重復執行產生某種頻率的信號。例如: 中音DO 的頻率為523Hz, 其周期為1912Ls, 半周期為956Ls, 若初始P110= 1, 經956Ls 后應使P110= 0, 再經956Ls 恢復P110= 1, 這樣就可發出中音DO。
上傳時間: 2013-10-11
上傳用戶:Altman
第1章 單片機系統概述1.1 AVR系列單片機的特點1.2 AT90系列單片機簡介第2章 AT90LS8535單片機的基礎知識2.1 AT90LS8535單片機的總體結構2.1.1 AT90LS8535單片機的中央處理器2.1.2 AT90LS8535單片機的存儲器組織2.1.3 AT90LS8535單片機的I/O接口2.1.4 AT90LS8535單片機的內部資源2.1.5 AT90LS8535單片機的時鐘電路2.1.6 AT90LS8535單片機的系統復位2.1.7 AT90LS8535單片機的節電方式2.1.8 AT90LS8535單片機的芯片引腳2.2 AT90LS8535單片機的指令系統2.2.1 匯編指令格式2.2.2 尋址方式2.2.3 偽指令2.2.4 指令類型及數據操作方式2.3 應用程序設計2.3.1 程序設計方法2.3.2 應用程序舉例第3章 AT90LS8535單片機的C編程3.1 支持高級語言編程的AVR系列單片機3.2 AVR的C編譯器3.3 ICC AVR介紹3.3.1 安裝ICC AVR3.3.2 設置ICC AVR3.4 用ICC AVR編寫應用程序3.5 下載程序文件第4章 數據類型、運算符和表達式4.1 ICC AVR支持的數據類型4.2 常量與變量4.2.1 常量4.2.2 變量4.3 AT90LS8535的存儲空間4.4 算術和賦值運算4.4.1 算術運算符和算術表達式4.4.2 賦值運算符和賦值表達式4.5 邏輯運算4.6 關系運算4.7 位操作4.7.1 位邏輯運算4.7.2 移位運算4.8 逗號運算第5章 控制流5.1 C語言的結構化程序設計5.1.1 順序結構5.1.2 選擇結構5.1.3 循環結構5.2 選擇語句5.2.1 if語句5.2.2 switch分支5.2.3 選擇語句的嵌套5.3 循環語句5.3.1 while語句5.3.2 do…while語句5.3.3 for語句5.3.4 循環語句嵌套5.3.5 break語句和continue語句第6章 函數6.1 函數的定義6.1.1 函數的定義的一般形式6.1.2 函數的參數6.1.3 函數的值6.2 函數的調用6.2.1 函數的一般調用6.2.2 函數的遞歸調用6.2.3 函數的嵌套使用6.3 變量的類型及其存儲方式6.3.1 局部變量6.3.2 局部變量的存儲方式6.3.3 全局變量6.3.4 全局變量的存儲方式6.4 內部函數和外部函數6.4.1 內部函數6.4.2 外部函數第7章 指針第8章 結構體和共用體第9章 AT90LS8535的內部資源第10章 AT90LS8535的人機接口編程第11章 AT90LS8535的外圍擴展第12章 AT90LS8535的通信編程第13章 系統設計中的程序處理方法
上傳時間: 2013-10-31
上傳用戶:smthxt
載波相移正弦脈寬調制(SPWM)技術是一種適用于大功率電力開關變換裝置的高性能開關調制策略,在有源電力濾波器中有良好的應用前景。本文介紹了如何利用高性能數字信號處理器TMS320F28335的片內外設事件管理器(EV)模塊產生三相SPWM波,給出了程序流程圖及關鍵程序源碼。該方法采用不對稱規則采樣算法,參數計算主要采用查表法,計算量小,實時性高。在工程實踐中表明,該方法既能滿足控制精度要求,又能滿足實時性要求,可以很好地控制逆變電源的輸出。
上傳時間: 2013-11-05
上傳用戶:tzrdcaabb
There has long been a need for portable ultrasoundsystems that have good resolution at affordable costpoints. Portable systems enable healthcare providersto use ultrasound in remote locations such asdisaster zones, developing regions, and battlefields,where it was not previously practical to do so.
上傳時間: 2013-10-26
上傳用戶:liulinshan2010
Field Programmable Gate Arrays (FPGAs) are becoming a critical part of every system design. Many vendors offer many different architectures and processes. Which one is right for your design? How do you design one of these so that it works correctly and functions as you expect in your entire system? These are the questions that this paper sets out to answer.
上傳時間: 2013-10-29
上傳用戶:lixqiang
UART 4 UART參考設計,Xilinx提供VHDL代碼 uart_vhdl This zip file contains the following folders: \vhdl_source -- Source VHDL files: uart.vhd - top level file txmit.vhd - transmit portion of uart rcvr.vhd - - receive portion of uart \vhdl_testfixture -- VHDL Testbench files. This files only include the testbench behavior, they do not instantiate the DUT. This can easily be done in a top-level VHDL file or a schematic. This folder contains the following files: txmit_tb.vhd -- Test bench for txmit.vhd. rcvr_tf.vhd -- Test bench for rcvr.vhd.
上傳時間: 2013-11-07
上傳用戶:jasson5678
The #1 Step-by-Step Guide to labviewNow Completely Updated for labview 8! Master labview 8 with the industry's friendliest, most intuitive tutorial: labview for Everyone, Third Edition. Top labview experts Jeffrey Travis and Jim Kring teach labview the easy way: through carefully explained, step-by-step examples that give you reusable code for your own projects! This brand-new Third Edition has been fully revamped and expanded to reflect new features and techniques introduced in labview 8. You'll find two new chapters, plus dozens of new topics, including Project Explorer, AutoTool, XML, event-driven programming, error handling, regular expressions, polymorphic VIs, timed structures, advanced reporting, and much more. Certified labview Developer (CLD) candidates will find callouts linking to key objectives on NI's newest exam, making this book a more valuable study tool than ever. Not just what to d why to do it! Use labview to build your own virtual workbench Master labview's foundations: wiring, creating, editing, and debugging VIs; using controls and indicators; working with data structures; and much more Learn the "art" and best practices of effective labview development NEW: Streamline development with labview Express VIs NEW: Acquire data with NI-DAQmx and the labview DAQmx VIs NEW: Discover design patterns for error handling, control structures, state machines, queued messaging, and more NEW: Create sophisticated user interfaces with tree and tab controls, drag and drop, subpanels, and more Whatever your application, whatever your role, whether you've used labview or not, labview for Everyone, Third Edition is the fastest, easiest way to get the results you're after!
上傳時間: 2013-10-14
上傳用戶:shawvi