2023年全國(guó)碩士研究生考試考研英語(yǔ)一試題真題(含答案詳解+作文范文)_第1頁(yè)
已閱讀1頁(yè),還剩17頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、<p><b>  中文4700字</b></p><p>  The Designing of Serial Communication Based on RS232</p><p><b>  Abstract</b></p><p>  This paper discussed the principle

2、of serial communication mainly, proposed the design method based on RS232, designed the hard circuit of serial communication, and realized the programming to PC Microcomputer and single chip microcomputer by using assemb

3、ly language and C++ Builder separately.</p><p>  Keywords: serial communication; single chip microcomputer; program design.</p><p>  I. INTRODUCTION</p><p>  During working in the c

4、ontrol system, the PC microcomputer sends instructions for step-by-step motor to collect the image information. Therefore the communication between the PC microcomputer and the driving system is needed for the communicat

5、ion system. In general, a complete communication system consists of transmitter, receiver, converting the data interface and transmitting data channel. The control of the step-by-step motor is realized through the pulse

6、distribution by single chip microcomp</p><p>  Serial communication is one of the oldest mechanisms for devices to communicate with each other. Starting with the IBM PC and compatible computers, almost all c

7、omputers are equipped with one or more serial ports and one parallel port. As the name implies, a serial port sends and receives data serially, one bit at a time. In contrast, a parallel port sends and receives data eigh

8、t bits at a time, using eight separate wires.</p><p>  For serial communication to work, you just need a minimum of three wires—one to send, one to receive, and one signal ground. For parallel communication,

9、 you need eight wires.</p><p>  Despite the comparatively slower transfer speed of serial ports over parallel ports, serial communication remains a popular connectivity option for devices because of its simp

10、licity and cost-effectiveness. It shows some of the devices that use a serial port to connect to the computer. Using a serial port, you can connect to a modem, a mouse, or a device such as a bridge/router for configurati

11、on purposes.</p><p>  II. THE BRIEF DESCRIPTION OF SERIAL PORT COMMUNITION</p><p>  Serial communication is the communication between sender and receiver data transfer is in the single data line

12、, to move each time a bit. The advantage is that only a pair of transmission lines to send information, so its low cost, suitable for long-distance communications; its disadvantage is that transmission speed is low.</

13、p><p>  As mentioned, a serial device sends and receives data one bit at a time. Some devices can send and receive data at the same time and are known as full-duplex devices. Others that can either send or rece

14、ive at any one time are known as single-duplex.</p><p>  To initiate transmission, a device first transmits a start bit, followed by the data bits. The data bits can be five, six, seven, or eight bits, depen

15、ding on what has been agreed upon. Both the sender and the receiver must be set to the same data bits for communication to take place correctly. Once the data bits are sent, a stop bit is sent. A stop bit can be one, one

16、 and a half, and two bits. The baud rate is the speed of transmission of data from one device to another. Baud rate is usually mea</p><p>  To detect that the data has been sent correctly, an optional parity

17、 bit can be included together with the data bits. A parity bit can be one of the following: odd, even, mark, space, or none (mark and space parity are almost always used). Using a parity bit provides a basic mechanism to

18、 detect corruption of data that was sent and does not guarantee that the data received is free from error. Nevertheless, a parity bit is useful for improving the integrity of the data sent.</p><p>  Most ser

19、ial ports adhere to the RS232C standard, which specifies a connector either with 25 pins or with 9 pins. Most serial devices use the nine-pin connector.</p><p>  Serial communication with asynchronous commun

20、ication and synchronous communication are two basic means of communication. Synchronous communication for the case of high transmission speed, the hardware complexity. The asynchronous communication used in transmission

21、speed between 50 and 19200 baud. Transmission is relatively common. In asynchronous communication, data is transmitted frame by frame, each frame of serial data format by a start bit, 5 to 8 data bits, a parity bit (opti

22、onal) and a Sto</p><p>  CMOS smart sensor IC has received wide application for low cost, miniaturization, intelligence and standardization. In smart sensor IC designs, the communication interface circuits a

23、lso play an important role other than sensors and signal processing circuits. There are more serial communication standard interfaces, such as RS-232, RS-485, USB Interface, IEEE-1394, which has itself good features and

24、also has focused on areas of application. RS-485 has a anti-noise capacity transmitting data, so i</p><p>  RS-232C standard RS-232C is the American Electronics Industry Association (EIA) formally announ

25、ced, in the asynchronous serial communication, the most widely used standard bus. The standard for DCE and DTE serial binary communication between the maximum data transfer rate of up to 19. 2kbps, the longest transmissi

26、on cables up to 15 meters 1RS - 232C standard defines the 25-lead, two-way communication in general, just Serial input RXD, serial output TXD and ground GND1RS - 232C standard level</p><p>  RS-232 is define

27、d as the single-ended standards, which has much characteristic, such as more communication distance in a low-speed serial communications, moderate price and good practicality of the system, so it is most appropriate to b

28、e a communication port. RS-232 is an essential modern computer interface, it includes ports COM1 and COM2, the port COM1 has 9-pin connector. The new generation computer has a 9-pin connector (DB9) so as to connect with

29、the RS-232 communication port. In order to a</p><p>  Figure 1. The RS-232 port</p><p>  III. THE HARDWARE DESIGN OF SERIAL PORT COMMUNICATION</p><p>  The in-out level of single ch

30、ip computer is TTL level, while the RS-232 serial interface of a PC computer is standard serial interface, so both the electrical specifications are inconsistent. In order to communicate with the upper and lower computer

31、, it is needed that the out level of single chip computer is changed to the TTL level. The common level converter chip between TTL and RS-232 level is MCI1488 and MCI1489. The MCI1488 converts TTL level to RS-232 level,

32、it needs the supply voltage of </p><p>  MAX232 is the product of the MAXIM Company; it is the road receiver and driver IC chip.</p><p>  About MAX232 chip MAXIM MAX232 chip is produced by l

33、ow-power, single-supply dual RS232 transmit / receiver 1 for all EIA-232E and V. 28 / V. 24 communication interfaces 1MAX232 a chip supply voltage converter, can+ 5V input power converted into RS - 232C ± 10V output

34、 voltage level required, so using this chip serial communications interface system as long as a single +5 V power supply can. MAX232 requires four external electrolytic capacitors C1, C2, C3, and C4, is the internal

35、capacitan</p><p>  MAX232 chip has a voltage converter which can transform the voltage of +5 V to the required voltage. Therefore, it adapts to the serial communication interface, moreover it has much charac

36、teristic, such as moderate price, the hardware simple, so it is used to be a voltage converter. The hardware circuit of serial communication module is shown in Figure 2.</p><p>  Figure 2. The hardware circu

37、it of serial communication module</p><p>  IV. THE SOFTWARE DESIGN OF SERIAL PORT COMMUNICATION</p><p>  The communication program of the single chip microcomputer communicates with PC computer

38、by interrupt and PC computer is called as main controller. When the single chip computer receives the data signals sent by PC computer, then it calls interrupt service program. The flowchart of the interrupt service main

39、 subprogram is shown in Figure 3. In order to fully exploit the efficiency of single chip computer to minimize CPU ‘time occupied by communication, the control program will be we will promptl</p><p>  A. The

40、 subprogram of serial port interrupts for receiving data</p><p>  The subprogram of serial port interrupts for receiving data is mainly responsible for receiving data sent by PC microcomputer and storing the

41、 data into allocated memory (it does not deal with data so as to reduce the time taken up by interruptions). The data received by the single chip microcomputer includes little information, such as speed, steps and on/off

42、 instructions, and the buffer is large enough to send the computer, so the software shake hands protocol is omit so as to raises the CPU ut</p><p>  B. The subprogram of sending the step-by-step impulse</

43、p><p>  Using counter-timer of the single chip microcontroller timer 0, as the fixed times complete, the p1.5 port is negated so as to periodically generate the driving pulses.</p><p>  The timer 0

44、 begins to count from initial value to 65535, then the interrupt sub-program of timer 0 is called, in which the p1.5 port is negated to generate a driving pulse. Meanwhile, the single chip microcomputer loads again the i

45、nitial value which is sent by the PC microcomputer by serial communication.</p><p>  Figure 3. The flowchart of the interrupt service main subprogram</p><p>  C. The subprograms of judging instr

46、uction</p><p>  The program of judging instruction is set on the serial port interrupt program to be called. The PC microcomputer sends data to the single chip microcomputer. After the single chip microcompu

47、ter receives data, it sets the RI higher and called the serial port interrupt sub-program, in which the first data is processed. If the first data is a digital symble”48”, the serial port interrupt sub-program sets P1.4

48、higher, then the next five bytes data is used to ensure the step-by-step motor’ speed and</p><p>  D. The processing subprogram of send interrupts</p><p>  The processing subprogram of send inte

49、rrupts is responsible to send data to the computer, sending interrupt state is off in the general. When the communication program completely deals with data sent by PC microcomputer, the symbol “1” can be written to send

50、 buffer. As the computer receives the symbol “1”, it is said that single chip computer executes completely the introduction sent by PC microcomputer. Therefore the serial port interrupt is set as “off” state by the singl

51、e chip microcontroller</p><p>  V. THE DESIGN OF COMMUNICATION PROGRAM OF PC MICROCOMPUTER AND SINGLE CHIP MICROCOMPUTER</p><p>  In order to realize the system software easily grafted and unifo

52、rmity, the program of upper computer is designed using the Boland C++ Builder 5.0 as a programming tool in the control system s the Boland C++ Builder 5.0 as a programming tool for PC programming. The serial port communi

53、cation can be utilized in two ways: First, register components, C++ Builder does not in itself provide a separate serial communication component, but it can be obtained through registered Microsoft MSComm32 component<

54、/p><p>  (1) Setting by communication protocol and opening the serial port, which is called initialization, then blocking the other programs to use the serial port.</p><p>  (2) Configuring the ser

55、ial port.</p><p>  (3) Transmitting data by the serial port to and fro, verifying data during transmission.</p><p>  (4) Closing the serial port as no needing it so that other program uses.</

56、p><p>  The sub-interface is simple, in which the setting on sub-interface parameters are defaults, such as baud rate that single chip communication module has been set to 2400Bps and that the baud rate is set

57、to 2400Bps in the computer settings on the ports. The PC microcomputer has two ports called as serial port COM1 and COM2 generally, so the program can automatically identify serial port so that it can send and receive da

58、ta and instructions successfully.</p><p>  Serial communication program includes two aspects, one is MCS-51 microcontroller communication program, on the other hand for the PC, the communication process. In

59、the preparation processes, the development of the two protocols is very important, otherwise it will not guarantee the reliability of data communications, and thus lose the meaning of communication. The communication pro

60、tocol is agreed as follows:1) The serial communication baud rate is 1200bps.2) The frame format is: a start bit, e</p><p>  VI. CONCLUSION</p><p>  The hardware of serial port communication is

61、 designed based on RS232, and the software of communication module between PC microcomputer and single chip microcomputer were programmed by using C++ Build and assembly language. The control system runs well on industry

62、 field, and controls the stepping motor’ Start/Stop and Forward/Reversal rotation by controlling single microcomputer. The PC microcomputer sends out control instruction to the single microcomputer by friendly user inter

63、face.</p><p>  REFERENCES</p><p>  [1] Fan Yizhi, Jiang Wenxiang, Chen Liyuan. Serial communication control based C++Build and RS232. Beijng: Tsinguua University Press, 2002, pp. 2-18</p>

64、<p>  [2] Gou Suai. C++Builder 5.0 Programmer’s Guide. Beijing: Beijing Hope Electronic Press, 2001, pp. 1-6</p><p>  [3] Liu Yanling. The Use of Communication Between MCS-51 Single Chip Microcomputer

65、and PC Microcomputer with MAX232. Journal of Tianjin Institute of Technology, 1999, Vol, 15(2): pp. 56-58</p><p>  [4] Yang Guoxia. Dealing With The Data Communication Between The Serial Port And The Main Pr

66、ogram by Message. Journal of The Hebei Academy of Sciences, 2001, Vol. 18(4): pp. 220-223</p><p>  [5] LI Buyin, Jiang Shenglin, Lu Wenzhong, Zhou Dongxiang. Serial Communication Programming Design Based on

67、C Language. Journal of Transcluction Technology, 2002, Vol. (2), pp. 65-66</p><p>  [6] Wang Zhihong.The serial communication of single chip microcomputer and PC. Modern Electronic Technique, 2000,119, pp. 6

68、8-70</p><p>  基于RS-232的串行通信設(shè)計(jì)</p><p><b>  摘 要</b></p><p>  論文抽象地論述了串行通信的主要原則,提出了在RS232的基礎(chǔ)上,設(shè)計(jì)串行通訊硬電路的方法。實(shí)現(xiàn)了分別在PC微機(jī)和單片機(jī)中使用匯編語(yǔ)言和C++Builder的編程。</p><p>  關(guān)鍵詞:串行

69、通信;單片機(jī);程序設(shè)計(jì)</p><p><b>  一、緒論</b></p><p>  在控制系統(tǒng)的工作中,PC微機(jī)通過(guò)發(fā)送指令到步進(jìn)電機(jī)中來(lái)收集圖像信息。因此,PC微機(jī)和驅(qū)動(dòng)系統(tǒng)之間的通信是系統(tǒng)通信所必需的。一般來(lái)說(shuō),一個(gè)完整的通信系統(tǒng)由發(fā)射器,接收器,轉(zhuǎn)換數(shù)據(jù)接口和傳輸數(shù)據(jù)通道所構(gòu)成。該步進(jìn)電機(jī)是通過(guò)單芯片來(lái)實(shí)現(xiàn)微機(jī)控制脈沖分配的。在電機(jī)的控制系統(tǒng)中,PC微機(jī)被

70、稱(chēng)為上位機(jī),而由單片機(jī)所控制的步進(jìn)電機(jī)被稱(chēng)為下位機(jī)。上位機(jī)與下位機(jī)之間的通信有兩個(gè)方法,它們分別是并行通信和串行通信。并行通信可以同時(shí)傳輸大量的數(shù)據(jù),具有傳送速度快的優(yōu)點(diǎn)。但是當(dāng)傳輸距離遠(yuǎn),并且傳輸數(shù)據(jù)的數(shù)量很多時(shí),它需要的傳輸線的數(shù)目也更多。此外,電壓等級(jí)會(huì)因?yàn)檩旊娋€路的因素和電磁干擾而改變。串行通信是一個(gè)數(shù)據(jù)按一個(gè)個(gè)序位單向傳輸?shù)耐ǖ溃渲袃蓚€(gè)過(guò)渡線是實(shí)現(xiàn)雙向通信傳輸?shù)男枰?。正是考慮到在控制系統(tǒng)中需傳遞的數(shù)據(jù)量多,而單次傳輸?shù)臄?shù)量少

71、,因此在控制系統(tǒng)中選擇串口通信的方法,簡(jiǎn)化了硬件結(jié)構(gòu)并節(jié)約了所需的成本。</p><p>  串行通信是最古老的溝通機(jī)制之一。從IBM個(gè)人電腦和兼容式電腦的時(shí)代開(kāi)始,幾乎所有的計(jì)算機(jī)都配有一個(gè)或多個(gè)串行端口和一個(gè)并行端口。顧名思義,一個(gè)串行端口發(fā)送和接收串行數(shù)據(jù),一次一位數(shù)據(jù)。相反,一個(gè)并行端口一次發(fā)送和接收8位數(shù)據(jù),使用8個(gè)單獨(dú)的電線。</p><p>  要使串行通信工作,你只需要一根

72、三根線的電纜——1根發(fā)送,1根用來(lái)接收,1根接地。對(duì)于并行通信,你需要采用8條導(dǎo)線。</p><p>  盡管相對(duì)較慢的傳輸速度遠(yuǎn)低于并行端口,串行端口通信依然因?yàn)樗?jiǎn)單的設(shè)備和高的成本效益而成為一個(gè)受歡迎的連接選項(xiàng)。它表現(xiàn)為一些設(shè)備使用串口連接到計(jì)算機(jī)。使用串行端口,你可以連接到調(diào)制解調(diào)器,鼠標(biāo)或其它設(shè)備,如一個(gè)橋梁/路由器進(jìn)行配置。</p><p><b>  二、串口通訊的

73、簡(jiǎn)述</b></p><p>  串行通信是指通信的發(fā)送方和接收方之間數(shù)據(jù)信息的傳輸是在單根數(shù)據(jù)線上,以每次一個(gè)二進(jìn)制位移動(dòng)。它的優(yōu)點(diǎn)是只需一對(duì)傳輸線進(jìn)行傳送信息,因此其成本低,適用于遠(yuǎn)距離通信;它的缺點(diǎn)是傳送速度低。</p><p>  如前所述,一個(gè)串行設(shè)備一次發(fā)送和接收一個(gè)位的數(shù)據(jù)。有些設(shè)備因?yàn)樵谕粫r(shí)間發(fā)送和接收數(shù)據(jù),被稱(chēng)為全雙工設(shè)備。其他可以在任何時(shí)間發(fā)送或接收被稱(chēng)為

74、單雙工設(shè)備。</p><p>  開(kāi)始傳輸時(shí),設(shè)備先發(fā)送一個(gè)起始位,其次是數(shù)據(jù)位。該數(shù)據(jù)位可以是五、六、七或八位,基于商定而定。發(fā)送器和接收器必須設(shè)置為相同的數(shù)據(jù)通信比特或正確的比特率。數(shù)據(jù)位被發(fā)送完后,就會(huì)發(fā)送一個(gè)停止位。一個(gè)停止位可以是一位,一個(gè)半位,或兩位。波特率是數(shù)據(jù)從一個(gè)設(shè)備到另一個(gè)的傳輸速度。波特率通常以每秒的位數(shù)(bps)來(lái)計(jì)量。大多數(shù)串行設(shè)備傳輸七、八位數(shù)據(jù)。</p><p&g

75、t;  為了檢測(cè)數(shù)據(jù)已被正確發(fā)送,一個(gè)可選的校驗(yàn)位可以同數(shù)據(jù)位在一起。一個(gè)校驗(yàn)位可以是以下內(nèi)容:奇數(shù),偶數(shù),標(biāo)記,空白或無(wú)(空的奇偶位標(biāo)志幾乎總是被使用)。使用校驗(yàn)位提供了一個(gè)基本的機(jī)制,以檢測(cè)已發(fā)送數(shù)據(jù)是否損壞,但不保證檢查數(shù)據(jù)本身的錯(cuò)誤。然而,校驗(yàn)位可用于改善完整數(shù)據(jù)的傳送。</p><p>  大多數(shù)串行端口使用RS232C標(biāo)準(zhǔn),它指定了一個(gè)25針或9針的連接器。大多數(shù)系列設(shè)備使用9針連接器。</p&

76、gt;<p>  串行通信有異步通信和同步通信兩種基本通信方式。同步通信適用于傳送速度高的情況,其硬件復(fù)雜。而異步通信應(yīng)用于傳送速度在50到19200波特之間,是比較常用的傳送方式。在異步通信中,數(shù)據(jù)是一幀一幀傳送的,每一串行幀的數(shù)據(jù)格式由一位起始位,5~8位的數(shù)據(jù)位,一位奇偶校驗(yàn)位(可省略)和一位停止位四部分組成。在串行通信前,發(fā)送方和接收方要約定具體的數(shù)據(jù)格式和波特率(通信協(xié)議)。PC機(jī)采用可編程串行異步通信控制器82

77、50來(lái)實(shí)現(xiàn)異步串行通信。通過(guò)對(duì)8250的初始化編程,可以控制串行數(shù)據(jù)傳送格式和速度。在PC機(jī)中一般有兩個(gè)標(biāo)準(zhǔn)RS-232C串行接口COM1和COM2。MCS-51系列單片機(jī)片內(nèi)含有一個(gè)全雙工的串行接口,通過(guò)編程也可實(shí)現(xiàn)串行通信功能。</p><p>  智能傳感器的CMOS芯片因?yàn)槠涞统杀?,小型化,智能化和?biāo)準(zhǔn)化的特點(diǎn)已得到廣泛應(yīng)用。在智能傳感器IC設(shè)計(jì)中,在傳感器和信號(hào)處理電路以外,通訊接口電路也可發(fā)揮重要角色

78、。串行通信擁有很多的標(biāo)準(zhǔn)接口,如RS-232,RS-485,USB接口和IEEE-1394。它們都有著自身的特點(diǎn),同時(shí)也分別適用于不同的的應(yīng)用領(lǐng)域。RS-485的數(shù)據(jù)傳輸具有抗噪聲的特點(diǎn),因此它通常用于工業(yè)生產(chǎn)。USB接口和IEEE-1394具有傳輸速度快的優(yōu)點(diǎn),但是有一些電腦和操作系統(tǒng)并不支持這種接口。RS-232是在PC機(jī)中和通信行業(yè)中應(yīng)用最廣泛的的串行接口。RS-232C標(biāo)準(zhǔn)是異步串行協(xié)議溝通,并已廣泛應(yīng)用于個(gè)人電腦和通信產(chǎn)業(yè)。許

79、多短距離打印機(jī)等電腦外設(shè),所有磁盤(pán)和終端與PC機(jī)通過(guò)RS232串行接口通信。</p><p>  RS-232C 標(biāo)準(zhǔn)</p><p>  RS-232C是美國(guó)電子工業(yè)協(xié)會(huì)(EIA)正式公布的,在異步串行通信中應(yīng)用最廣的標(biāo)準(zhǔn)總線。該標(biāo)準(zhǔn)適用于DCE和DTE間的串行二進(jìn)制通信,最高數(shù)據(jù)傳送速率可達(dá)19.2kbps,最長(zhǎng)傳送電纜可達(dá)15米。RS-232C標(biāo)準(zhǔn)定義了25根引線,對(duì)于一般的雙向通信

80、,只需使用串行輸入RXD,串行輸出TXD和地線GND。RS-232C標(biāo)準(zhǔn)的電平采用負(fù)邏輯,規(guī)定+3V~+15V之間的任意電平為邏輯“0”電平,-3V~-15V之間的任意電平為邏輯“1”電平,與TTL和CMOS電平是不同的。在接口電路和計(jì)算機(jī)接口芯片中大都為T(mén)TL或CMOS電平,所以在通信時(shí),必須進(jìn)行電平轉(zhuǎn)換,以便與RS-232C標(biāo)準(zhǔn)的電平匹配。MAX232芯片可以完成電平轉(zhuǎn)換這一工作。</p><p>  RS-

81、232被定義為單端標(biāo)準(zhǔn),它具有許多的優(yōu)點(diǎn),如更低速的串行通信,通信距離遠(yuǎn),適中的價(jià)格和良好的系統(tǒng)實(shí)用性,所以它是最適用的一個(gè)通信端口。RS-232是一個(gè)基本現(xiàn)代化的計(jì)算機(jī)接口,它包括COM1和COM2端口,該端口COM1有九針連接器。新一代的計(jì)算機(jī)有一個(gè)九針連接器(DB9),這樣就可以通過(guò)這個(gè)九針連接器來(lái)連接RS-232串行端口。為了實(shí)現(xiàn)可靠的,實(shí)時(shí)的傳輸,該系統(tǒng)采用三線連接方式,即RS-232端口的GND引腳,RXD引腳和TXD的引腳

82、與外部端口連接,如圖1所示。</p><p>  圖1.RS-232的端口</p><p>  三、串行通信端口的硬件設(shè)計(jì)</p><p>  單片機(jī)應(yīng)用的是TTL電平,而PC機(jī)的RS-232串行接口使用的是標(biāo)準(zhǔn)的串行接口標(biāo)準(zhǔn),所以?xún)烧叩碾姎庑阅芤?guī)格是不一致的。為了溝通上位機(jī)和下位機(jī),就需要將單片機(jī)輸出的TTL電平進(jìn)行轉(zhuǎn)換。常見(jiàn)的TTL電平和RS-232電平之間的電

83、平轉(zhuǎn)換芯片是MCI1488和MCI1489。TTL電平可由MCI1488轉(zhuǎn)換為RS-232電平,它需要±12V電源電壓,而MCI1489可以將RS-232轉(zhuǎn)換成標(biāo)準(zhǔn)級(jí)的TTL電平,它需要電源電壓為+5V。由于適用三個(gè)電源電壓,電路將不可避免地變得復(fù)雜,所以該電路采用標(biāo)準(zhǔn)的RS-232芯片MAX232。</p><p>  MAX232芯片簡(jiǎn)介</p><p>  MAX232是M

84、axim公司的產(chǎn)品,它是路徑接收和驅(qū)動(dòng)IC芯片。MAX232芯片是Maxim公司生產(chǎn)的低功耗、單電源雙RS232發(fā)送/接收器,適用于各種EIA-232E和V.28/V.24的通信接口。MAX232芯片內(nèi)部有一個(gè)電源電壓變換器,可以把輸入的+5V電源變換成RS-232C輸出電平所需±10V電壓,所以采用此芯片接口的串行通信系統(tǒng)只要單一的+5V電源就可以。</p><p>  MAX232外圍需要4個(gè)電解電

85、容C1、C2、C3、C4,是內(nèi)部電源轉(zhuǎn)換所需電容。其取值均為1μF/25V,宜選用鉭電容并且應(yīng)盡量靠近芯片,C5為0.1μF的去耦電容。</p><p>  MAX232的引腳T1IN、T2IN、R1OUT、R2OUT為接TTL/CMOS電平的引腳,引腳T1OUT、T2OUT、R1IN、R2IN為接RS-232C電平的引腳。因此TTL/CMOS 電平的T1IN、T2IN 引腳應(yīng)接MCS-51的串行發(fā)送引腳TXD;

86、R1OUT、R2OUT應(yīng)接MCS-51的串行接收引腳RXD,與之對(duì)應(yīng)的RS-232C電平的T1OUT、T2OUT應(yīng)接PC機(jī)的接收端RD;R1IN、R2IN應(yīng)接PC機(jī)的發(fā)送端TD。MAX232芯片有一個(gè)電壓轉(zhuǎn)換器,它可以改變+5V的電壓至所需的電壓。因此,它適應(yīng)了串行通信接口。不僅如此,它有許多優(yōu)點(diǎn),比如價(jià)格適中,硬件簡(jiǎn)單等等。因此,用它來(lái)作為電壓轉(zhuǎn)換器適用。串行通信模塊的硬件電路如圖2所示。</p><p>  

87、圖2 串行通信模塊的硬件電路</p><p>  四、串口通信的軟件設(shè)計(jì)</p><p>  單片機(jī)的通信程序與PC機(jī)之間通過(guò)中斷通信,PC機(jī)被稱(chēng)為主控制器。當(dāng)單片機(jī)接收通過(guò)PC電腦發(fā)送的數(shù)據(jù)信號(hào)時(shí),它就會(huì)調(diào)用中斷服務(wù)程序。中斷服務(wù)子程序流程圖如圖3所示。為了充分利用單片機(jī),以減少CPU的占用時(shí)間,提高溝通效率,控制程序?qū)⑹俏覀儠?huì)及時(shí)響應(yīng)和控制的對(duì)象,通訊程序?qū)⒌玫絻?yōu)化。子程序的串口接收數(shù)

88、據(jù),逐個(gè)發(fā)送脈沖,通過(guò)上升沿判斷指令子程序和中斷子程序發(fā)送的數(shù)據(jù)。</p><p>  A串口中斷子程序用于接收數(shù)據(jù)</p><p>  用于接收數(shù)據(jù)的串行端口的中斷子程序,主要是將PC微機(jī)接收和發(fā)送的數(shù)據(jù)存儲(chǔ)到分配的內(nèi)存中(不進(jìn)行數(shù)據(jù)處理,以減少中斷的時(shí)間)。由單片機(jī)接收到的數(shù)據(jù)包括一些信息,如速度,步驟和開(kāi)/關(guān)指示,由于緩沖區(qū)的大小足夠把這些數(shù)據(jù)發(fā)送到電腦中,所以省略了軟件握手協(xié)議,以

89、提高CPU利用率。當(dāng)串口中斷程序接收到指定的數(shù)據(jù)時(shí),便退出串行口中斷。</p><p>  B發(fā)送步進(jìn)脈沖子程序</p><p>  使用反單晶片微控制器定時(shí)器0,作為固定的時(shí)間計(jì)時(shí),能使P1.5端口電平被反轉(zhuǎn),從而產(chǎn)生周期性的驅(qū)動(dòng)脈沖。定時(shí)器從0開(kāi)始計(jì)數(shù)初始值65535,然后中斷設(shè)定的定時(shí)器0被調(diào)用,在其中P1.5端口電平被反轉(zhuǎn)產(chǎn)生驅(qū)動(dòng)脈沖。同時(shí),單片機(jī)重新載入由PC機(jī)通過(guò)串行通信微機(jī)發(fā)

90、送的初始值。</p><p>  圖3 主要中斷服務(wù)子程序流程圖</p><p><b>  C判斷指令的子程序</b></p><p>  PC微機(jī)發(fā)送數(shù)據(jù)到單片機(jī)。經(jīng)過(guò)單片機(jī)接收數(shù)據(jù),并調(diào)用串口中斷子程序,它第一次發(fā)送的數(shù)據(jù)被處理。如果第一個(gè)數(shù)據(jù)是一個(gè)數(shù)字標(biāo)記“48”,串行口中斷分程序設(shè)置P1.4腳為高電平,那么接下來(lái)的五個(gè)字節(jié)的數(shù)據(jù)用于確

91、保步進(jìn)電機(jī)的速度和步驟。如果第一個(gè)數(shù)據(jù)是一個(gè)數(shù)字標(biāo)記“49”,這意味著步進(jìn)電機(jī)反轉(zhuǎn),則單片機(jī)接收到發(fā)送來(lái)的速度和步驟信息。否則,單片機(jī)判定接收到的數(shù)據(jù)是不是“停止”指令,如果是這樣,它發(fā)出“停止”指令驅(qū)動(dòng)系統(tǒng),如果沒(méi)有,它便退出中斷。D發(fā)送中斷處理子程序 發(fā)送中斷處理子程序負(fù)責(zé)將數(shù)據(jù)發(fā)送到計(jì)算機(jī),中斷狀態(tài)一般為不允許中斷。當(dāng)通信方案完全由PC微機(jī)發(fā)送的數(shù)據(jù)交換,代碼為“1”可寫(xiě)入發(fā)送緩沖區(qū)。隨著計(jì)算機(jī)接收代碼“1”,這表明,單

92、片機(jī)上執(zhí)行完全由PC微機(jī)發(fā)送的指令。因此,串口中斷設(shè)置為“關(guān)閉”狀態(tài)的單片機(jī),將它設(shè)定為“開(kāi)”狀態(tài)的數(shù)據(jù)后再發(fā)送數(shù)據(jù)。這時(shí),單片機(jī)返回到主程序和等待接收指令。</p><p>  五、PC和單片機(jī)通信程序的設(shè)計(jì)</p><p>  為了方便地實(shí)現(xiàn)系統(tǒng)軟件移植和統(tǒng)一,上位機(jī)程序的設(shè)計(jì)使用作為控制系統(tǒng)編程工具C++Builder 5.0 ,C++Builder 5.0是一個(gè)PC的編程工具。串行

93、口通信可以利用兩種方式:一是注冊(cè)組件,生成的C++本身并不提供單獨(dú)的串行通訊組件,但是它可通過(guò)已注冊(cè)的Microsoft MSComm32成分,生成相對(duì)簡(jiǎn)單的VB,VC代碼。第二種方法是調(diào)用Windows API(應(yīng)用程序接口)函數(shù),此函數(shù)是由操作系統(tǒng)提供,以提供大量的功能。該設(shè)計(jì)的步驟如下:</p><p> ?。?)設(shè)置通信協(xié)議,打開(kāi)串行端口,這是所謂的初始化,然后阻止其他程序使用串行端口。</p>

94、;<p><b> ?。?)配置串口。</b></p><p> ?。?)傳遞串口轉(zhuǎn)來(lái)的數(shù)據(jù),驗(yàn)證數(shù)據(jù)的傳輸過(guò)程。</p><p>  (4)關(guān)閉串口,供其他程序使用。</p><p>  子接口很簡(jiǎn)單,其中的子接口的參數(shù)設(shè)置,如波特率通信模塊的芯片已被設(shè)置為2400Bps,在計(jì)算機(jī)上的端口的默認(rèn)設(shè)置2400Bps。微機(jī)具有兩個(gè)串

95、口,一般稱(chēng)為COM1和COM2,以便程序可以自動(dòng)識(shí)別串行端口,利于端口成功的發(fā)送和接收數(shù)據(jù)和指令。</p><p>  串行通信程序包括兩部分,一部分是MCS-51單片機(jī)的通信程序,另一部分是PC機(jī)的通信程序。在編寫(xiě)程序之前,制定其雙方通信協(xié)議是十分重要的,否則將無(wú)法保證通信數(shù)據(jù)的可靠性,從而失去通信的意義?,F(xiàn)約定其通信協(xié)議如下:</p><p> ?。?)串行通信波特率為1200bps。

96、</p><p>  (2)幀格式為:一位起始位,八位數(shù)據(jù)位,一位可編程的第九位(此位為發(fā)送和接收的地址/數(shù)據(jù)的標(biāo)志位),一位停止位。</p><p>  (3)設(shè)定單片機(jī)的地址碼為F1H。在傳送數(shù)據(jù)前先聯(lián)絡(luò)地址碼,如地址碼正確則傳送數(shù)據(jù),否則繼續(xù)聯(lián)絡(luò)地址碼。</p><p> ?。?)無(wú)奇偶校驗(yàn)位。數(shù)據(jù)的通信采用累加和校驗(yàn)的方法,即每傳送一組數(shù)據(jù)(個(gè)數(shù)自定,設(shè)為1

97、00個(gè)),校驗(yàn)一次累加和是否正確,正確則返回00H,否則返回FFH。</p><p> ?。?)通信可以有中斷傳送方式和查詢(xún)方式。在這里介紹查詢(xún)方式通信。</p><p> ?。?)聯(lián)絡(luò)方式為PC機(jī)主動(dòng)聯(lián)絡(luò)MCS-51單片機(jī)。</p><p> ?。?)PC機(jī)采用COM2通信。</p><p><b>  六、結(jié)論</b>

98、;</p><p>  串口通信的硬件設(shè)計(jì)基于RS-232,PC機(jī)和單片機(jī)之間進(jìn)行通信的軟件模塊使用C++和匯編語(yǔ)言編程。該控制系統(tǒng)在產(chǎn)業(yè)領(lǐng)域運(yùn)行良好,并通過(guò)控制單個(gè)步進(jìn)電機(jī)啟動(dòng)/停止和正轉(zhuǎn)/反轉(zhuǎn)旋轉(zhuǎn)。PC微機(jī)通過(guò)友好的用戶(hù)界面向單片機(jī)發(fā)送控制指令。</p><p><b>  參考文獻(xiàn)</b></p><p>  [1]樊一支,姜文祥,陳梨園

99、.串行通信控制的C++生成和RS232.北京:清華大學(xué)出版社,2002年,第2-18</p><p>  [2]茍?zhí)K艾.C++Builder5.0的的程序員指南.北京:北京希望電子出版社,2001年,第1-6</p><p>  [3]劉艷玲.使用MAX232進(jìn)行的MCS-51單片機(jī)與PC機(jī)之間的的通信.天津科技,1999年,第研究所15(2):第56-58</p><

100、p>  [4]楊國(guó)霞.采用消息方式處理串口與主程序間的通訊.雜志:促進(jìn)科技,2001年,河北省科學(xué)院卷.18(4):220-223頁(yè)</p><p>  [5]黎步銀,江盛林,盧重,周東祥.基于C語(yǔ)言的串行通信程序設(shè)計(jì).作者:Transcluction技術(shù),2002,卷.(2)第65-66</p><p>  [6]王志忠.單片機(jī)和PC機(jī)之間的串行通信.現(xiàn)代電子技術(shù),2000,119

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 眾賞文庫(kù)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論