基于单片机的多功能智能小车设计毕业论文

合集下载

基于51单片机的智能车毕业设计(论文)

基于51单片机的智能车毕业设计(论文)

基于80C51的电动智能单片机摘要80C51单片机是一款八位单片机,它的易用性和多功能性受到了广大使用者的好评。

这里介绍的是如何用80C51单片机来实现长春工业大学的毕业设计,该设计是结合科研项目而确定的设计类课题。

本系统以设计题目的要求为目的,采用80C51单片机为控制核心,利用超声波传感器检测道路上的障碍,控制电动小汽车的自动避障,快慢速行驶,以及自动停车,并可以自动记录时间、里程和速度,自动寻迹和寻光功能。

整个系统的电路结构简单,可靠性能高。

实验测试结果满足要求,本文着重介绍了该系统的硬件设计方法及测试结果分析。

采用的技术主要有:(1)通过编程来控制小车的速度;(2)传感器的有效应用;(3)新型显示芯片的采用.关键词80C51单片机、智能、光电检测器、PWM调速、电动小车Design and create an intelligence electricity motive small carAbstract80C51 is a 8 bit single chip computer. Its easily using and multi-function suffer large users. This article introduces the CCUT graduation design with the 80C51 single chip computer. This design combines with scientific research object. This system regards the request of the topic, adopting 80C51 for controlling core, super sonic sensor for test the hinder. It can run in a high and a low speed or stop automatically. It also can record the time, distance and the speed or searching light and mark automatically the electric circuit construction of whole system is simple, the function is dependable. Experiment test result satisfy the request, this text emphasizes introduced the hardware system designs and the result analyze.The adoption of technique as:(1)Reduce the speed by program the engine;(2)Efficient application of the sensor;(3)The adoption of the new display chip.Keywords 80C51 single chip computer, light electricity detector, PWM speed adjusting, Electricity motive small car目录第一章前言 (1)第二章方案设计与论证 (3)一直流调速系统 (3)二检测系统 (4)三显示电路 (9)四系统原理图 (9)第三章硬件设计 (10)一 80C51单片机硬件结构 (10)二最小应用系统设计 (11)三前向通道设计 (12)四后向通道设计 (15)五显示电路设计 (17)第四章软件设计 (20)一主程序设计 (20)二显示子程序设计 (24)三避障子程序设计 (25)四软件抗干扰技术 (26)五“看门狗”技术 (28)六可编程逻辑器件 (29)第五章测试数据、测试结果分析及结论 (30)致谢 (31)参考文献 (32)附录A 程序清单 (33)附录B 硬件原理图 (41)第一章前言随着汽车工业的迅速发展,关于汽车的研究也就越来越受人关注。

智能小车优秀毕业论文

智能小车优秀毕业论文

智能小车优秀毕业论文编号本科生毕业设计基于单片机的智能小车设计The Design of Intelligent Vehicle Based on MCU 学生姓名xxx专业自动化学号xxx指导教师xxx学院电子信息工程二〇一三年六月毕业设计原创承诺书1.本人承诺:所呈交的毕业设计(论文)《基于单片机的智能小车设计》,是认真学习理解学校的《长春理工大学本科毕业设计(论文)工作条例》后,在教师的指导下,保质保量独立地完成了任务书中规定的内容,不弄虚作假,不抄袭别人的工作内容。

2.本人在毕业设计(论文)中引用他人的观点和研究成果,均在文中加以注释或以参考文献形式列出,对本文的研究工作做出重要贡献的个人和集体均已在文中注明。

3.在毕业设计(论文)中对侵犯任何方面知识产权的行为,由本人承担相应的法律责任。

4.本人完全了解学校关于保存、使用毕业设计(论文)的规定,即:按照学校要求提交论文和相关材料的印刷本和电子版本;同意学校保留毕业设计(论文)的复印件和电子版本,允许被查阅和借阅;学校可以采用影印、缩印或其他复制手段保存毕业设计(论文),可以公布其中的全部或部分内容。

以上承诺的法律结果将完全由本人承担!作者签名:• 年•• 月• 日摘要随着我国高科技水平的不断提高和工业自动化进程的不断推进,智能车被广泛应用于各种玩具和其他产品的设计中,极大地丰富了人们的生活。

本文基于ATmega16 单片机设计了一种智能循迹避障小车,由电源模块、红外传感器模块、电机驱动模块、调试模块和MCU模块组成。

利用红外对管和超声波检测黑线与障碍物,当左边的红外对管检测到黑线时,小车往左边偏转,右边的红外对管检测到黑线时,小车往右边偏转。

以ATmega16单片机为控制芯片控制电动小车的速度及转向,从而实现自动循迹避障的功能。

其中小车驱动由L298N驱动电路完成,速度由单片机控制。

关键词:智能小车单片机自动循迹避障AbstractWith the increasing levels of high-tech and industrial automation process progresses, the intelligent vehicle is widely used to all kinds of toys and another production’s devise. It is greatly enriched the life of the people.Based on ATmega16 microcontroller,this paper is about a design of intelligent tracking-avoidance car, which is consist of the power supply module, infrared sensor module, the motor drive module, debug module and the MCU modules. Using infrared and ultrasonic testing on the tube black line and the obstacle, when left on the tube detects infrared black line, the car deflected to the left, the right of infrared tube black line is detected, the car to the right deflection. ATmega16 microcontroller for the control chip to control the speed and steering electric car, enabling automatic tracking avoidance function. Which car is driven by L298N driver circuit completed, the speed controlled by the MCU.Keywords: Intelligent Vehicle; MCU;automatic tracking; obstacle avoidance目录摘要 (I)ABSTRACT (II)目录 (III)第1章绪论 (1)1.1引言 (1)1.2课题研究目的及意义 (1)1.3课题研究现状及发展趋势 (2)1.4本文的主要工作 (3)第2章小车的总体方案设计 (4)2.1设计思路 (4)2.2小车循迹避障传感器的选型 (6)2.3小车循迹避障设计方案 (8)第3章小车的硬件电路设计 (10)3.1单片机的选型 (10)3.2小车的硬件电路设计 (14)第4章小车的软件设计 (19)4.1主程序设计及流程图 (19)4.2避障子程序设计及流程图 (20)4.3循迹子程序设计及流程图 (21)结论 (22)参考文献 (23)致谢 (24)附录1 系统电路图 (24)附录2 智能循迹壁障小车完整程序 (27)第1章绪论1.1引言智能,在科技高速发展的今天,已成为一个引领时尚前沿的代名词,智能手机,智能机器人等等已经在工业,军事中得到广泛的作用,在不为人们所熟知的领域,如深海探测,航空航天,地质勘探,智能也发挥着举足轻重的作用[1]。

基于单片机的智能小车的设计毕业论文总

基于单片机的智能小车的设计毕业论文总

基于单片机的智能小车的设计-毕业论文-总————————————————————————————————作者:————————————————————————————————日期:基于单片机的智能小车的设计摘要单片机作为一种微型控制器,自走入人们的视野以来,就随着科技进步不断地更新换代。

它能够将计算机所有关键的零件整合集中在一块芯片上,并且具有强大的计数功能,以及各种必要的接口,因此单片机在自动控制系统中通常处于核心地位。

本文对于智能小车的设计思路就应用了最常见的AT89S51单片机作控制处理器,该单片机在低功率的基础上,能够保持其性能在一个较高的水平上,且其8K的处理器够灵巧,适用于嵌入式产品,在众多单片机中,表现较为优秀。

本设计是在单片机的基础上实施的,兼具数据处理、即时调控和报警提醒功能,小车接到行驶指令后,红外探头会检测路况信息(是否处在黑线路径范围内)并反馈给单片机处理,单片机判断后作出相应指令,由电机驱动使小车执行相应行驶动作。

单片机与系统的配合使智能小车的行驶保持灵敏迅速的状态。

关键词:单片机寻迹报警红外线电机驱动AbstractWith the rapid development of science and technology in recent years,SCM applications arecontinually deepen ing.Traditionalcontroltest drive at the same ti me, the rapidly growing update. In real-timedetect ionandcontrolof the microcomputer application system,the microcontrolleris oftenused asacore component.SCM is the main featureint egrated computer chip ina micro-computer. Itis a setof multi-counting and the interface in oneof the micro-controller. The 51 single-chip microcontroll eris the mosttypical andmost representative one.Thedesignof the mainapplicationAT89S51asthecontrol,anddisplaydriverintegratedcircuit sand other systems.Based on single chipdesign.MCUAT89S51 using the controlleras an alarm device that can givefull playto AT89S51ofdata processing and real-time control functions.Make the system work in the bestcondition,improvethesystem sensit ivity.Whentwo signal driven forward bycar tracing module,theinfrares onwhether to producelevel signalsthrough the black,retutn again according to requirement ofdesign procedure of judgment for motor drivermodule,itcontrolsthe car turning back forward ofrunning onthe blackline.Keywords:SCM,Tracing, Alarm device,Levelsignals,Motor driver module目录摘要ﻩ错误!未定义书签。

基于单片机的智能小车毕业论文

基于单片机的智能小车毕业论文

本科毕业设计(论文)基于单片机的智能小车控制基于单片机的智能小车控制摘要:智能化作为现代电子产品的新趋势,是今后的电子产业的发展方向。

智能化设计的电子产品可以按照预先设定的模式在一个环境里自动运作,不需要人为的管理,可应用于科学勘探、环境监测、智能家居等方面。

基于单片机的智能小车控制就是其中的一个体现。

本设计实现了一种基于51单片机的自动避障智能模型车系统,通过红外传感器采集路况信息,通过对检测信息的分析,自动控制转向电机转向,改变行驶路径,绕过障碍物,从而实现车稳定避障。

本课题设计的智能小车,具有自动避障功能,超声波测距报警,无线电遥控等功能。

关键词:智能车;51单片机;避障;红外线Smart car based on SCM controlAbstract:As a new trend of modern electronic products, intelligent is the developmental direction of electronic industry after then. Electronic products, which are intelligently designed, can automatically operate following the mode that is pre-set. Without the management of human beings, it can be used for scientific exploring, environmental monitoring, intelligent home furnishing, etc. One of the embodiments is the intelligent control car which is based on single chip microcomputer. In the design, an intelligent model car system based on MCU 51 has been realized. It can collect traffic information with infrared sensors. Meanwhile, by the analysis of information examined, it can transfer from automatic control to motor steering in order to change the route and dodge the obstacles so that the steady avoidance of the barrier can come true. In this paper, a car with the ability of intelligent judgment has been designed and made. It functions as the device which can dodge obstacles automatically, alarm with ultrasonic distance examination, and remote control by radio.Key words: Smart Cart;Single-chip 51;Obstacle Avoidance;Infrared目录序言 ............................................................................................................ 错误!未定义书签。

智能小车-毕业论文(设计)文献综述

智能小车-毕业论文(设计)文献综述

华侨大学厦门工院本科生毕业设计(论文)题目:智能小车软件系统设计姓名:魏雄飞学号: 1102104031系别:电气工程信息系专业:电气工程及其自动化年级: 11级指导教师:晏来成年月日基于单片机的智能小车摘要:随着电子工业的发展,智能技术广泛运用于各种领域,智能小车不仅在工业智能化上得到广泛的应用,而且运用于智能家居中的产品也越来越受到人们的青睐。

国外智能车辆的研究历史较长。

相比于国外,我国开展智能车辆技术方面的研究起步较晚,在智能车辆技术方面的研究总体上落后于发达国家但是也取得了一系列的成果。

随着人工智能技术、计算机技术、自动控制技术的迅速发展,智能控制将有广阔的发展空间.本文就智能小车研究现状以及未来的应用与发展前景做一个全方面的介绍.关键词:智能技术,STC89C52单片机,自动循迹,避障1 前言随着电子技术、计算机技术和制造技术的飞速发展,数码相机、DVD、洗衣机、汽车等消费类产品越来越呈现光机电一体化、智能化、小型化等趋势。

智能化作为现代社会的新产物,是以后的发展方向,他可以按照预先设定的模式在一个特定的环境里自动的运作,无需人为管理,便可以完成预期所要达到的或是更高的目标。

智能小车,也称轮式机器人,是一种以汽车电子为背景,涵盖控制、模式识别、传感技术、电子、电气、计算机、机械等多科学的科技创意性设计,一般主要路径识别、速度采集、角度控制及车速控制等模块组成。

一般而言,智能车系统要求小车在白色的场地上,通过控制小车的转向角和车速,使小车能自动地沿着一条任意给定的黑色带状引导线行驶。

本次课题设计以此为背景,设计一种简易的运动小车,运用直流电机对小车进行速度和正反方向的运动控制,通过单片机来控制直流电机的工作,从而实现对整个小车系统的运动控制。

2 主题智能车辆作为智能交通系统的关键技术,是许多高新技术综合集成的载体。

智能车辆驾驶是一种通用性术语,指全部或部分完成一项或多项驾驶任务的综合车辆技术.智能车辆的一个基本特征是在一定道路条件下实现全部或者部分的自动驾驶功能,下面简单介绍一下国内外智能小车研究的发展情况2.1国外智能车辆研究现状国外智能车辆的研究历史较长,始于上世纪50年代.它的发展历程大体可以分成三个阶段:第一阶段??20世纪50年代是智能车辆研究的初始阶段.1954年美国BarrettElectronics公司研究开发了世界上第一台自主引导车系统AGVS (AutomatedGuidedVehicleSystem)。

基于单片机的多功能智能小车设

基于单片机的多功能智能小车设

鉴于单片机的多功能智能小车设(实物制作)纲要跟着社会的发展,智能化愈来愈遇到人们的关注。

本设计经过模拟汽车的自动行驶及避障功能,来实现智能化。

本设计主要有三个模块包含信号检测模块、主控模块、电机驱动模块。

在此设计中,用 STC89C51单片机作为主控芯片,办理接收到的各样信号,并作出相应的反应;用红外对管来进行黑线检测,进而达到循迹和避障的目的;经过编写的程序,保证了电机的左右转动,进而达到小车设计时预约的目标。

因为小车在设计过程中,采纳了模块化的设计思路,所以在进行调试时特别方便。

我们能够分别对每一个功能部分来进行调试,驱动部分调试时,只需给电机向前或许向后的信号,就能够调试出其功能。

循迹部分调试时,只需经过检测到黑线,判断能否沿黑线行驶,即能够调试出。

在进行避障调试中,我们能够把阻碍物放在小车前面,而后看小车两个轮子的转向。

这类模块化的设计思想不单简化了设计过程,并且对我们此后的设计也会有必定启迪。

ABSTRACTAlong with the development of society, more and more intelligent attention. This design by simulating a cardriving and automatic obstacle avoidance, to achieve intelligent. This design has three main modulesincluding drive module, signal detection module, maincontrol module, motor. In this design, with STC89C51SCM as the master chip, processing various signals received, and make corresponding feedback; usingInfrared to tube to detect the black line, so as toachieve the purpose of tracking; Through the program,ensure the motor rotation, so as to achieve the designof the car when the scheduled target.As the car in the design process, using a modulardesign concept, so very convenient during debugging.We were part of each function for debugging, debugging driving part, as long as the motor forward or backwardsignal, you can debug the functionality.Whendebugging tracking part, simply by detecting the black line, todetermine whether the black line running along, thatyou can debug a. Avoidance during commissioning, we can put an obstacle in front of the car, and then look atthe car two steering wheels. This modular design notonly simplifies the design, but also for our futuredesigns also have some inspiration.Key Words : Intelligent,SCM,Infrared to tube ,Obstacle avoidance tracking目录一、绪论智能小车的研究与意义智能小车的现状论文研究内容与主要构造二、方案选型设计车体设计电机驱动选择PWM 调速技术循迹模块技术避障模块技术2. 6驱动模块2. 7控制系统模块2. 8电源选择三、硬件设计整体设计电源电路设计驱动电路设计循迹部分电路避障部分电路主控电路设计四、软件设计主程序设计概括主程序流程图驱动程序流程图循迹程序流程图避障程序流程图五、制作安装与调试小车的安装小车运动模式调试小车循迹调试小车避障调试小车的功能六、结论七、参照文件八、道谢第1章绪论智能小车的研究意义跟着计算机、微电子、信息技术的迅速发展,智能化技术的发展速度也愈来愈快,智能化与人们生产生活的联系愈来愈密切,智能化将是未来社会发展的必定趋向。

基于单片机的多功能智能小车设计

基于单片机的多功能智能小车设计

学科代码:学号:XXXXXXXXXXXXX 大学(本科)毕业论文题目:基于单片机的多功能智能小车设计学院:专业:年级:姓名:指导教师:完成时间:20 年月日、基于单片机的多功能智能小车设计摘要:近几年,我国经济的迅速的增长使得小车的销售量逐渐升高,2016年,我国新能源汽车的销售达到了51.7万辆,销售率同比增长了20.5%。

汽车数量的日益增多使得交通拥挤的现象越来越严重,因此,交通事故的发生的频率也在逐渐的增多。

为了提高小车运行的安全,本文提出了一种基于单片机的多功能智能型小车的设计。

本文以STC89C51的单片机为核心,设计了一款多功能的智能小车,由于STC89C51的单片机在市场上受到了消费者普遍的好评,利用它进行智能小车的设计,既满足了大众的需求,又提高了小车设计的性能。

同时,本文还结合了直流电机L298N型号的驱动芯片、E18-D80NK 红外避障传感器、TCRT5000红外反射式接近开关传感器对智能小车的整体进行了构架。

关键词:单片机;多功能;智能小车;设计AbstractIn recent years, China's rapid economic growth makes the car sales gradually increased, in 2016, China's new energy vehicle sales reached 517,000, sales rate increased by 20.5%. The increasing number of cars makes traffic congestion more and more serious, so the frequency of traffic accidents is gradually increasing. In order to improve the safety of car operation, this paper presents a multi-functional intelligent car based on single-chip design.In this paper, STC89C51 single-chip as the core, designed a multi-functional smart car, as STC89C51 microcontroller in the market by consumers generally praise, use it for intelligent car design, both to meet the needs of the public, but also improve The performance of the car design. At the same time, this article also combines the DC motor L298N model driver chip, E18-D80NK infrared obstacle avoidance sensor, TCRT5000 infrared reflector proximity switch sensor on the overall structure of the smart car.Key Words: Single-chip; multi-function; intelligent car; design目录Abstract (3)引言 (4)1方案选型 (4)1.1车体设计 (4)1.2电机驱动选择 (4)2.3 PWM调速技术 (6)2.4 循迹模块技术 (6)2.5 避障模块技术 (7)2.6 控制系统模块 (7)2.7电源选择 (8)2总体方案设计 (8)2.1设计任务描述 (8)2.2总体设计 (8)2.3需求分析 (9)2.4总体方案 (9)3硬件电路设计 (9)3.1电源电路设计 (9)3.2驱动电路设计 (9)3.3循迹避障部分电路 (10)4程序设计 (12)4.1主程序设计概述 (12)4.2 主程序流程图 (12)4.3 驱动程序流程图 (13)4.4 循迹程序流程图 (14)4.5 避障程序流程图 (15)5制作安装与调试 (16)5.1小车的安装 (16)5.2小车运动模式调试 (16)5.3小车循迹调试 (17)5.4小车避障调试 (17)5.3小车的功能 (17)结论 (18)参考文献 (19)引言当前,关于智能化小车的设计越来越成为当前学者们关注的热点问题,对于智能小车的设计,采用的方法也越来对多样,利用单片机的程序设计的智能小车也是其中的一种。

基于单片机智能小车毕业设计(论文)

基于单片机智能小车毕业设计(论文)

毕业设计(论文)设计(论文)题目:基于单片机的智能小车学院名称:电子与信息工程学院专业:电子与信息工程班级:电信092班姓名:\ 学号\指导教师:\ 职称\基于单片机的智能小车摘要智能车辆是目前世界车辆研究领域的热点和汽车工业新的增长点。

未来的车辆也一定是智能化的车辆。

所以,智能化的车辆是未来人们生活重要的载体。

因此有必要对智能车辆进行研究。

研制一种智能,高效的智能小车控制系统具有重要的实际意义和科学理论价值。

本文设计了一个能自动循迹的智能小车控制系统。

以STC89C52单片机为控制核心,利用反射式光电传感器检测黑线实现小车循迹,利用超声波传感器检测道路上的障碍并提示,利用LCD1602显示小车的速度和路程。

能实现小车自动根据地面黑线前进倒退、转向行驶,超声波测距提示障碍物,LCD1602实时显示小车的速度和行驶的路程,具有高度的智能化,达到设计目标。

关键词:智能小车,STC89C52单片机,超声波传感器,LCD1602目录摘要....................................................................................... 错误!未定义书签。

ABSTRACT ............................................................................................. 错误!未定义书签。

目录......................................................................................... 错误!未定义书签。

第1章绪论.................................................................................... 错误!未定义书签。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

基于单片机的多功能智能小车设计毕业论文目录1 设计任务 (3)1.1 要求 (3)2 方案比较与选择 (4)2.1路面检测模块 (4)2.2 LCD显示模块 (5)2.3测速模块 (5)2.4控速模块 (6)2.5模式选择模块 (7)3 程序框图 (7)4 系统的具体设计与实现 (9)4.1路面检测模块 (9)4.2 LCD显示模块 (9)4.3测速模块 (9)4.4控速模块 (9)4.5复位电路模块 (9)4.6模式选择模块 (9)5 最小系统图 (10)6 最终PCB板图 (12)7 系统程序 (13)8 致谢 (46)9 参考文献 (47)10 附录 (48)1. 设计任务:设计并制作了一个智能电动车,其行驶路线满足所需的要求。

1.1 要求:1.1.1 基本要求:(1)分区控制:如(图1)所示:(图1)车辆从起跑线出发(出发前,车体不得超出起跑线)。

在第一个路程C~D区(3~6米)以低速行驶,通过时间不低于10s;第二个路程D~E区(2米)以高速行驶,通过时间不得多于4秒;第三个路程E~F区(3~6米)以低速行驶,通过时间不低于10s。

(2)小车能自动记录、显示行驶时间、行驶距离以及行驶速度,还能记录每段所走的时间,从而判断是否符合课程设计要求。

(记录显示装置要求安装在车上)。

1.1.2 发挥部分:S型控制:如(图2)所示:(图2)车辆沿着S形铁片行驶,自动转弯,自动寻找正确方向和铁片。

当离开S型铁片跑道或者感应不到铁片一段时间的时候,小车自动停止,并记录行驶时间,路程,平均速度并通过LCD显示出来。

2. 方案比较与选择:根据设计任务要求,并且根据我们自己的需要而附加的功能,该电路的总体框图可分为几个基本的模块,框图如(图3)所示:(图3)2.1 路面检测模块:采用铁片感应器TL-Q5MC来检测路面上的铁片从而给单片机中断脉冲。

原理图接线如(图4)所示:(图4)2.2 LCD显示模块:采用1602LCD,由单片机的总线模式连接。

为节约电源电量并且不影响LCD的功能,LCD的背光用单片机进行控制,使LCD的背光在小车行驶的过程中不亮,因为我们不必看其显示;在其它我们需要看显示的容的时候LCD背光亮。

2.3 测速模块:2.3.1 方案1:采用采用霍尔开关元器件A44E检测轮子上的小磁铁从而给单片机中断脉冲,达到测量速度的作用。

霍尔元件具有体积小,频率响应宽度大,动态特性好,对外围电路要求简单,使用寿命长,价格低廉等特点,电源要求不高,安装也较为方便。

霍尔开关只对一定强度的磁场起作用,抗干扰能力强,因此可以在车轮上安装小磁铁,而将霍尔器件安装在固定轴上,通过对脉冲的计数进行车速测量。

2.3.2 方案2:采用红外传感器进行测速。

但无论是反射式红外传感器还是对射式红外传感器,他们对都对外围环境要求较高,易受外部环境的影响,稳定性不高,且价格较为昂贵。

通过对方案1、方案2的比较其优缺点,综合多方面因素决定选用方案1,其原理图接线如(图5)所示:(图5)2.4 控速模块:2.4.1 方案1:使用功率三极管作为功率放大器的输出控制直流电机。

线性型驱动的电路结构和原理简单,成本低,加速能力强,但功率损耗大,特别是低速大转距运行时,通过电阻R 的电流大,发热厉害,损耗大,对于小车的长时间运行不利。

2.4.2 方案2:采用继电器对电动机的开或关进行控制,通过开关的切换对小车的速度进行调整.此方案的优点是电路较为简单,缺点是继电器的响应时间慢,易损坏,寿命较短,可靠性不高。

2.4.3 方案3:采用由双极性管组成的H桥电路。

用单片机控制晶体管使之工作在占空比可调的开关状态,精确调整电机转速。

这种电路由于工作在管子的饱和截止模式下,效率非常高;H桥电路保证了可以简单地实现转速和方向的控制;电子开关的速度很快,稳定性也很高,是一种广泛采用的调速技术。

综合3种方案的优缺点,决定选择方案3,其电路原理图如(图6)所示:(图6)2.5 模式选择模块:模式选择模块通过一个74LS00与非门和两个不带锁按钮来控制单片机单片机的两个中断口,从而按动按钮来选择小车走动的路型、来选择小车的速度是快速、中速、慢速;走完路程小车停止后还可以通过按钮选择想要在LCD上想看的信息,比如总时间、走过各段路程的时间、平均速度、总路程等。

小车走动的模式选择有:(1)直线型:满足设计任务的基本要求,能稳定的走完全程。

之后按顺序循环不断的显示走完全程所用的时间、走完高速区所用的时间和走完低速区所用的时间这三个时间;或者可以通过两个按钮以及LCD显示的菜单选择所要看的容如平均速度、全程距离以及那三个时间。

(2) S型:满足设计任务的发挥部分的要求,小车能自动的感应到在前面或在后面铁片,即第一次转弯后若感应到的是错误的方向,则小车会后退自动调整方向,沿着S 型的铁片走。

当走完S型铁片后的一定时间里,小车自动停止。

之后自动进入菜单由我们自己选择要看的容时间、平均速度和所走的距离。

(3)自动型:小车先以一定的速度走完全程,之后再以一定的速度倒退回起点,再调整速度在一定的时间走完全程。

走完后LCD显示的容与直线型显示的容一样。

3. 程序框图:单片机主程序框图、速度感应程序框图和铁片感应程序框图分别如(图7)所示。

(图7)4.系统的具体设计与实现:4.1 路面检测模块:应用一个金属感应器,安装在车盘下,离地略小于或约四毫米。

当金属传感器检测到铁片时将对单片机发送中断信号,单片机运行中断,改变输给电机驱动信号的电压占空比来控制小车的速度。

4.2 LCD显示模块:采用1602LCD,由单片机的总线模式连接。

为节约电源,LCD的背光用单片机进行控制。

4.3 测速模块:通过霍尔元件感应磁铁来产生脉冲(当霍尔元件在离磁场较近时输出会是高电平,其它时候是低电平),一个车轮均匀放四个小磁铁,计算一秒所得的脉冲数,从而计算出一秒小车轮子转动圈数,再测量出小车车轮周长即可计算出小车当前速度,累加可得到当前路程。

4.4 控速模块:考虑到元器件的缺少以及我们所用的电路的驱动电机的电路原理图和和小车自带的电路的电机驱动原理图一样,所以暂时使用小车自带的电机驱动电路图。

4.5 复位电路模块:单片机的复位电路通过手动来实现,复位电路图如(图8)所示。

(图8)4.6 模式选择模块:两个中断口使用和感应铁片、感应速度所使用的中断口一样,通过一个与非门和按钮控制。

原理图如(图9)所示:(图9)5.最小系统图:该系统主要用到的是单片机,所以主要的部分是最小系统图,该最小系统图如(图10)所示:(图12)6. 最终PCB板图:该最小系统的最终PCB板图(包括LCD接口以及其他的外部扩展电路部分,考虑到最小系统的简洁以及容易看懂,外部扩展电路不在最小系统图上显示。

)分别如(图11)、(图12)所示:(图11)(图12)7.系统程序:按照预定的功能,系统实现预定的功能的程序如下所示:#include<intrins.h>#include<AT89X52.h>/********************************************************************************\** 宏定义区** \********************************************************************************//*------------------------------- LCD模块 ------------------------------------*/#define LCD_RW P2_6 //读写控制端#define LCD_RS P2_7 //数据命令选择端#define LCD_E P2_5 //执行使能端#define LCD_Data P1 //P1口#define Write 0x00//低电平写入#define Read 0x01//高电平读出#define Data 0x01//高电平选择数据#define Cmd 0x00//低电平选择命令#define Enable 0x00//跃变到低电平时执行命令#define Disable 0x01#define True 0x01#define False 0x00#define LCD_Init 0x38//初始化模式#define LCD_DispCtr 0x0C//开显示及光标设置#define LCD_CloseCtr 0x08//关显示#define LCD_CLS 0x01//清屏幕#define LCD_EnterSet 0x06//显示光标#define Busy P1_7 //忙信号/*-------------------------- 测速/测距/测时模块 -------------------------------*/ #define CircleLength 0.132//小车转一轮的长度为.132m/*-------------------------------- 控速模块 -----------------------------------*/ #define P03 P0_3 //后电机#define P04 P0_4 //后电机#define P01 P0_1 //前电机#define P02 P0_2 //前电机#define P31 P0_5 //控制液晶背光#define P33 P3_3/*------------------------------ 菜单选择模块---------------------------------*/ #define Line 0x00//0代表直线模式#define Curve 0x01//1代表S型模式#define Normal 0x00//0 代表正常速度#define Low 0x01//1 代表低速#define High 0x02//2 代表高速/*********************************************************************************\ ** 全局函数声明区 ** \*********************************************************************************//*------------------------------- LCD模块 -------------------------------------*/ void LCDInit(void); //LCD初始化void SetWriteCmd(void); //设置写命令模式void SetReadCmd(void); //设置读命令模式void SetWriteData(void); //设置写数据模式void WriteCmd(char cmd); //写命令void WriteData(char ddata); //写数据void ExecuteCmd(void); //执行命令void SetXY(char x,char y); //定位显示地址void DisplaySingleChar(char x,char y,char cchar); //显示单个字符void DisplayString(char x,char y,char *str); //显示一段字符串void Delay(unsigned int time); //延时主程序void DelayUs(unsigned int time); //延时子程序bit IsBusy(void); //判断忙标志函数void DisplayTime(void); //显示时间void DisplayAVGSpeed(void); //显示平均速度void DisplayDistance(void); //显示路程/*-------------------------- 测速/测距/测时模块 -------------------------------*/void INTInit(void); //所有中断初始化void SpeedINT(void); //测速中断void ComputeTime(void);void ComputeSpeedANDDistance(void); //计算速度和距离/*-------------------------------- 控速模块 -----------------------------------*/ void CtrSpeedINT(void); //控速中断void Time0INT(void);void Time1INT(void); //控速单位时间中断void Clock0_Init(void); //时钟中断初始化void Clock1_Init(void); //时钟中断初始化void CtrSpeed(void);/********************************************************************************\** 全局变量区** \********************************************************************************/float SpeedCount = 0; //测速计数脉冲float Speed = 0.0;float Distance = 0.0;char Time1INTCount=0; //T1中断时间计时float PassTime=0.00; //小车行走的时间short IsT0INT=1;bit IsT1INT; //判断T1是否已经响应中断short IsT0INT2=1;char Thx[5]={0xf4,0xf4,0xc5,0xf4,0xff}; //3ms,3ms,15ms,3mschar Tlx[5]={0x48,0x48,0x68,0x48,0xff};char Thx0=0xd8;char Tlx0=0xf0;char Thx1=0xb1; //20mschar Tlx1=0xe0;short Round=0;short Back=0;short Back0=0;bit Backid;bit Stop=0;char Area0=0;char Area1=0; //区域变量char LowSpeedArea1StartTime;char LowSpeedArea1EndTime;char HighSpeedAreaEndTime;char LowSpeedArea2EndTime;char LowSpeedArea1PassTime=0; //第一个低速区通过时间char HighSpeedAreaPassTime=0; //高速区通过时间char LowSpeedArea2PassTime=0; //第二个低速区通过时间char ReadyToGo=4; //倒计时char flag;bit Roundid=0;char Nocurve=0;char ChangeFlag;char Mode;bit Running;bit SelectedAll; //模式和速度是否选择完毕标志bit IsSelectingMode; //模式选择标志bit IsSelectingSpeed; //速度选择标志bit ModeSelected; //已经被选择的模式标志char SelectedMode=10; //模式选择是否完毕标志bit Next; //Next键标志bit SpeedSelected; //已经被选中的速度方案标志char SelectedSpeed; //速度选择是否完毕标志bit ChoosingDisplay; //人工选择菜单开始标志bit SelectedShow; //显示选择标志bit SelectedReturn; //返回选择标志bit Selected; //确定/返回键选择标志bit ReturnSelection; //返回键启用标志bit AVGSpeedShow; //平均速度显示标志bit TotalDistanceShow; //总路程显示标志bit ReturnMain; //返回主菜单标志bit AutoDisplay; //自动显示标志bit GoToChoosingDisplay; //人工选择标志bit AutoMode=0;char PassLineID=0;char PassLine=0;float PrepareDistance;float FirstDistance;float SecondDistance;float ThirdDistance;int FirstHigh;int SecondHigh;int ThirdHigh;float Rate=1.25; //5ms时的速度float Count=4; //时间的倍数/********************************************************************************\ ** 全局函数实现区** \********************************************************************************//*-------------------------------- 主函数 ------------------------------------*/ void main(){P01=0;P02=0;P03=0;P04=0;P31=1; //单片机复位,背光开Delay(40); //延时等待LCD启动LCDInit(); //初始化LCDDisplayString(0x0,0," Starting... ");DisplayString(0x0,1,"Designed By 202");Delay(300);WriteCmd(LCD_CLS);EA=1; //开总中断EX0=1; //开INT0中断IT0=1; //INTO边沿触发EX1=1; //开INT1中断IT1=1; //INT1边沿触发SelectedAll=False; //开始模式和速度选择/*------------------------------ 模式选择 ---------------------------------*/ DisplayString(0x0,0,"Choose The Mode ");DisplayString(0x0,1,"you want. ");Delay(50);WriteCmd(LCD_CLS);IsSelectingMode=True;while(1){WriteCmd(LCD_CLS);DisplayString(0x0,0," Line Mode ");DisplayString(0x0,1,"Next Yes");Delay(300); //延时消除抖动while (1) //不断检测中断,直到按确定键或是NEXT键{if (Next==True) //如果按Next键则直接跳出break;if (ModeSelected==True) //如果按确定键则设置模式为Line并跳出{SelectedMode=Line;break;} //如果什么键都没有按下,那么一直显示等待}if (ModeSelected==True) //按下了确定键,退出模式选择{IsSelectingMode=False;break;}if (Next==True) //按下了Next键,显示下一个菜单项{Next=False;WriteCmd(LCD_CLS);DisplayString(0x0,0," Curve Mode ");DisplayString(0x0,1,"Next Yes");Delay(300); //延时消除抖动while(1) //不断检测中断,直到按确定键或是Next键 {if (Next==True) //如果再一次按下Next键,则跳出break;if (ModeSelected==True) //如果按下确定键,则设置模式为Curve,并跳出{SelectedMode=Curve;break;}}}if (ModeSelected==True) //按下了确定键,退出模式选择{IsSelectingMode=False;break;}if (Next==True) //再一次按下了Next键,则循环模式选择{Next=False;WriteCmd(LCD_CLS);DisplayString(0x0,0," AutoMode ");DisplayString(0x0,1,"Next Yes");Delay(300); //延时消除抖动while(1){if (Next==True)break;if (ModeSelected==True){AutoMode=1;break;}}}if (ModeSelected==True){IsSelectingMode=False;break;}if (Next==True){Next=False;continue;}}Delay(50);WriteCmd(LCD_CLS);/*------------------------------ 速度选择 ---------------------------------*/if (SelectedMode==Line && AutoMode==0){DisplayString(0x0,0," Now Choose a ");DisplayString(0x0,1," kind of Speed ");Delay(50);WriteCmd(LCD_CLS);IsSelectingSpeed=True;while(1){WriteCmd(LCD_CLS);DisplayString(0x0,0," Normal Speed ");DisplayString(0x0,1,"Next Yes");Delay(300); //延时消除抖动while(1){if (Next==True) //如果按Next键则直接跳出break;if (SpeedSelected==True) //如果按确定键则设置速度为Normal并跳出{Thx[0]=0xec;Tlx[0]=0x78; //5msThx[1]=0xf0;Tlx[1]=0x60; //4msThx[2]=0x8a;Tlx[2]=0xd0; //30msThx[3]=0xf4;Tlx[3]=0x48; //3msSelectedSpeed=Normal;break;} //如果什么键都没有按下,那么一直显示等待}if (SpeedSelected==True) //按下了确定键,退出速度选择{IsSelectingSpeed=False;break;}if (Next==True){Next=False;WriteCmd(LCD_CLS);DisplayString(0x0,0," Low Speed ");DisplayString(0x0,1,"Next Yes");Delay(300); //延时消除抖动while(1){if (Next==True) //如果再一次按下Next键,则跳出break;if (SpeedSelected==True) //如果按下确定键,则设置速度为Low,并跳出{SelectedSpeed=Low; //这里没有速度设置,因为默认速度就是Lowbreak;}}}if (SpeedSelected==True) //按下了确定键,退出速度选择{IsSelectingSpeed=False;break;}if (Next==True){Next=False;WriteCmd(LCD_CLS);DisplayString(0x0,0," High Speed ");DisplayString(0x0,1,"Next Yes");Delay(300); //延时消除抖动while(1){if (Next==True) //如果再一次按下Next键,则跳出break;if (SpeedSelected==True) //如果按下确定键,则设置速度为High,并跳出{Thx[0]=0xe0;Tlx[0]=0xc0; //8msThx[1]=0xe0;Tlx[1]=0xc0; //8msThx[2]=0x63;Tlx[2]=0xc0; //40msThx[3]=0xec;Tlx[3]=0x78; //5msSelectedSpeed=High;break;}}}if (SpeedSelected==True) //按下了确定键,退出速度选择{IsSelectingSpeed=False;break;}if (Next==True) //再一次按下了Next键,则循环速度选择{Next=False;continue;}}}SelectedAll=True; //标志模式选择和速度选择完毕Running=True;Delay(50);WriteCmd(LCD_CLS);/*------------------------- 显示所选择的模式和速度方案 -------------------------*/ if (SelectedMode==Line){DisplayString(0x0,0,"Choosen Mode is ");DisplayString(0x0,1," Line ");Delay(50);WriteCmd(LCD_CLS);}if (SelectedMode==Curve){DisplayString(0x0,0,"Choosen Mode is ");DisplayString(0x0,1," Curve ");Delay(50);WriteCmd(LCD_CLS);}if (AutoMode==1){DisplayString(0x0,0,"Choosen Mode is ");DisplayString(0x0,1," AutoMode ");Delay(50);WriteCmd(LCD_CLS);}if (SelectedMode==Line){if (SelectedSpeed==Normal){DisplayString(0x0,0,"Choosen Speed is");DisplayString(0x0,1," Normal ");Delay(50);WriteCmd(LCD_CLS);}if (SelectedSpeed==Low){DisplayString(0x0,0,"Choosen Speed is");DisplayString(0x0,1," Low ");Delay(50);WriteCmd(LCD_CLS);}if (SelectedSpeed==High){DisplayString(0x0,0,"Choosen Speed is");DisplayString(0x0,1," High ");Delay(50);WriteCmd(LCD_CLS);}}INTInit(); //初始化所有中断DisplayString(0x0,0,"Left Times To Go");while (ReadyToGo--){DisplaySingleChar(0x7,1,ReadyToGo+0x30);DisplaySingleChar(0x09,1,'s');Delay(300);}WriteCmd(LCD_CLS);DisplayString(0x05,0,"Go");Delay(100);WriteCmd(LCD_CLS);DisplayString(0x0,0," Living... ");DisplayString(0x0,1,"Designed by 202");if (SelectedMode==Line&&AutoMode==0)flag=Area0;elseflag=1;while(flag<5){if(AutoMode==1) //自动模式 {switch(PassLineID){case0 :{if(IsT0INT==1){P01=P02=P04=0;P03=1;}else{P01=P02=P03=P04=0;}}break;case1 :{P01=P02=P03=0;P04=1;}break;case2 :{P01=P02=P04=0;P03=1;}break;default :break;}}else{if(SelectedMode==Line) //直线模式 {flag=Area0;if(IsT0INT==1){P03=1;P04=0;P01=P02=0;}else{P03=0;P04=0;P01=P02=0;}}else{ //S型模式if((Nocurve<2)&&Round!=0&&(Back0>0)&&Back!=0){if(Backid==1){P01=1;P02=0;P03=0;P04=1;}else{P01=0;P02=1;P03=0;P04=1;}Back=1;}else{if(Round==0){if(IsT0INT2==1){P01=0;P02=0;P03=1;P04=0;}else{P01=0;P02=0;P03=0;P04=0;}}else{if(P33==0){if(IsT0INT2==1){P01=0;P02=0;P03=1;P04=0;}else{P01=0;P02=0;P03=0;P04=0;}}else{EX1=1;if(Round%2){if(IsT0INT2==1){P01=1;P02=0;P03=1;P04=0;Backid=1;}else{P01=1;P02=0;P03=0;P04=0;}}else{if(IsT0INT2==1){P01=0;P02=1;P03=1;P04=0;Backid=0;}else{P01=0;P02=1;P03=0;P04=0;}}}}}}}if (IsT1INT==1){IsT1INT=0;ComputeTime();ComputeSpeedANDDistance();}}//补中断路程,加上最后一次中断缺失的路程ComputeSpeedANDDistance();P04=1;P03=0;P01=P02=0;Delay(90);P03=0;P04=0; //行程结束,小车停止P31=1; //行程结束,背光开ET0=0x0; //关T0中断ET1=0x0; //关T1中断EX1=0x01; //开INT1中断Running=False;AutoDisplay=True; //默认情况下直线模式会自动显示各个区域经过的时间WriteCmd(LCD_CLS);if (SelectedMode==Line) //直线模式才显示{while(1){if (GoToChoosingDisplay==True)break;Delay();WriteCmd(LCD_CLS);Delay();DisplayString(0,0," LowSpeedArea1");DisplayString(0,1," Costed ");DisplaySingleChar(0x0C,1,'s');LowSpeedArea1PassTime=LowSpeedArea1EndTime-LowSpeedArea1StartTime;DisplaySingleChar(0x0A,1,LowSpeedArea1PassTime%10+0x30);if (LowSpeedArea1PassTime > 9) //通过第一个低速区的时间超过s DisplaySingleChar(0x0B,1,LowSpeedArea1PassTime/10+0x30);if (GoToChoosingDisplay==True)break;Delay();WriteCmd(LCD_CLS);Delay();DisplayString(0,0," HighSpeedArea ");DisplayString(0,1," Costed ");DisplaySingleChar(0x0C,1,'s');HighSpeedAreaPassTime=HighSpeedAreaEndTime-LowSpeedArea1EndTime;DisplaySingleChar(0x0A,1,HighSpeedAreaPassTime%10+0x30);if ( HighSpeedAreaPassTime> 9) //通过高速区的时间超过s DisplaySingleChar(0x0B,1,HighSpeedAreaPassTime/10+0x30);if (GoToChoosingDisplay==True)break;Delay();WriteCmd(LCD_CLS);Delay();DisplayString(0,0," LowSpeedArea2 ");DisplayString(0,1," Costed ");DisplaySingleChar(0x0C,1,'s');LowSpeedArea2PassTime=LowSpeedArea2EndTime-HighSpeedAreaEndTime;DisplaySingleChar(0x0A,1,LowSpeedArea2PassTime%10+0x30);if ( LowSpeedArea2PassTime> 9) //通过第二个低速区的时间超过s DisplaySingleChar(0x0B,1,LowSpeedArea2PassTime/10+0x30);}}AutoDisplay=False;/*---------------- 菜单选择你想要看的容--总时间、总路程以及平均速度 --------------*/ ChoosingDisplay=True;WriteCmd(LCD_CLS);/*首先显示主菜单,然后显示第一个选项*/DisplayString(0x0,0,"Now Choose what ");DisplayString(0x0,1,"you want to see ");Delay(100);while(1){WriteCmd(LCD_CLS);DisplayString(0x0,0," Costed Time ");DisplayString(0x0,1,"Next Show");Delay(250); //延时消除抖动/*------------------------------------第一次按键--------------------------------------*//*不断检测确定键和Next键*/while(1){if (Next==True)break;if (SelectedShow==True)break;}/*按下了确定键,显示第一个选项的容*/if (SelectedShow==True){SelectedShow=False;SelectedReturn=False;Selected=False;WriteCmd(LCD_CLS);DisplayString(0,0,"Costed Time is");DisplayTime();DisplayString(0x0A,1,"s");ReturnSelection=True; //按下了确定键,那么这个时候开启返回键的功能AVGSpeedShow=False;Delay(250); //延时消除抖动}/**按下了Next键,则显示第二个选项*/if (Next==True) //按下Next键,显示AVGSpeed菜单项{Next=False;WriteCmd(LCD_CLS);DisplayString(0x0,0," AVGSpeed ");DisplayString(0x0,1,"Next Show");ReturnMain=False;ReturnSelection=False; //按下了Next键,那么这个时候关闭返回键的功能AVGSpeedShow=True; //表明AVGSpeed选项已经显示过了Delay(250); //延时消除抖动}/*------------------------------------第二次按键--------------------------------------*/ /*显示第一个选项的容后又不断检测返回键(确定键)和Next键*/while(1){if (Next==True)break;if (Selected==True)break;}if (Next==True){Next=False;ReturnMain=False;ReturnSelection=False; //按下了Next键,那么这个时候关闭返回键的功能if (AVGSpeedShow==False) //还没有显示AVGSpeed选项,显示它{ //即第一次选择了确定键WriteCmd(LCD_CLS);DisplayString(0x0,0," AVGSpeed ");DisplayString(0x0,1,"Next Show");TotalDistanceShow=False; //显示了AVGSpeed,则表明TotalDistance还没有显示Delay(250); //延时消除抖动}if (AVGSpeedShow==True) //已经显示过AVGSpeed选项了,则显示下一个选项{ //即第一次选择了Next键WriteCmd(LCD_CLS);DisplayString(0x0,0," Total Distance ");DisplayString(0x0,1,"Next Show");TotalDistanceShow=True; //表明显示了TotalDistance选项Delay(250); //延时消除抖动}}if (Selected==True) //按下了确定键或返回键{SelectedShow=False;SelectedReturn=False;Selected=False;if (ReturnSelection==True) //第一次选择了确定键,故这次按下的是返回键ReturnMain=True;if (ReturnSelection==False){WriteCmd(LCD_CLS);DisplayString(0,0,"The AVGSpeed is");DisplayString(0x0A,1,"m/s");ReturnSelection=True; //按下了确定键,那么这个时候开启返回键的功能Delay(250); //延时消除抖动}TotalDistanceShow=False;}if (ReturnMain==True) //按下了返回键,返回主菜单{ReturnMain=False;continue;}/*------------------------------------第三次按键--------------------------------------*/ /*如果没有返回主菜单,则继续检测Next键和确定键*/while(1){if (Next==True)break;if (SelectedShow==True)break;}/*按下Next键,显示下一个选项*/if (Next==True){Next=False;ReturnMain=False;ReturnSelection=False; //按下了Next键,那么这个时候关闭返回键的功能if (TotalDistanceShow==True)ReturnMain=True;if (TotalDistanceShow==False) //还没有显示TotalDistance选项,显示它{WriteCmd(LCD_CLS);DisplayString(0x0,0," Total Distance ");DisplayString(0x0,1,"Next Show");TotalDistanceShow=True;Delay(250); //延时消除抖动}}if (Selected==True) //按下了确定键或返回键{SelectedShow=False;SelectedReturn=False;Selected=False;if (ReturnSelection==True) //按下的是返回键ReturnMain=True;if (ReturnSelection==False){if (TotalDistanceShow==False) //表明AVGSpeed选项的容还没有显示{WriteCmd(LCD_CLS);DisplayString(0,0,"The AVGSpeed is");DisplayAVGSpeed();DisplayString(0x0A,1,"m/s");ReturnSelection=True;Delay(250); //延时消除抖动}if (TotalDistanceShow==True){WriteCmd(LCD_CLS);DisplayString(0,0,"Total Distance");DisplayDistance();DisplayString(0x0A,1,"m");ReturnSelection=True; //按下了确定键,那么这个时候开启返回键的功能Delay(250); //延时消除抖动}}}if (ReturnMain==True) //按下了返回键,返回主菜单{ReturnMain=False;continue;}/*------------------------------------第四次按键--------------------------------------*/ while(1){if (Next==True)break;if (SelectedShow==True)if (Next==True) //所有菜单项已经显示完毕,返回主菜单{Next=False;ReturnMain=False;ReturnSelection=False;if (TotalDistanceShow==False){WriteCmd(LCD_CLS);DisplayString(0x0,0," Total Distance ");DisplayString(0x0,1,"Next Show");TotalDistanceShow=True;Delay(250); //延时消除抖动}}if (SelectedShow==True){SelectedShow=False;SelectedReturn=False;Selected=False;if (ReturnSelection==True) //按下的是返回键ReturnMain=True;if (ReturnSelection==False){if (TotalDistanceShow==True){WriteCmd(LCD_CLS);DisplayString(0,0,"Total Distance");DisplayDistance();DisplayString(0x0A,1,"m");ReturnSelection=True; //按下了确定键,那么这个时候开启返回键的功能Delay(250); //延时消除抖动}}}if (ReturnMain==True) //按下了返回键,返回主菜单{ReturnMain=False;/*------------------------------------第五次按键--------------------------------------*/ while(1){if (Next==True)break;if (SelectedShow==True)break;}if (Next==True) //所有菜单项已经显示完毕,返回主菜单{Next=False;ReturnMain=False;ReturnSelection=False;if (TotalDistanceShow==True) //最后一个选项已经显示完毕,返回主菜单{ReturnMain=True;}}if (SelectedShow==True){SelectedShow=False;SelectedReturn=False;Selected=False;if (ReturnSelection==True) //按下的是返回键ReturnMain=True;if (ReturnSelection==False){if (TotalDistanceShow==True){WriteCmd(LCD_CLS);DisplayString(0,0,"Total Distance");DisplayDistance();DisplayString(0x0A,1,"m");ReturnSelection=True; //按下了确定键,那么这个时候开启返回键的功能Delay(250); //延时消除抖动}}/*------------------------------------第六次按键--------------------------------------*/ while(1){if (Next==True)break;if (SelectedShow==True)break;}if (Next==True){Next=False;ReturnMain=False;ReturnSelection=False;}if (SelectedShow==True){SelectedShow=False;SelectedReturn=False;Selected=False;}continue;}while(1);}/****************************************************************************************\ ** LCD驱动模块** \****************************************************************************************//*--------------------------------- LCD初始化函数--------------------------------------*/void LCDInit(void){//三次显示模式设置LCD_Data=0;LCD_E=Disable;Delay(5);WriteCmd(LCD_Init);Delay(5);WriteCmd(LCD_Init);Delay(5);WriteCmd(LCD_Init);WriteCmd(LCD_Init); //初始化WriteCmd(LCD_CloseCtr); //关显示WriteCmd(LCD_CLS); //清屏幕WriteCmd(LCD_EnterSet); //光标移动设置WriteCmd(LCD_DispCtr); //显示开以及光标设置}/*--------------------------------- LCD模式设置函数--------------------------------------*\SetWriteCmd() 设置LCD为写命令模式SetReadCmd() 设置LCD为读命令模式SetWriteData() 设置LCD为写数据模式\*----------------------------------------------------------------------------------------*/ void SetWriteCmd(void){LCD_RW=Write;LCD_RS=Cmd;}void SetReadCmd(void){LCD_RW=Read;LCD_RS=Cmd;}void SetWriteData(void){LCD_RW=Write;LCD_RS=Data;}/*--------------------------------- LCD功能执行函数--------------------------------------*\WriteCmd() 写命令WriteData() 写数据ExecuteCmd() 执行命令SetXY() 显示定位DisplaySingleChar() 显示单个字符DisplayString() 显示一串字符IsBusy() 忙标志检测\*----------------------------------------------------------------------------------------*/ void WriteCmd(char cmd)while(IsBusy());LCD_Data=cmd;SetWriteCmd();ExecuteCmd();}void WriteData(char ddata){while(IsBusy());LCD_Data=ddata;SetWriteData();ExecuteCmd();}void ExecuteCmd(void){LCD_E=Enable;LCD_E=Disable;}void SetXY(char x,char y){if (y)x|=0x40;x|=0x80;Delay(5);WriteCmd(x);}void DisplaySingleChar(char x,char y,char cchar) {SetXY(x,y);WriteData(cchar);}void DisplayString(char x,char y,char *str){while(*str){Delay(5);DisplaySingleChar(x++,y,*str);str++;}bit IsBusy(void){LCD_Data=0xFF;SetReadCmd();ExecuteCmd();return (bit)(P1 & 0x80);}/*------------------------------------- 延时函数 -------------------------------------*/ void Delay(unsigned int time){unsigned int timeCounter = 0;for (timeCounter = time;timeCounter > 0 ;timeCounter --)DelayUs(255);}void DelayUs(unsigned int time){unsigned int timeCounter = 0;for (timeCounter = 0;timeCounter < time;timeCounter ++)_nop_();}/*******************************************************************************************\ ** LCD显示模块 ** \*******************************************************************************************/void ComputeTime(void){if (Area0 < 5)PassTime+=0.5;}void ComputeSpeedANDDistance(void){Speed=SpeedCount/4*CircleLength; //计算瞬时速度Distance+=Speed; //计算距离SpeedCount=0;}/*------------------------------------- 显示时间 ----------------------------------------*/ void DisplayTime(void){char PassTime2=0x30;char PassTime3=0x30;char PassTime4=0x30;if ((int)PassTime*100<100) //时间未够1s{PassTime1+=0;PassTime2+=(int)(PassTime*100)/10;PassTime3+=(int)(PassTime*100)%10;}else if ((int)(PassTime*100) > 100 && (int)(PassTime*100) < 1000) //够1s而未够10s{PassTime1+=(int)(PassTime*100)/100;PassTime2+=(int)(PassTime*100)/10%10;PassTime3+=(int)(PassTime*100)%10;}else{PassTime1+=(int)(PassTime*100)/1000;PassTime2+=(int)(PassTime*100)/100%10;PassTime3+=(int)(PassTime*100)/10%10;PassTime4+=(int)(PassTime*100)%10;}if ((int)(PassTime*100) < 1000){DisplaySingleChar(0x05,1,PassTime1);DisplaySingleChar(0x06,1,'.');DisplaySingleChar(0x07,1,PassTime2);DisplaySingleChar(0x08,1,PassTime3);}else{DisplaySingleChar(0x04,1,PassTime1);DisplaySingleChar(0x05,1,PassTime2);DisplaySingleChar(0x06,1,'.');DisplaySingleChar(0x07,1,PassTime3);DisplaySingleChar(0x08,1,PassTime4);}}/*------------------------------------ 显示平均速度----------------------------------------*/{int Speed1=0x30; //初始化为0的ASCII码int Speed2=0x30;int Speed3=0x30;if ((int)(Distance/PassTime*100)< 100){Speed1+=0;Speed2+=(int)(Distance/PassTime*100)/10;Speed3+=(int)(Distance/PassTime*100)%10;}else{Speed1+=(int)(Distance/PassTime*100)/100;Speed2+=(int)(Distance/PassTime*100)/10%10;Speed3+=(int)(Distance/PassTime*100)%10;}DisplaySingleChar(0x05,1,Speed1);DisplaySingleChar(0x06,1,'.');DisplaySingleChar(0x07,1,Speed2);DisplaySingleChar(0x08,1,Speed3);}/*------------------------------------- 显示路程 ----------------------------------------*/void DisplayDistance(void){int Distance1=0x30;int Distance2=0x30;int Distance3=0x30;int Distance4=0x30;if ((int)(Distance*100) < 100){Distance1+=0;Distance2+=(int)(Distance*100)/10;Distance3+=(int)(Distance*100)%10;}else if ((int)(Distance*100) > 100 && (int)(Distance*100) < 1000){Distance1+=(int)(Distance*100)/100;Distance2+=(int)(Distance*100)/10%10;Distance3+=(int)(Distance*100)%10;}else。

相关文档
最新文档