欢迎来到三一文库! | 帮助中心 三一文库31doc.com 一个上传文档投稿赚钱的网站
三一文库
全部分类
  • 研究报告>
  • 工作总结>
  • 合同范本>
  • 心得体会>
  • 工作报告>
  • 党团相关>
  • 幼儿/小学教育>
  • 高等教育>
  • 经济/贸易/财会>
  • 建筑/环境>
  • 金融/证券>
  • 医学/心理学>
  • ImageVerifierCode 换一换
    首页 三一文库 > 资源分类 > DOC文档下载  

    《毕业论文:基于Visual_Basic的计算机与单片机串口通信研究》.doc

    • 资源ID:8793661       资源大小:156KB        全文页数:12页
    • 资源格式: DOC        下载积分:4
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录 QQ登录   微博登录  
    二维码
    微信扫一扫登录
    下载资源需要4
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    《毕业论文:基于Visual_Basic的计算机与单片机串口通信研究》.doc

    SelectionParagraphFormatLineSpacingLinesToPointsSelectionParagraphFormatLineSpacingLinesToPointselectionParagraaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaphFormatLineSpacingLinesToPointsSelectionParagraphFormatLineSpacingLinesTSelectionParbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbagraphFoLineSpacingLinesToPointsSelectionParagraphFormatLineSpacingLinesToPointse11111111111111111111111111111111lectionParagraphFormatLineSpacingLinesToPointsSelectionParagraphFormatLineSpacingLinesToPoctionParagraphFormatLineSpaci2222222222222222222222ngLinesToPoints2SelectionParagraphFormatLineSpacingLinesToPointsSelectionParagraphFormatLineSpacingLinesToPointselectionParagraphFccccccccccccccccccccccccccccccccccccccccccccccccccccccccormatLineSpacingLinesToPointsSelectionParagraphFormatLineSpacingLinesToPoctionParagraSelec摘要:本文研究了计算机与单片机串口通信的实现方法。详细介绍了在Windows环境下用Visual Basic 6.0中的MSComm通讯控件实现计算机与单片机串行通信的编程方法。最后,利用MCS-51单片机的数字时钟,通过Visual Basic语言编写上位机程序,在PC机终端上显示当前时间。关键词: 单片机,串行通信,通信控件,Visual Basic 6.0Study on the Serial Communication of Computer and Single-Chip Microcomputer on Visual BasicCheng Lai Xing, Zhang Ying Bo(Huang Shi Polytechnic School, Hebei Huangshi, 435003)Abstract: The serial communication method of the computer and Single-Chip Microcomputer is researched. The programming method of the serial communication method of the computer and Single-Chip Microcomputer is described in detail by MSComm communication control button of Visual Basic 6.0 in the Windows environment. Finally, by the number of Single-Chip Microcomputer Clock, the current time of the Single-Chip Microcomputer Clock is displayed in the PC terminal using Visual Basic language programming.Key words: Single-Chip Microcomputer; Serial Communication; Communication Control; Visual Basic 6.01 前言随着计算机的迅速普及和计算机控制技术的发展,计算机被广泛应用于自动化控制领域之中。完成一个控制过程一般都要利用集散式计算机控制系统。在这种控制系统中,下位机主要完成对现场数据采集和对设备一级的监控,上位机则要完成对整个系统的采集、分析、处理和控制以及数据、图形显示、打印、人机对话等工作。上位机与下位机大多是通过PC机的RS-232串行接口实现通信。随着Windows系统的普及,使得数据采集及工业控制软件也上升到了Windows环境下。这就给程序员提出了如何编写面向Windows的串行通信程序问题。Visual Basic 6.0(以下简称VB)是一个Windows下简单易学、高效的可视化软件开发平台,VB不但提供了良好的界面设计能力,而且在串口通信方面也有很强的功能。它提供的Microsoft Communication control(简称MSComm)通信控件,“隐藏”了大部分串口通信的低层运行过程和许多繁琐的过程,它使用户能够方便地访问Windows下串口通信驱动程序的大多数特性。所以整个串行通信程序的开发过程变得十分简单易行,程序员不需要处理繁琐的细节,利用该通信控件,只需编写少量的代码就可实现主要应用功能和界面的设计,完成软件的开发过程。2 基于Visual Basic的串口通信实现方法通信就是两个设备之间的数据交换,是通过电信号来实现的。计算机工具箱和窗体上的MSComm控件是Microsoft公司提供的主要用于串行通信编程的ActiveX控件。如果通过C、VC+编写串口通信程序,那么就要使用API函数发送和接收数据。而VB6.0中的MSComm控件实际上是这些Windows API函数的有机集成,它以属性和事件的形式提供了对Windows通信驱动程序的API接口,封装了API函数的低层操作,为应用程序提供了通过串行接口收发数据的简便方法1。因此,编程人员只需在程序中设置和监视MSComm控件的属性和事件即可完成对串口的编程。MSComm控件不在最常用的控件工具箱中出现,故编程的第一步应添加到工具栏上以方便编程。具体的做法如下:单击VB6.0菜单栏中的“工程”菜单,并选择“部件”命令,则弹出如图1所示的对话框。在部件对话框中选择Microsoft Comm Control 6.0,在所需要控件前面的复选框上单击,使复选框中出现“”符号,说明已经选中此控件。单击“确定”,则响应控件就加载进内存,此时工具箱应出现一个电话图表,这就是MSComm图标,如图2所示。MSComm控件通过串行端口传输和接收数据,为应用程序提供串行通信功能。MSComm控件提供下列两种处理通信的方式:事件查询方式和事件驱动方式。图1 部件对话框 图2 工具栏中的通信控件3 单片机与计算机串口通信的实例研究单片机与计算机串口通信的实例:“MCS-51单片机的数字时钟在计算机上的显示过程”。借助MSComm控件,利用Visual Basic语言编写出上位机程序在PC机终端上显示单片机数字时钟的当前时间。在Visual Basic界面窗口上绘制指针表盘,将单片机串口时间在指针表盘上显示出来,实现计算机与单片机之间的串口通信。3.1 下位机(单片机)数字显示模块的设计初始化串口包括设置串行口的工作方式。根据通信要求设置串行口工作方式为1,SCON=0x50。定时器0和1都工作在方式2,TMOD=0x22。通过定时器1控制串行口中断。在串行口工作方式1,定时器1工作在方式2,其波特率式子:波特率=(2SMOD/32)*(fosc/12)/(256-TL1)写入时间常数TH1=0xf3,TL1=0xf3来设置波特率,定时器0也工作在方式2,设置初值为TH0=0xce,TL0=0xce,因此每100s产生一次中断,产生10000次中断秒针值加一。根据中断优先级,定时器中断优先于串行口中断。图3 单片机数字钟显示程序框图图4 单片机数字钟显示原理图3.2 上位机(PC机)界面设计及编程(1) 创建应用程序界面建造Visual Basic的应用程序的第一步是创建窗体,然后在创建的窗体上绘制构成界面的图像。窗体对象是VB应用程序的基本构造模块,是运行运用程序时与用户交互操作的实际窗口。窗体有自己的属性,事件和方法用于控制其外观和行为2,3。在VisualBasic6.0环境下设置通信窗口显示窗体用鼠标单击桌面任务栏中的“开始”按钮,再单击“程序”,将鼠标移动到“Microsoft Visual Basic6.0中文版”上,会出现一个子菜单,然后单击“Microsoft Visual Basic6.0中文版”,即可启动Visual Basic6.0。在“文件”菜单中,单击“新建工程”命令,屏幕上出现一个“新建工程”对话框,如图5所示。在该对话框中选择“标准EXE”,然后单击“确定”按钮,这时Visual Basic6.0集成开发环境将创建一个名为“工程1”的工程容器窗口,并在窗体设计器中自动创建一个名为“Form1”的窗体文件,这样就创建了一个标准的32位Visual Basic应用程序,Visual Basic为新建工程清除版面,并在屏幕中央显示空白窗体用于构造用户界面。Visual Basic6.0的集成开发环境如图6所示。图5 新建工程对话框 图6 VisualBasic6.0的集成开发环境单击工具箱中的命令按钮(Command Button),把鼠标指针移动到窗体上,选中命令按钮控件之后,当鼠标指针位于窗体上时,它变为十字形状,十字光标用于绘出命令按钮的矩形外框,当按下鼠标左键并拖拽鼠标时,命令按钮对象就使用矩形框的大小并调整到网格位置。按照此步骤,取出4个命令按钮,并分别设置好其属性,分别设置Caption属性依次为打开端口、关闭端口、推算日期、结束。绘制表盘:单击工具箱中的Shape按钮,然后把鼠标指针移动到窗体上,选中命令按钮控件之后,当鼠标指针位于窗体上时,它变为十字形状,十字光标用于绘出矩形外框,当按下鼠标左键并拖拽鼠标时,矩形框的大小可调整到网格位置,并在属性窗口中,将Shape的属性设置为3-Circle,这样在窗口中就出现了圆形框,框的大小可以通过属性栏中的位置属性来确定。将它作为表盘使用,表盘的外观可以通过属性来设置。指针的绘制:单击工具箱中的Line按钮,然后把鼠标指针移动到窗体上,选中命令按钮控件之后,当鼠标指针位于窗体上时,它变为十字形状,这时在窗体上的表盘圆点处按下鼠标左键,拖拽鼠标,根据自己的需要确定线的长度,在属性窗口中将线的名称改为LineH,作为时针来使用,也可以根据需要设置线的颜色和线的宽度,同理可以确定分针LineM,秒针LineS,这样我们就绘制好了一个表盘。在工具栏中添加串口通信控件MSComm,用鼠标左键点击工具栏中串口通信控件MSComm,当鼠标指针位于窗体上时,它变为十字形状,十字光标用于绘出串口通信控件的矩形外框,当按下鼠标左键并拖拽鼠标时,松开左键,窗体中就出现了MSComm的图标,根据通信协议,设置好MSComm的属性。添加Timer时间控件:按照上述同样方法在窗口中添加好时间控件。然后将Timer的Enabled的属性设置为True。在VB界面窗口中设计界面背景,可根据自己的喜好选取图片,将图片复制后,回到VB对象窗口,右键点击窗口Form,点击粘贴即可,我们可以根据自己的需要设计出各种背景。按照以上步骤设置好的窗口界面如下图7所示。图7 设置好的窗口界面(2) 编写代码并运行运用程序代码将该应用程序所需要的所有内容都设计完毕,把这些内容连接起来,就形成一个可用的应用程序。3.3 设计程序该设计中重点是要将下位机指令添加到上位机表盘指针显示模块中,进而通过VB程序调用单片机中的数字钟显示。指针的指示值对应数字钟的时间,通过下面的方法对VB界面进行完善5:(1)首先在程序代码窗口声明各变量类型。(2)对窗口中各个控件设置程序代码,鼠标左键双击窗体中的“结束”按钮,在程序窗口出现标记程序段的开始与结束语句之间,加入End语句做为过程体。(3)鼠标左键双击对象窗口中“打开端口”命令按钮,窗口跳转到代码窗口,显示符出现在新的标记程序段的开始与结束语句之间,在该过程体中加入MSComm1.PortOpen =True,在“关闭端口”对应的代码窗口中的过程体之间加入MSComm1.PortOpen =False代码语句。(4)鼠标左键双击对象窗口中“推算日期”命令按钮,窗口跳转到代码窗口,显示符出现在新的标记程序段的开始与结束语句之间,在该过程体中加入调用时钟Timer及Data语句,声明该程序段中要涉及到的变量类型,让后输入Print语句,通过数学推算语句来计算日期。(5)绘制指针语句同样是根据物理中的坐标变量及平行四边形定则理论,来确定指针长度。(6)时间程序代码1中,为使第一个表盘指针显示串口输入时间,在该过程体中应该线定义一个数组变量,将串行口输入的时钟、分钟和秒钟时间分别存到数组中,然后将数组中的各个变量对应的赋给表盘的时分秒指针。(7)时间程序代码2中,为使第二个表盘指针显示当前的时钟值,同样将时钟的小时、分钟、秒钟的时间赋给表盘指针,按照上述(6)的原理,使得指针旋转。4 结束语VB6.0具有良好的图形接口并支持面向对象的编程方法和具有结构化的事件驱动编程模式,采用VB6.0编写程序,短时间内就可以设计出交互界面友好、功能易扩展的程序。本文对Windows环境下通过VB6.0程序使用MSComm串行通信ActiveX控件进行编程的方法进行了探讨和实践。VB6.0的通信控件功能强大、编程简单,使得Windows环境下的串口通讯程序设计变得方便易行。该设计原理还适用于下位机的温度显示系统、IE的控制、机场空域飞行冲突的模拟和学校机房U盘实时监控等。参考文献1 李长林. Visual Basic串口通信技术与典型实例M (第1版). 北京: 清华大学出版社, 2006.4:1282 闫金玉. 浅析VB应用程序中如何进行界面设计J. 甘肃科技纵横, 2007,(04)3 王强, 苑秉成, 席再杰. 基于中断方式的PC机与单片机串口通信的实现J. 舰船电子工程, 2008,(10)4 李跃纲. VB界面设计方法与技巧J. 电子与电脑, 2000,(02)5 张筠莉, 刘书智. Visual C+实践与提高-串口通信与工程应用篇M. 北京:中国铁道出版社, 2005.11:2245作者简介:程来星(1964),湖北武穴人,高级讲师,黄石职业技术学院科研处处长。Opinions and suggestions on the partys mass line educational practiceAccording to the central and provincial, municipal unified deployment, according to municipal Party committee "about carrying out the partys mass line educational practice activity in the citys implementation opinions, the spirit of the partys mass line educational practice activities from 20* in January to 99 months, carried out at all levels of departments and directly affiliated institutions and grass-roots party organizations. According to my actual County, the county to carry out the education practice put forward the following implementation opinions.First, the overall requirementsCounty county education practice to the eighteen Party of eight, the spirit of the the third Plenary Session of the 18th CPC Central Committee as the guidance, conscientiously implement the spirit of general secretary Xi Jinping book series of important speech, earnestly implement the Central Committee really, opinions and advice > < < >, < party implementing the guiding ideology of opinions to determine the objectives and requirements, step method, in accordance with the "" look in the mirror, dress up, wash bath, cure treatment, the general requirements of "for the people pragmatic honest people as the theme, in carrying forward the spirit of Zhuanglang Zhuang, improve their work style, service to the masses of the people, the foundation of consolidating grassroots, promote transformation across efforts, to further implement the central eight regulations and < The opposition party and government austerity waste regulations "," double section "provincial regulations, municipal provisions of the" twelve "plan and the implementation measures for < on improving the work style of close ties with the masses law, highlight style building, carry out the whole wind spirit, resolutely oppose formalism, bureaucracy, hedonism and wasteful extravagance to solve the problems, Party members and cadres of the style and the masses of people strong, the Ministry of Party members and cadres to further improve their thinking and understanding, to further change the style of the wind, the masses to close, honest and pragmatic people honest image to further establish the foundation to further reinforce the basic level. Style of the building of the new results to promote the construction of a powerful force of the county and the ecological culture of the county and county construction.In educational practice activities of the unit is mainly: the county and below county departments under the organs, enterprises and institutions directly under the township, street, and community, village, non-public economic organizations, social organizations and other grass-roots organizations. Agencies and branches, each single unit, follow the rules on internal institutions. Educational practice with step by step.To adhere to the county leadership, leadership and leading cadres to focus on outstanding catch to directly contact the service of the masses of law supervision departments and window units, service industry, educational practice, pay attention to grasp the heavy towns, streets and villages, community education activities and the masses of grassroots groups in close contact to strengthen, and the majority of Party members, cadres and the mass line line Marx doctrine view of the masses and the partys education.Always speak seriously as a basic attitude, adhere to positive education, to carry out criticism and self criticism group, adhere to the pragmatic, more emphasis on leadership, pay more attention to the layers of the demonstration, more focus on the four winds, solve the problem, pay more attention to open the door, the participation of the masses, pay more attention to the classification guidance. Orderly, pay more attention to the cooperation and cohesion driven, more strict requirements on injection, really supervision practice, ensure education practice is not empty is not empty is not partial, not as a mere formality.Two, the key point of the taskThe main task of the countys education practice is to seize against "four wind" this focus on centralized solve outstanding problems asked County, township leadership and leading cadres of the four winds, the disadvantages of the style, scale behavior to a large scale investigation, overhaul, cleaning greatly. At the same time, respond to the concerns of the masses, safeguard the interests of the masses, pay attention to solve practical problems, solve the people around the unwholesome tendencies especially on eat, take the card, Yong lazy luxury, extravagance and waste fees, privileges and other issues, timely and effective, without any discount to solve, to improve the style of real implementation of the requirements of real to the grassroots, real let group Benefit the public.(a) focus on solving the "four winds" outstanding issuesThe central and provincial requirements, the county leadership and leading cadres of key performance concept is not correct, do not dare to play, to engage in "image project", "political project", a leadership guide, a set of ideas, orders and prohibitions, and a policy, there are countermeasures county. The units directly under the heavy focus on solving Yung lazy drag, buck passing skin, work is not implemented, the service is not active. The dynamic problem of law enforcement and supervision departments and window units, service industry mainly solve the door hard, ugly face, something difficult, and arbitrary charges, fines, levies, and breach of privilege, chinakayao, not the problem of law. The township, street The collar of leading bodies and leading cadres to solve key does nottheir own conditions to develop the correct road, the maximum to avoid investment risk, gain profit.(three) vigorously promote the brand. To establish brand awareness, awareness of the use of brand, brand value, brand acquisition performance, enhance the competitive strength. Concentrated manpower, careful planning, packaging and publicity of a number of unique, market influence and coverage of the brand, the implementation of key breakthroughs, to enhance the competitive strength, walking business road the competition of alienation and characteristics, the pursuit of stability and development of the market.(four) to promote the integration of resources. To further broaden their horizons, effective integration of resources within the group, the city resources, other industries and regional resources, mutual trust, mutual benefit, seeking win-win principle, in the framework of national policies and regulations, strict inspection and argumentation, legal consultation, examination and approval procedures, strict regulation of economic activities, attract injection the social investment to the industry group, to achieve leveraging the development, ensure that the value of state-owned assets.(five) to strengthen the construction management personnel. Strengthen the management of education and training of cadres and workers of the existing business, firmly establish the concept of the market, enhance the sense of crisis to adapt to market competition, the sense of urgency, improve the ability to respond to market competition, improve management and operation of the market. At the same time, according to the need of industrial development, vigorously the introduction of high-quality management management personnel, and strive to build a high-quality professional management team, hard work, and promote the entire workforce knowledge structure, age structure, structure optimization and upgrading ability, enhance core competitiveness, adapt to the need of market competition.(six) seriously study the policy for policy. Serious research about social support the development of cultural undertakings in the country and the XX policy, especially the policy of industrial development, financial investment policy, financial policy and tax policy, and actively seek policy, projects and funds, enterprise and industry group mission to promote leapfrog development.SelectionParagraphFormatLineSpacingLinesToPointsSelectionParagraphFormatLineSpacingLinesToPointselectionParagraaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaphFormatLineSpacingLinesToPointsSelectionParagraphFormatLineSpacingLinesTSelectionParbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbagraphFoLineSpacingLinesToPointsSelectionParagraphFormatLineSpacingLinesToPointse11111111111111111111111111111111lectionParagraphFormatLineSpacingLinesToPointsSelectionParagraphFormatLineSpacingLinesToPoctionParagraphFormatLineSpaci

    注意事项

    本文(《毕业论文:基于Visual_Basic的计算机与单片机串口通信研究》.doc)为本站会员(rrsccc)主动上传,三一文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一文库(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    经营许可证编号:宁ICP备18001539号-1

    三一文库
    收起
    展开