外文翻译中英对照--基于RS-232的串行通信.doc_第1页
外文翻译中英对照--基于RS-232的串行通信.doc_第2页
外文翻译中英对照--基于RS-232的串行通信.doc_第3页
外文翻译中英对照--基于RS-232的串行通信.doc_第4页
外文翻译中英对照--基于RS-232的串行通信.doc_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

外文翻译 专业: 班级: 姓名: 基于RS-232的串行通信摘要这篇文章论述了串行通信的主要原则,提出了在RS232的基础上,设计串行通讯硬电路的方法。实现了分别在PC微机和单片机中使用汇编语言和C+Builder编程。关键词:串行通信;单片机;程序设一绪论在控制系统的工作中,PC微机发送指令到步进电机中来收集图像信息。因此,PC微机和驱动系统之间的通信是系统通信所必需的。一般来说,一个完整的通信系统由发射器、接收器、转换数据接口和传输数据通道所构成。该步进电机是通过单芯片来实现微机控制脉冲分配的。在电机的控制系统中,PC微机被称为上位机,而由单片机所控制的步进电机被称为下位机。上位机与下位机之间的通信有两个方法,他们分别是串行通信和并行通信。并行通信可以同时传输大量的数据,具有传送速度快的优点。但是当传输距离远,并且传输数据的数量很多时,它需要的传输线的数目也更多。此外,电压等级会因为输电线路的因素和电压干扰而改变。串行通信是一个数据按一个个序位单向传输的通道,其中两个过渡线是需要实现双向通信传输。正是考虑到在控制系统中需传递的数据多,而单次传输的数量少,因此在控制系统中选择串口通信的方法,从而简化了硬件结构并节约了所需的成本。二串口通讯的简述每次一个二进制位移动的。它的优点是只需一对传输线进行传送信息,因此其成本低,适用于远距离通信;它的缺点是传送速度低。串行通信有异步通信和同步通信两种基本通信方式。同步通信适用于传送速度高的情况,它的硬件复杂。而异步通信应用于传送速度在50到19200波特之间。是比较常用的传送方式。在异步通信中,数据是一帧一帧传送的,每一串行帧的数据格式由一位起始位,5-8位的数据位,一位奇偶校验位(可省略)和一位停止位四部分组成。在串行通信前,发送方和接收方要约定具体的数据格式和波特率(通信协议),PC机采用可编程串行异步通信控制器8250来实现异步串行通信。通过对8250的初始化编程,可以控制串行数据传送格式和速度。在PC机中一般有两个标准RS-232C串行接口COM1和COM21MCS51系列单片机内含有一个全双工的串行接口,通过编程也可实现串行通信功能。智能传感器的CMOS芯片应为其低成本,小型化,智能化和标准化的特点已得到广泛应用。在智能传感器IC设计中,在传感器和信号处理电路以外,通信接口电路也可发挥重要角色。串行通信拥有很多的标准接口,如RS-232,RS_485,USB接口和IEEE-1394。它们各自都有着自身的特点,同时也分别适用于不同的应用领域。RS-485具有抗噪声数据传输的特点,因此它通常用于工业生产。USB接口和IEEE-1394具有传输速度快的优点,但是有一些电脑和操作系统并不支持这种接口。RS-232是在PC机中和通信行业中应用最广泛的串行接口。RS-232C标准是异步串行协议沟通,并已广泛应用于个人电脑和通信产业。许多短距离打印机等电脑外设交际,所以磁盘和终端与PC机通过RS232通信串行接口。RS-232标准RS-232是美国电子工业协会(EIA)正式公布的,在异步串行通信中应用最广泛的标准总线。该标准适用于DCE和DTE间的串行二进制通信,最高数据传输速率可达19.2kbps,最长传送电缆可达15米IRS-232C标准定义了25根引线。对于一般的双向通信,只需使用串行输入RXD,串行输出TXD和地线GND1RS-232C标准的电平采用负逻辑,规定+3V-+15V之间的任意电平为逻辑“0”电平,-3V-15V之间的任意电平为逻辑“1”电平,与TTL和CMOS电平是不同的。在接口电路和计算机接口芯片中大多为TTL或CMOS电平,所以在通信时,必须进行电平转换,以便与RS-232C标准的电平匹配1MAX232芯片可以完成电平转换这一工作。RS-232C被定义为单端标准,它具有许多的优点,如更低速的串行通信,通信距离远,适中的价格和良好的系统适用性,所以它是最试用的一个通信端口。RS-232是一个基本现代化的计算机接口,它包括COM1和COM2端口,该端口COM1有9针连接器。新一代的计算机有一个9针连接器(DB9),这样就可以通过这个9针连接器来连接RS-232串行端口。为了实现可靠的,实时的传输,该系统采用三线连接方式,即RS-232端口的GND引脚,RXD引脚和TXD引脚与外部端口连接,如图1所示。连接端口电脑端口 图1.RS-232端口三串口通信的软件设计该单片机与PC机之间通过中断与PC机通信程序通信被称为主控制器。当单片机接收通过PC电脑发送的数据信号时,它就会调用中断服务程序。为了充分利用单片机,以减少CPU的占用时间,提高沟通效率,控制程序将是我们会及时响应和控制的对象。通讯程序将得到优化。子程序的串口接收数据,逐个发送脉冲,为判断指令子程序和中断子程序发送数据。A串口中断子程序用于接收数据对用于接收数据的串行端口的中断子程序主要是由PC接收和发送的数据存储到分配的内存中的数据(不与数据处理,以减少由中断注册的时间)负责。由单片机接收到的数据包括一些信息,如速度,步骤和开/关指示,由于缓冲区的大小足够把这些数据发送到电脑中,所以省略了软件握手协议,以提高CPU利用率。当串口中断程序接收到指定的数据时,便退出串行口中断。B发送步进脉冲子程序使用反单晶片微控制器定时器0定时器,作为固定的时间完成,能使P1.5端口被否定,从而产生周期性的驱动脉冲。定时器从0开始计数初始值65535,然后中断分项计划的定时器0被调用,在其中P1.5端口被否定产生驱动脉冲。同时,单片机重新载入PC机通过串行通信微机发送的初始值。C判断指令的子程序教学计划的判断上设置被称为串行口中断的程序。PC微机发送数据到单片机。经过单片机接收数据,并调用串口中断子程序,其中第一次发送的数据被处理。如果第一个数据是一个数字symble“48”,串行口中断分程序设置P1.4脚高,那么接下来的五个字节的数据用于确保步进电机的速度和步骤。如果第一个数据是一个数字symble“49”,这意味着步进电机反转,则单片机接收到发送来的速度和步骤信息。否则,单片机判定接收到的数据是不是“STOP”指令,如果是这样,它发出“停止”指令驱动系统,如果没有,他便推出中断。D发送中断处理子程序在发送中断处理子程序负责将数据发送到计算机,发送中断状态一般是关闭的。当通信方案完全由PC微机发送的数据交易,代码为“1”可写入发送缓冲区,随着计算机接收符号“1”,这是说,单片机上执行完全由PC微机发送的介绍。因此,串口中断设置为“关闭”状态的单片机,他设定为“开”状态的数据后再发送。因此,单片机返回到主程序和等待接收指令。4 PC和单片机通信程序的设计 为了方便地实现系统软件移植和统一,上位机程序的设计使用作为控制系统编程工具博兰的C+Builder的5.0是一个PC编程的编程工具。串行口通信可以利用两种方式:一是注册组件,生成的C+本身并不提供单独的串行通讯组件,但是它可通过已注册的Microsoft MSComm32成分,其中相对简单的VB,VC的这种方式。第二种方法是调用Window API(应用程序接口)函数,此函数是由操作系统提供,以提供大量的行政职能。该计划的步骤是如下:(1) 设置的通信协议,打开串行端口,这是所谓的初始化,然后阻止其他的程序使用串行端口。(2) 配置串口。(3) 传递串口转来的数据,验证数据的传输过程。(4) 关闭串口,使其他程序试用。 子接口很简单,其中的子接口的设置,如波特率通信模块的单芯片已被设置为2400Bps和波特率设置为在计算机上的端口的默认设置2400Bps。微机具有两个串口,一般称为COM1和COM2,以便程序可以自动识别串行端口,利于端口可以成功的发送和接收数据和指令。串行通信程序包括两个方面,一方面是MCS-51单片机的通信程序,另一方面为PC机的通信程序。在编写程序之前,制定其双方通信协议是十分重要的,否则将无法保证通信数据的可靠性,从而失去通信的意义。现约定其通信协议如下:(1) 串行通信波特率为1200bps。(2) 帧格式为:一位起始位,八位数据位,一位可编程的第九位(此位为发送和接收的地址/数据的标志位),一位停止位。(3) 设定单片机的地址码为F1H。在传送数据前先联络地址码,如地址码正确则传送数据,否则继续联络地址码。(4) 无奇偶校验位。数据的通信采用累加和校验的方法,即每传送一组数据(个数自定,设为100个),校验一次累加和是否正确,正确则回送00H,否则回送FFH。(5) 通信可以有中断传送方式和查询方式。在这里介绍查询方式通信。(6) 联络方式为PC机主动联络MCS-51单片机。(7) PC机采用COM2通信。四结论串口通信的硬件设计基于RS-232,PC机和单片机之间进行通信的软件模块使用C+编译和汇编语言编程。该控制系统在产业领域运行良好,并通过控制单个步进电机启动/停止和正转/反转旋转。PC危机通过友好的用户界面向单片机发送控制指令。参考文献【1】樊一支,姜文祥,陈梨园。串行通信控制的C+生成和RS232.北京:清华大学出版社,2002年,第2-18【2】苟苏艾。C+Builder5.0的程序员指南。北京:北京希望电子出版社,2001年,第1-6【3】刘艳玲。使用MAX232进行的MCS-51单片机与PC机之间的通信。天津科技,1999年,第56-58【4】杨国霞。采用消息方式处理串口与主程序间的通讯。杂志:促进科技,2001年,河北省科学院卷。18(4):220-223页【5】黎步银,江盛林,卢重,周东祥。基于C语言的串行通信程序设计。作者:Transcluction技术,2002,卷。(2)第65-66【6】王志忠。单片机和PC机之间的串行通信。现代电子技术,2000,119,第68-7The Designing of Serial Communication Base on RS232Abstract-This Paper discussed the principle 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 assembly language and C+ Builder separately,Keywords-serial communication;single chip microcomputer;program designI.INTRODUCTIONDuring working in the control 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 communication system.In general,a complete communication system consists of transmitter,receiver,converting the data interface and transmitting data channel.The control of tne step-by step motor is realized through the pulse distribution by single chip microcomputer.On the motor control system,the PC microcomputer is called as upper computer,and the single chip microcomputer for driving step_by_step motor is called as lower computer.The communication between the upper computer and the lower computer has two methods,that si to say the parallel interface can transmit much data at the same time and has the fast speed,but when the transmission distance is far and the number of data is much,it needs more the number of transmission lines.In addition,the voltage level may be changed by the transmission line factor and electromagnetic interference.Serial communication is utilized in the control system so as to simplify the hardware and save the cost. II. THE BRIEF DESCRIPTION OF SERIAL PORT COMMUNITION Serial communication is the communication between sender and receiver data line,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 communication;its disadvantage is that transmission speed is low.Serial communication with asynchronous communication 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 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(optional) and a Stop bit of four parts.Before the serial communication,the sender and receiver to agree the specific data format and baud rate(communication protocol).PC-programmable serial asynchronous communication controller 8250 to implement asynchronous serial communication.By 8250 the initial programming,you can control serial data transmission format and speed.In the PC,in general there are two standard RS-232C serial interface COM1 and COM21MCS-51 serial micro-controller chip includes a full-duple serial interface,can also be realized by programming the serial communications. CMOS smart sensor IC has received wide application for low cost,miniaturization,intelligence and standardization.In smart sensor IC designs,the communication interface circuits also 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 also has focused on areas of application.RS-485 has a anti-noise capacity transmitting data,so it is commonly used in industrial production.USB interface and IEEE-1394 have fast speed,but some computers and operating systems do not support such interfaces.RS-232C standard is a protocol of asynchronous serial communication and has been widely used in PC and communication industries.Many short distance communicational peripherals of PC such as printers,disks and terminals all communicate with PC via RS232 serial interface. RS-32C standard RS-232C is the American Electronics Industry Association(EIA) formally announced,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 transmission cables up to 15 meters RS-232C standard defines the 25-lead,two-way communication in general,just Serial input RXD,serial output TXD and ground GND1RS-232C standard levels using negative logic,the provisions of +3V+15V at any level between a logic ”1” level,with TTL and CMOS levels are different.In the interface circuit and computer interface chip in the mostly level TTL or CMOS,so the communication,the need for level conversion,so with RS-232C standard level matching 1MAX232 chip level conversion can be done in this work. RS-232 is defined as the single-ended standards,which has much characteristic,such as more communication distance in a low-speed serial communication,moderate price and good practically of the system,so it is most appropriate to be 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 the RS-232 communication port.In order to achieve reliable and realtime transmission,the system adopt a three-wire connection method,that is to say that the GND pin,RXD pin and TXD pin of RS-232 port is connected with the external port,it is shown in Figure 1: Figure 1. The RS-232 port III. THE SOFTWARE DESIGN OF SERIAL PORT COMMUNICATION The communication program of the single chip microcomputer communications with PC computer by interrupt and PC computer is called as main controller.When the single chip computer receives the data singles sent by PC computer,then it calls interrupt service program.The flowchart of the interrupt service main 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 promptly respond to and control objects.The communication program will be optimized.The subprogram of serial port interrupt for receiving data,the subprogram for sending step-by-step impulse,the subprogram for judging instruction and the subprogram foe sending data.A.The subprogram of serial port interrupts for receiving dataThe subprogram of serial port interrupt for receiving data is mainly responsible for receiving data send by PC microcomputer and storing the 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 instructions,and the buffers is large enough to send the computer,so the software shake hands protocol is omit so as to raises the CPU utilization.When the program of serial port interrupt receives the specified data,it exits the serial port interrupt.B.The subprogram of sending the step-by-step impulseUsing counter-timer of the single chip microcomputer time 0,as the fixed times complete,the p1.5 port is negated so as to periodically generate the driving pulses.The time 0 begins to count from initial value which 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 initial value which is send by the PC microcomputer by serial communication.C.The subprograms of judging instruction 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 microcomputer 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 symbol “48”,the serial port interrupt sub-program sets P1.4 higher,then the next five bytes data is used to ensure the step-by-step motor speed and steps.If the first data is a digital symbol “49”,it means that the step-by-step motor reverses,then the single chip microcomputer receives the speed and steps information.Otherwise the single chip microcomputer judges that the received data is not “STOP” instruction,if so,it sends “stop” instruction to the drive system;if not,it quits the interrupt.D.The processing subprogram of send interrupts The processing subprogram of send interrupts is responsible to send data to the computer,sending interrupt state is off in the general.When the communication program completely deals with data with data sent by PC microcomputer,the symbol “1”can be written to send 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 single chip microcomputer and it is set “on” state again after data are sent.So the single chip microcomputer returns to main program and waits for receiving instructions.IV.THE DESIGN OF COMMUNICATION PROGRAM OF PC MICROCOMPUTER AND SINGLE CHIP MICROCOMPUTERIn order to realize the system software easily grafted and uniformity,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 communication 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 components,in which it is relatively simply for VB,VC in this way.The second method is called Windows API(Application Program Interface)function,in which this function is provided by the operating system in order to provide a lot of executive function.This program steps is followed:(1) Setting by communication protocol and opening the serial port,which is called initialization,then blocking the other program to use the serial port.(2) Configuring the serial port.(3) Transmitting data by the serial port to and fro,verifying data during transmission.(4) Closing the serial port as no needing it so that other program uses. 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 to 2400Bps in the computer setting 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 data and instructions successfully.Serial communication program includes two aspects,one is MCS-51 micro-controller communication program,on the other hand for the PC,the communication process.In 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 protocol is agreed as follows:1) The serial communication baud rate is 1200bps.2) The frame format is:a start bit,eight data bits,a programmable ninth bit(this bit is sent and received address/data flag),one stop bit.3) Set the address of the micro-controller code F1H.Contact before sending the data in the address code,such as the address code is the correct transmission of data,or to contact the address code.4) No parity.The communication of data accumulation and verification of the method,that is,each

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论