教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 实用模板 >

单片机与PC机串口通信的设计(9)

来源:网络收集 时间:2026-07-17
导读: must operate carries on the read-write authority, may use chmod to order to carry on the document jurisdiction revision. It initialization function is as follows: The initialization will later start

must operate carries on the read-write authority, may use chmod to order to carry on the document jurisdiction revision.

It initialization function is as follows:

The initialization will later start to transmit and to receive the data, first for a string of character transmission the monolithic integrated circuit, after the monolithic integrated circuit receives the data, will give the data returns the position machine. But needs to pay attention, because on the position machine speed is much quicker than the monolithic integrated circuit, a time cannot transmit excessively many data, otherwise will have the possibility to cause extremely to transmit the buffer overflow to lose the data, the transmission from now on, but also will have to wait for period of time, will cause the monolithic integrated circuit to transmit completely the data after on position machine, then will carry on the read. 2.2 direct read-write serial port hardware port method

Is using this method time, must have some understandings to the serial port correspondence hardware principle. The PC machine serial port is by general asynchronous transceiver 8250UART (or 16550) is the core constitution, the register base address respectively is 0x3f8(COM1) and 0x2f8(COM2), but also has the register which other some use in controlling. Has very many registers is with the Modem correlation, but carries on the correspondence when the use three-wire system with, only uses the care and the correspondence related register, compares the use to come for the general function compilation serial port equipment driver, the direct read-write correlation register efficiency is higher.

After the initialization, might carry on the data receiving and dispatching, accepted in front of the data had to guarantee the receive data ready, this might judge through 0x2fd D0, transmitted in front of the data must guarantee transmission register for spatial, this might judge through 0x2fd D5, the code was as follows: 3 conclusions

The experiment indicated, this system uses 2 methods all completely have realized between LinuxPC machine and the monolithic integrated circuit the point-to-point correspondence, the method simple reliable, basically in need to use PC machine and the monolithic integrated circuit serial communication situation may use this method. Along with recent years Linux in the domestic application scope daily strength, in domains and so on industry control, data acquisition also will certainly more and more many use Linux, this article to be possible to calculate did is a beneficial attempt. Certainly in the practical application also needs to consider some questions, for instance carry on make a mistake the processing question, may again transmit a verification after the string of character which must transmit and, when receives the returns the verification and with the transmission verification and inconsistent again carries on the reproduction, again for instance uses the RS232C transmitting range is very short, and antijamming ability is very bad, by now needed to transform the main line the difference transmission RS485/RS422。 Moreover, improves slightly, may realize PC machine with the multi-piece 51 monolithic integrated circuit serial communications,

第26页,共37页

because by now used in common a main line, had to give each monolithic integrated circuit to assign an address, then carried on the arbitration by PC machine to the main line, only then obtained the main line right of use the monolithic integrated circuit to be able to carry on the correspondence with on position machine, here no longer gave unnecessary detail.

In brief, this article only was Linux PC and the monolithic integrated circuit serial communication has provided a typical model, had to apply in the actual project, but also needed according to the actual situation concrete consideration, the nimble application, finally to be able to form one reliably based on the Linux platform system.

第27页,共37页

附录B 中文翻译

Linux PC和51系列单片机串行通信的设计

摘 要:介绍了一种采用Linux操作系统的PC机通过串口和MCS-51系列单片机进行通信的设计方法,给出了基本的硬件原理和通信程序设计的2种方法。实验证明,这种方案简单可靠、价格低廉,为Linux在工业控制等领域中的应用提供了一种解决方法。 关键词:Linux;单片机;串行通信;工业控制

单片机性能稳定、价格低廉、功能强大,在智能仪器、工业装备以及日用电子消费品中得到了越来越广泛的应用。在单片机的输入输出控制中,除直接接上小键盘和LCD显示屏等方法外,一般都通过串口和上位机PC进行通信,而后一种方法由于能实现远程控制,并且能够利用PC机强大的数据处理功能以及友好的控制界面,显得尤为重要。在一般的利用PC机对单片机进行控制的场合,都是采用Windows作为上位机的平台,其优点是界面友好,编程和操作都比较容易,缺点是稳定性太差,这对于需要连续数天或数月运行的装置来说,尤其不合适。在要求比较苛刻的场合,一般都采用UNIX工作站作为主控平台,如合肥同步辐射加速器的主控平台采用的是SUN的Solaris工作站系统,然而UNIX工作站昂贵的价格又大大限制了其使用的范围。近年来,随着Linux的迅猛发展,使其逐渐从少数人的玩具变成了主流的操作系统。Linux是遵循GPL协议的免费源代码开放软件,任何人都可以自由的从Internet上取得其源程序,也可在GPL的协议下修改其源代码以适应特定的应用,其运行在普通的PC上,性能稳定,特别适于做工业控制,因此实现Linux和单片机的串行通信非常有意义,他可以是昂贵的UNIX工作站的一种可选的替代方法。 1 硬件原理

目前国内使用较多的为MCS-51系列的单片机,因此选用的单片机实验对象为一片AT89C51,图1是硬件原理图,由于要实现符合RS232C的串行通信,还应该用一片ICL232CPE(MAX232)作为串行通信的电平转换电路。在实验过程中,为了查看通信是否成功,除了让单片机对上位机回送数据外,还在单片机外围扩展了几片锁存器,几个LED发光二极管和几个小键盘。串行通信是采用最简单的TxD,RxD,GND三线制连接,注意TxD和RxD两边应该交叉连线。

上位机是一台普通的PC机,共有2个串行口COM1,COM2,其运行RedHat8.0,实际上,如果不要求运行Gnome或KDE等图形界面,Linux对系统硬件的要求相 …… 此处隐藏:3466字,全部文档内容请下载后查看。喜欢就下载吧 ……

单片机与PC机串口通信的设计(9).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/520285.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)