可以设置16条定时自动发送的数据,以及每条数据发送后的延时时间; 可以同时监控2个串口,利用特制电缆可监听2个串口设备之间的通讯过程; 发送数据时,可自动计算并添加和校验发送;
DTR自动控制是为了方便RS485通讯测试而添加的功能; 方便的查找功能,使你可以轻松搜索接收文本框中的字符; 使用快捷键可快速调用最近五次发送的不同数据。 5.4 结果
通过软件仿真,单片机可以向PC机发送数据,同时接收PC机发来的数据,完全实现了单片机
与PC机之间点对点的通信。由于5.12地震的影响,毕设暂停了一段时间,加之器材室元器件缺少我所需的器件,硬件电的路焊接也就没有完成。
第21页,共37页
6结语
实验表明,此系统完全实现了PC机与单片机之间点对点的通信,方法简单可靠,基本上在需要用到PC机与单片机串行通信的场合均可采用此种方法。随着近年来PC在国内应用范围的日益壮大,在工业控制、数据采集等领域越来越多的采用PC,本文可以算作是一个有益的尝试。当然在实际应用中还需要考虑一些问题,比如进行出错处理的问题,可以在一个要发送的字符串后再发送一个校验和,当收到返回的校验和与发送的校验和不一致时再进行重发,再比如所采用的RS232C传输距离很短,并且抗干扰能力很差,这时需要将总线转换成差分传输的RS485/RS422。另外,稍加改进,就可实现PC机与多片51单片机的串行通信,这时由于共用一条总线,必须给每个单片机分配一个地址,然后由PC机对总线进行仲裁,只有获得总线使用权的单片机才能与上位机进行通信,这里不再赘述。
总之,本文只是为PC和单片机串行通信提供了一个典型的范例,要应用到实际的项目中去,还需要根据实际的情况具体考虑,灵活应用,最终才能形成一个可靠的基于PC与单片机的串行通信系统。
第22页,共37页
参考文献
[1]王福瑞.单片微机测控系统设计大全[M].北京:北京航空航天大学出版社,1998.06 [2]李华.MCS一51系列单片机实用接口技术[M].北京:北京航空航天大学出版社,1993.07 [3]李朝青.PC机与单片机&DSP数据通信技术选编(1)[M].北京:北京航空航天大学出版社,2003.12
[4]刘金伍.单片机应用与实践[M].北京:北京航空航天大学出版社,1995.08 [5]刘大茂.智能仪器:单片机应用系统设计[M].北京:机械工业出版社,1998.04
[6]万福君,潘松峰.单片微机原理系统设计与应用[M].合肥:中国科学技术大学出版社,2001.01 [7][美]安格斯生.串行端口大全[M].精英科技译.北京:中国电力出版社,2001.01
第23页,共37页
附录A 英文资料
Linux PC and 51 series monolithic integrated circuit serial communication design Abstract: Introduced one kind uses Linux operating system PC machine carries on the correspondence through the serial port and the MCS-51 series monolithic integrated circuit the design method, has given the basic hardware principle and the signal procedure design 2 methods. The experiment proved that, this kind of plan simple reliable, the price is inexpensive, was Linux in domain and so on in industry control applications has provided one solution.
Key word: Linux; Monolithic integrated circuit; Serial communication; Industry control.
The monolithic integrated circuit performance stable, the price inexpensive, the function is formidable, in the intelligent instrument, industry equipment as well as in the everyday use electronic consumable obtained the more and more widespread application. In the monolithic integrated circuit input output control, except directly joins small methods and so on outside keyboard and LCD display monitor, generally all and on position machine PC carries on the correspondence through the serial port, but latter method because can realize the long-distance control, and can use the PC machine formidable data processing function as well as the friendly control interface, appears especially importantly. Carries on the control in general use PC machine to the monolithic integrated circuit the situation, all is uses Windows to take on the position machine platform, its merit is the contact surface is friendly, the programming and the operation quite is all easy, the shortcoming is the stability too is bad, this regarding needs the installment which the consecutive number day or several months move, is especially inappropriate. In the request quite harsh situation, all uses the UNIX workstation to take the master control platform generally, if the Hefei synchronization radiation accelerator master control platform uses is the SUN Solaris workstation system, however the UNIX workstation expensive price has limited its use scope greatly. In recent years, along with the Linux swift and violent development, caused it gradually to turn the mainstream operating system from small number of people's toy. Linux is follows the GPL agreement the free source code opening software, anybody all may free obtain its source program from Internet, also may revise its source code under the GPL agreement to adapt the specific application, its movement on ordinary PC, the performance is stable, is suitable for to make the industry control specially, therefore realizes Linux and the monolithic integrated circuit serial communication has the significance extremely, he may be the substitution method which the expensive UNIX workstation one kind may elect. 1 hardware principle
At present the domestic use many is the MCS-51 series monolithic integrated circuit, therefore selects the monolithic integrated circuit experiment object is piece of AT89C51, Figure 1 is the hardware schematic diagram, because must realize conforms to the RS232C serial communication, but also should use one piece ICL232CPE(MAX232) to take the serial communication the level switching circuit. In
第24页,共37页
experimental process, in order to examine corresponds whether succeeds, besides lets the monolithic integrated circuit return to on position machine delivers the data, but also expanded several piece of latches in the monolithic integrated circuit periphery, several LED light emitter diode and several small keyboards. The serial communication uses the simple TxD, RxD, GND three-wire system connection, pays attention to TxD and RxD nearby two should the overlapping segment.
On the position machine is ordinary PC machine, altogether has 2 serial port COM1, COM2, it moves RedHat8.0, in fact, if does not request to move graphical interfaces and so on Gnome or KDE, Linux is quite low to the system hardware request.
The experiment proved that, this electric circuit simple reliable, is suitable extremely for the test serial communication.
2 serial communication programming
Serial communication procedure including lower position machine monolithic integrated circuit and on position machine PC machine procedure. The monolithic integrated circuit receives the data which the position machine transmits, puts to internal RAM inside, again the data simultaneously transmits RAM in to exterior expansion latch and on the position machine, from this may judge corresponds whether succeeds. This procedure wrote by the assembly language, when initialization the baudrate establishment is 4 800 b/s, the mailing address is 8-N-1.
On the position machine procedure compilation is the essential part, because must carry on the operation to the serial port hardware equipment, some 2 methods, one are use Linux essence bringing the serial port driver, moreover one method is the direct read-write serial port hardware port, below introduced separately. 2.1 use serial port driver programming method
Carries on the programming using the Linux own serial port driver, in fact is transfers the driver a series of functions, completes the serial port correspondence parameter the establishment, the data transmission and the receive. In this method, Linux all assigns a document index number for each serial port, has the corresponding document name, in fact is regards as the hardware equipment one kind of special document, like COM1, COM2 correspondence document respectively be/dev/ttyS0,/dev/ttyS1, operates these 2 serial ports in fact operates these 2 documents, but with does not certainly have to the hardware equipment document operation to the ordinary document operation what differently, all may use same document I/The O transfer function (open, write, read, close), the similarity lies in with system call open() opens the serial port obtains after the corresponding equipment document description symbol, first must to it carry on the initialization, establishes some specific parameters, like baudrate, The data position, the input output way and so on, these parameters deposit in structtermios, function tcsetattr() may establish the serial port structtermios, tcgetattr() to be possible to obtain serial port struct termios. After established the correspondence parameter carries on read-write on available read and write to the serial port document. When operating procedure must pay attention to the user whether has to the serial port document which
第25页,共37页