《毕业设计基于AT89C51单片机的电容式液位检测系统的设计.doc》由会员分享,可在线阅读,更多相关《毕业设计基于AT89C51单片机的电容式液位检测系统的设计.doc(18页珍藏版)》请在三一办公上搜索。
1、基于AT89C51单片机的电容式液位检测系统的设计一、概述随着微电子工业的迅速发展,单片机控制的智能型控制器广泛应用于电子产品中,为了对单片机控制的智能型控制器有较深的了解。经过综合分析选择了由单片机控制的智能型液位控制器作为研究项目,通过训练充分激发自己分析问题、解决问题和综合应用所学知识的潜能。另外,液位控制在高层小区水塔水位控制,污水处理设备和有毒,腐蚀性液体液位控制中也被广泛应用。通过对模型的设计可很好的延伸到具体应用案例中。本设计基于AT89C51单片机,包括测量电路部分、AD转换部分、键盘输入控制部分、液位实时数显输出部分以及液位控制部分,还可在此基础上添加报警器。二、系统设计方案
2、的确定2.1 功能需求分析(1)要求能够实现较高精度的测量。(2)以单片机AT89C51为基础,设计外围电路。(3)电路设计,包括AD转换模块、数显模块、键盘输入模块 、报警模块、控制模块。(4)对测量电路的各种精度指标进行测试(非线性误差、重复性、滞后、灵敏度、抗侧向能力大小、温变对灵敏度的影响等指标)。2.2 系统设计方案的选择对于液位进行控制的方式有很多,而应用较多的主要有2种,一种是简单的机械式控制装置控制,一种是复杂的控制器控制方式。 复杂控制器控制方式,这种控制方式是通过安装在水泵出口管道上的压力传感器,把出口压力变成标准工业电信号的模拟信号,经过前置放大、多路切换、AD变换成数字
3、信号传送到单片机,经单片机运算和给定参量的比较,进行PID运算,得出调节参量;经由DA变换给调压变频调速装置输入给定端,控制其输出电压变化,来调节电机转速,以达到控制水箱液位的目的。针对上述2种控制方式,以及设计需达到的性能要求,这里选择第二种控制方式,同时考虑到成本需要把PID控制去掉。最终形成的方案是,利用单片机为控制核心,设计一个对低温储罐液位进行监控的系统。根据监控对象的特征,要求实时检测低温储罐的液位高度,并与开始预设定值做比较,由单片机控制固态继电器的开断进行液位的调整,最终达到液位的预设定值。检测值若高于上限设定值时,要求报警,断开继电器,控制水泵停止上水;检测值若低于下限设定值
4、,要求报警,开启继电器,控制水泵开始上水。现场实时显示测量值,从而实现对水箱液位的监控。原理流程图如下(图2.2):图2.2 液位测量原理流程图三、部分电路的设计3.1传感器的组成图3.1 为传感器部分的结构原理图。它主要是由细长的不锈钢管(半径为R1 ) 、同轴绝缘导线(半径为R0 ) 以及其被测液体共同构成的金属圆柱形电容器构成。该传感器主要利用其两电极的覆盖面积随被测液体液位的变化而变化, 从而引起对应电容量变化的关系进行液位测量。图3.1传感器原理图3.2 单片机电路设计3.2.1 AT89C51功能及引脚分布本次毕业设计基于AT89C51单片机, AT89C51是一种带4K字节闪烁可
5、编程可擦除只读存储器的低电压,高性能CMOS8位微处理器,俗称单片机。AT89C2051是一种带2K字节闪烁可编程可擦除只读存储器的单片机。单片机的可擦除只读存储器可以反复擦除100次。该器件采用ATMEL高密度非易失存储器制造技术制造,与工业标准的MCS-51指令集和输出管脚相兼容。由于将多功能8位CPU和闪烁存储器组合在单个芯片中,ATMEL的AT89C51是一种高效微控制器。AT89C单片机为很多嵌入式控制系统提供了一种灵活性高且价廉的方案。引脚分布如下图3.2.1所示:图3.2.1 AT89C51及引脚分布VCC:供电电压。GND:接地。P0口:P0口为一个8位漏级开路双向I/O口,每
6、脚可吸收8TTL门电流。当P1口的管脚第一次写1时,被定义为高阻输入。P0能够用于外部程序数据存储器,它可以被定义为数据/地址的第八位。在FIASH编程时,P0 口作为原码输入口,当FIASH进行校验时,P0输出原码,此时P0外部必须被拉高。P1口:P1口是一个内部提供上拉电阻的8位双向I/O口,P1口缓冲器能接收输出4TTL门电流。P1口管脚写入1后,被内部上拉为高,可用作输入,P1口被外部下拉为低电平时,将输出电流,这是由于内部上拉的缘故。在FLASH编程和校验时,P1口作为第八位地址接收。P2口:P2口为一个内部上拉电阻的8位双向I/O口,P2口缓冲器可接收,输出4个TTL门电流,当P2
7、口被写“1”时,其管脚被内部上拉电阻拉高,且作为输入。并因此作为输入时,P2口的管脚被外部拉低,将输出电流。这是由于内部上拉的缘故。P2口当用于外部程序存储器或16位地址外部数据存储器进行存取时,P2口输出地址的高八位。在给出地址“1”时,它利用内部上拉优势,当对外部八位地址数据存储器进行读写时,P2口输出其特殊功能寄存器的内容。P2口在FLASH编程和校验时接收高八位地址信号和控制信号。P3口:P3口管脚是8个带内部上拉电阻的双向I/O口,可接收输出4个TTL门电流。当P3口写入“1”后,它们被内部上拉为高电平,并用作输入。作为输入,由于外部下拉为低电平,P3口将输出电流(ILL)这是由于上
8、拉的缘故。P3口也可作为AT89C51的一些特殊功能口,如下表所示:管脚 备选功能P3.0 RXD(串行输入口)P3.1 TXD(串行输出口)P3.2 /INT0(外部中断0)P3.3 /INT1(外部中断1)P3.4 T0(记时器0外部输入)P3.5 T1(记时器1外部输入)P3.6 /WR(外部数据存储器写选通)P3.7 /RD(外部数据存储器读选通)P3口同时为闪烁编程和编程校验接收一些控制信号。RST:复位输入。当振荡器复位器件时,要保持RST脚两个机器周期的高电平时间。ALE/PROG:当访问外部存储器时,地址锁存允许的输出电平用于锁存地址的地位字节。在FLASH编程期间,此引脚用于
9、输入编程脉冲。在平时,ALE端以不变的频率周期输出正脉冲信号,此频率为振荡器频率的1/6。因此它可用作对外部输出的脉冲或用于定时目的。然而要注意的是:每当用作外部数据存储器时,将跳过一个ALE脉冲。如想禁止ALE的输出可在SFR8EH地址上置0。此时, ALE只有在执行MOVX,MOVC指令是ALE才起作用。另外,该引脚被略微拉高。如果微处理器在外部执行状态ALE禁止,置位无效。/PSEN:外部程序存储器的选通信号。在由外部程序存储器取指期间,每个机器周期两次/PSEN有效。但在访问外部数据存储器时,这两次有效的/PSEN信号将不出现。/EA/VPP:当/EA保持低电平时,则在此期间外部程序存
10、储器(0000H-FFFFH),不管是否有内部程序存储器。注意加密方式1时,/EA将内部锁定为RESET;当/EA端保持高电平时,此间内部程序存储器。在FLASH编程期间,此引脚也用于施加12V编程电源(VPP)。XTAL1:反向振荡放大器的输入及内部时钟工作电路的输入。XTAL2:来自反向振荡器的输出。3.2.2 振荡方式的选择 本次设计用到的是内部振荡方式,这种方式下在X1和X2两端跨接石英晶体及两个电容,如下图所示,这样就和内部的反响放大器构成稳定的自己振荡器。电容C1和C2通常取30pF,可稳定频率并对正当频率有微调作用。接线图如下:图3.2.2 内部振荡方式3.2.3 复位电路的设计
11、复位电路的基本功能是:系统上电时提供复位信号,直至系统电源稳定后,撤销复位信号。为可靠起见,电源稳定后还要经一定的延时才撤销复位信号,以防电源开关或电源插头分-合过程中引起的抖动而影响复位。图1所示的RC复位电路可以实现上述基本功能,图3为其输入-输出特性。但解决不了电源毛刺(A点)和电源缓慢下降(电池电压不足)等问题 而且调整 RC常数改变延时会令驱动能力变差。左边的电路为高电平复位有效右边为低电平Sm为手动复位开关 Ch可避免高频谐波对电路的干扰。电路图如下:图3.2.3 复位电路3.3 AD转换电路的设计 本次毕业设计使用AD转换器件是ADC0809,ADC0809是8路模拟信号的分时采
12、集,片内有8路模拟选通开关,以及相应的通道抵制锁存用译码电路,其转换时间为100s左右,ADC0809芯片为28引脚为双列直插式封装,其引脚分布图如下:图3.3 AD0809引脚图3.3.1 ADC0809主要信号引脚的功能IN7IN0模拟量输入通道ALE地址锁存允许信号。对应ALE上跳沿,A、B、C地址状态送入地址锁存器中。START转换启动信号。START上升沿时,复位ADC0809;START下降沿时启动芯片,开始进行A/D转换;在A/D转换期间,START应保持 低电平。本信号有时简写为ST.A、B、C地址线。 通道端口选择线,A为低地址,C为高地址,引脚图中为ADDA,ADDB和AD
13、DC。其地址状态与通道对应关系见表9-1。CLK时钟信号。ADC0809的内部没有时钟电路,所需时钟信号由外界提供,因此有时钟信号引脚。通常使用频率为500KHz的时钟信号EOC转换结束信号。EOC=0,正在进行转换;EOC=1,转换结束。使用中该状态信号即可作为查询的状态标志,又可作为中断请求信号使用。D7D0数据输出线。为三态缓冲输出形式,可以和单片机的数据线直接相连。D0为最低位,D7为最高OE输出允许信号。用于控制三态输出锁存器向单片机输出转换得到的数据。OE=0,输出数据线呈高阻;OE=1,输出转换得到的数据。Vcc +5V电源。Vref参考电源参考电压用来与输入的模拟信号进行比较,
14、作为逐次逼近的基准。其典型值为+5V(Vref(+)=+5V, Vref(-)=-5V).3.3.2 ADC0809与AT851单片机的连接电路连接主要涉及两个问题。一是8路模拟信号通道的选择,二是A/D转换完成后转换数据的传送。ADC0809与AT89C51单片机的连接图如下:图3.3.2.1 ADC0809与AT89C51单片机的接线图如图3.2.2.2所示模拟通道选择信号A、B、C分别接最低三位地址A0、A1、A2即(P0.0、P0.1、P0.2),而地址锁存允许信号ALE由P2.0控制,则8路模拟通道的地址为0FEF8H0FEFFH.此外,通道地址选择以WR作写选通信号,这一部分电路连
15、接如图所示。图3.2.2.2 模拟通道选择信号接线图从图中可以看到,把ALE信号与START信号接在一起了,这样连接使得在信号的前沿写入(锁存)通道地址,紧接着在其后沿就启动转换。启动A/D转换只需要一条MOVX指令。在此之前,要将P2.0清零并将最低三位与所选择的通道好像对应的口地址送入数据指针DPTR中。例如要选择IN0通道时,可采用如下两条指令,即可启动A/D转换: MOV DPTR , #FE00H ;送入0809的口地址 MOVX DPTR , A ;启动A/D转换(IN0)注意:此处的A与A/D转换无关,可为任意值。3.3.3 转换数据的传送A/D转换后得到的数据应及时传送给单片机
16、进行处理。数据传送的关键问题是如何确认A/D转换的完成,因为只有确认完成后,才能进行传送。为此可采用下述三种方式。1)定时传送方式对于一种A/D转换其来说,转换时间作为一项技术指标是已知的和固定的。例如ADC0809转换时间为128s,相当于6MHz的MCS-51单片机共64个机器周期。可据此设计一个延时子程序,A/D转换启动后即调用此子程序,延迟时间一到,转换肯定已经完成了,接着就可进行数据传送。2)查询方式A/D转换芯片由表明转换完成的状态信号,例如ADC0809的EOC端。因此可以用查询方式,测试EOC的状态,即可却只转换是否完成,并接着进行数据传送。3)中断方式把表明转换完成的状态信号
17、(EOC)作为中断请求信号,以中断方式进行数据传送。不管使用上述那种方式,只要一旦确定转换完成,即可通过指令进行数据传送。首先送出口地址并以信号有效时,OE信号即有效,把转换数据送上数据总线,供单片机接受。不管使用上述那种方式,只要一旦确认转换结束,便可通过指令进行数据传送。所用的指令为MOVX 读指令,仍以图9-17所示为例,则有 MOV DPTR , #FE00H MOVX A , DPTR该指令在送出有效口地址的同时,发出有效信号,使0809的输出允许信号OE有效,从而打开三态门输出,是转换后的数据通过数据总线送入A累加器中。这里需要说明的示,ADC0809的三个地址端A、B、C即可如前
18、所述与地址线相连,也可与数据线相连,例如与D0D2相连。这是启动A/D转换的指令与上述类似,只不过A的内容不能为任意数,而必须和所选输入通道号IN0IN7相一致。例如当A、B、C分别与D0、D1、D2相连时,启动IN7的A/D转换指令如下:MOV DPTR, #FE00H ;送入0809的口地址MOV A ,#07H ;D2D1D0=111选择IN7通道MOVX DPTR, A ;启动A/D转换3.4 键盘输入电路的设计3.4.1 按键去抖通常的按键所用开关为机械弹性开关,当机械触点断开、闭合时,电压信号小型如下图。由于机械触点的弹性作用,一个按键开关在闭合时不会马上稳定地接通,在断开时也不会
19、一下子断开。因而在闭合及断开的瞬间均伴随有一连串的抖动,如下图。抖动时间的长短由按键的机械特性决定,一般为5ms10ms。按键稳定闭合时间的长短则是由操作人员的按键动作决定的,一般为零点几秒至数秒。键抖动会引起一次按键被误读多次。为确保CPU对键的一次闭合仅作一次处理,必须去除键抖动。在键闭合稳定时读取键的状态,并且必须判别到键释放稳定后再作处理。按键的抖动,可用硬件或软件两种方法。(1)硬件消抖:在键数较少时可用硬件方法消除键抖动。下图所示的RS触发器为常用的硬件去抖。图3.3.1 RS触发器硬件消抖图中两个“与非”门构成一个RS触发器。当按键未按下时,输出为1;当键按下时,输出为0。此时即
20、使用按键的机械性能,使按键因弹性抖动而产生瞬时断开(抖动跳开B),中要按键不返回原始状态A,双稳态电路的状态不改变,输出保持为0,不会产生抖动的波形。也就是说,即使B点的电压波形是抖动的,但经双稳态电路之后,其输出为正规的矩形波。这一点通过分析RS触发器的工作过程很容易得到验证。(2)软件消抖:如果按键较多,常用软件方法去抖,即检测出键闭合后执行一个延时程序,产生5ms10ms的延时,让前沿抖动消失后再一次检测键的状态,如果仍保持闭合状态电平,则确认为真正有键按下。当检测到按键释放后,也要给5ms10ms的延时,待后沿抖动消失后才能转入该键的处理程序。3.4.2 键盘扫描方法扫描查询法,是一种
21、最常用的按键识别方法,如下图所3.4示键盘,介绍过程如下。(1)判断键盘中有无键按下 将全部行线Y0-Y3置低电平,然后检测列线的状态。只要有一列的电平为低,则表示键盘中有键被按下,而且闭合的键位于低电平线与4根行线相交叉的4个按键之中。若所有列线均为高电平,则键盘中无键按下。 (2)判断闭合键所在的位置 在确认有键按下后,即可进入确定具体闭合键的过程。其方法是:依次将行线置为低电平,即在置某根行线为低电平时,其它线为高电平。在确定某根行线位置为低电平后,再逐行检测各列线的电平状态。若某列为低,则该列线与置为低电平的行线交叉处的按键就是闭合的按键。 图3.4 44键盘扫描法接口电路3.5 数显
22、输出电路的设计下图为并行输入硬件译码静态显示电路,采用锁存器MC14495将P1口低4位输出地BCD码译成七段字形段码,利用P1口高4位作为各锁存译码器的锁存信号。CPU把送显数据写到锁存器后,对应的各位LED即可稳定显示。图3.5 硬件译码并行输入静态显示电路3.6报警及控制电路的设计四、软件设计部分4.1 原理图的绘制根据需求制作了MC14495原件,改造了AT89C51原件,原件图如下:图4.1.1 AT89C51图4.1.2 ADC08094.2 流程图的设计Employment tribunals sort out disagreements between employers an
23、d employees.You may need to make a claim to an employment tribunal if: you dont agree with the disciplinary action your employer has taken against you your employer dismisses you and you think that you have been dismissed unfairly.For more information about dismissal and unfair dismissal, seeDismiss
24、al.待添加的隐藏文字内容3You can make a claim to an employment tribunal, even if you haventappealedagainst the disciplinary action your employer has taken against you. However, if you win your case, the tribunal may reduce any compensation awarded to you as a result of your failure to appeal.Remember that in m
25、ost cases you must make an application to an employment tribunal within three months of the date when the event you are complaining about happened. If your application is received after this time limit, the tribunal will not usually accept i.If you are worried about how the time limits apply to you,
26、 take advice from one of the organisations listed underFurther help.Employment tribunals are less formal than some other courts, but it is still a legal process and you will need to give evidence under an oath or affirmation.Most people find making a claim to an employment tribunal challenging. If y
27、ou are thinking about making a claim to an employment tribunal, you should get help straight away from one of the organisations listed underFurther help.If you are being represented by a solicitor at the tribunal, they may ask you to sign an agreement where you pay their fee out of your compensation
28、 if you win the case. This is known as adamages-based agreement. In England and Wales, your solicitor cant charge you more than 35% of your compensation if you win the case.If you are thinking about signing up for a damages-based agreement, you should make sure youre clear about the terms of the agr
29、eement. It might be best to get advice from an experienced adviser, for example, at a Citizens Advice Bureau. To find your nearest CAB, including those that give advice by e-mail, click onnearest CAB.For more information about making a claim to an employment tribunal, seeEmployment tribunals.The (la
30、ck of) air up there Watch mCayman Islands-based Webb, the head of Fifas anti-racism taskforce, is in London for the Football Associations 150th anniversary celebrations and will attend Citys Premier League match at Chelsea on Sunday.I am going to be at the match tomorrow and I have asked to meet Yay
31、a Toure, he told BBC Sport.For me its about how he felt and I would like to speak to him first to find out what his experience was.Uefa hasopened disciplinary proceedings against CSKAfor the racist behaviour of their fans duringCitys 2-1 win.Michel Platini, president of European footballs governing
32、body, has also ordered an immediate investigation into the referees actions.CSKA said they were surprised and disappointed by Toures complaint. In a statement the Russian side added: We found no racist insults from fans of CSKA.Age has reached the end of the beginning of a word. May be guilty in his
33、 seems to passing a lot of different life became the appearance of the same day; May be back in the past, to oneself the paranoid weird belief disillusionment, these days, my mind has been very messy, in my mind constantly. Always feel oneself should go to do something, or write something. Twenty ye
34、ars of life trajectory deeply shallow, suddenly feel something, do it.一字开头的年龄已经到了尾声。或许是愧疚于自己似乎把转瞬即逝的很多个不同的日子过成了同一天的样子;或许是追溯过去,对自己那些近乎偏执的怪异信念的醒悟,这些天以来,思绪一直很凌乱,在脑海中不断纠缠。总觉得自己自己似乎应该去做点什么,或者写点什么。二十年的人生轨迹深深浅浅,突然就感觉到有些事情,非做不可了。The end of our life, and can meet many things really do?而穷尽我们的一生,又能遇到多少事情是真正地非做
35、不可?During my childhood, think lucky money and new clothes are necessary for New Year, but as the advance of the age, will be more and more found that those things are optional; Junior high school, thought to have a crush on just means that the real growth, but over the past three years later, his wr
36、iting of alumni in peace, suddenly found that isnt really grow up, it seems is not so important; Then in high school, think dont want to give vent to out your inner voice can be in the high school children of the feelings in a period, but was eventually infarction when graduation party in the throat
37、, later again stood on the pitch he has sweat profusely, looked at his thrown a basketball hoops, suddenly found himself has already cant remember his appearance.童年时,觉得压岁钱和新衣服是过年必备,但是随着年龄的推进,会越来越发现,那些东西根本就可有可无;初中时,以为要有一场暗恋才意味着真正的成长,但三年过去后,自己心平气和的写同学录的时候,突然就发现是不是真正的成长了,好像并没有那么重要了;然后到了高中,觉得非要吐露出自己的心声才
38、能为高中生涯里的懵懂情愫划上一个句点,但毕业晚会的时候最终还是被梗塞在了咽喉,后来再次站在他曾经挥汗如雨的球场,看着他投过篮球的球框时,突然间发现自己已经想不起他的容颜。Originally, this world, can produce a chemical reaction to an event, in addition to resolutely, have to do, and time.原来,这个世界上,对某个事件能产生化学反应的,除了非做不可的坚决,还有,时间。A persons time, your ideas are always special to clear. Wan
39、t, want, line is clear, as if nothing could shake his. Also once seemed to be determined to do something, but more often is he backed out at last. Dislike his cowardice, finally found that there are a lot of love, there are a lot of miss, like shadow really have been doomed. Those who do, just green
40、 years oneself give oneself an arm injection, or is a self-righteous spiritual.一个人的时候,自己的想法总是特别地清晰。想要的,不想要的,界限明确,好像没有什么可以撼动自己。也曾经好像已经下定了决心去做某件事,但更多的时候是最后又打起了退堂鼓。嫌恶过自己的怯懦,最终却发现有很多缘分,有很多错过,好像冥冥之中真的已经注定。那些曾经所谓的非做不可,只是青葱年华里自己给自己注射的一支强心剂,或者说,是自以为是的精神寄托罢了。At the moment, the sky is dark, the air is fresh f
41、actor after just rained. Suddenly thought of blue plaid shirt; Those were broken into various shapes of stationery; From the corner at the beginning of deep friendship; Have declared the end of the encounter that havent start planning. Those years, those days of do, finally, like youth, will end in
42、our life.此刻,天空是阴暗的,空气里有着刚下过雨之后的清新因子。突然想到那件蓝格子衬衫;那些被折成各种各样形状的信纸;那段从街角深巷伊始的友谊;还有那场还没有开始就宣告了终结的邂逅计划那些年那些天的非做不可,终于和青春一样,都将在我们的人生中谢幕。Baumgartner the disappointing news: Mission aborted. r plays an important role in this mission. Starting at the ground, conditions have to be very calm - winds less than 2
43、mph, with no precipitation or humidity and limited cloud cover. The balloon, with capsule attached, will move through the lower level of the atmosphere (the troposphere) where our day-to-day weather lives. It will climb higher than the tip of Mount Everest (5.5 miles/8.85 kilometers), drifting even
44、higher than the cruising altitude of commercial airliners (5.6 miles/9.17 kilometers) and into the stratosphere. As he crosses the boundary layer (called the tropopause),e can expect a lot of turbulence.The supersonic descent could happen as early as Sunda.The weatheThe balloon will slowly drift to
45、the edge of space at 120,000 feet ( Then, I would assume, he will slowly step out onto something resembling an Olympic diving platform.Below, the Earth becomes the concrete bottom of a swimming pool that he wants to land on, but not too hard. Still, hell be traveling fast, so despite the distance, i
46、t will not be like diving into the deep end of a pool. It will be like he is diving into the shallow end. Skydiver preps for the big jumpWhen he jumps, he is expected to reach the speed of sound - 690 mph (1,110 kph) - in less than 40 seconds. Like hitting the top of the water, he will begin to slow
47、 as he approaches the more dense air closer to Earth. But this will not be enough to stop him completely.If he goes too fast or spins out of control, he has a stabilization parachute that can be deployed to slow him down. His team hopes its not needed. Instead, he plans to deploy his 270-square-foot
48、 (25-square-meter) main chute at an altitude of around 5,000 feet (1,524 meters).In order to deploy this chute successfully, he will have to slow to 172 mph (277 kph). He will have a reserve parachute that will open automatically if he loses consciousness at mach speeds.Even if everything goes as planned, it wont. Baumgartner still will free fall at a speed that would cause you