毕业设计基于STC89C52的单片机的数字温度计设计_第1页
毕业设计基于STC89C52的单片机的数字温度计设计_第2页
毕业设计基于STC89C52的单片机的数字温度计设计_第3页
毕业设计基于STC89C52的单片机的数字温度计设计_第4页
毕业设计基于STC89C52的单片机的数字温度计设计_第5页
已阅读5页,还剩16页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、基于stc89c52的数字温度计基于stc89c52的数字温度计目 录1、 绪论.32、 方案选择 2.1、主控芯片选择 32.2、显示模块.32.3、温度检测模块.43、 系统硬件设计3.1、51单片机最小系统设计.43.2、电源供电电路设计.53.3、lcd显示电路设计.63.4、温度检测电路设计.74、 系统软件设计4.1、温度传感器数据读取流程图.94.2、系统程序设计.105、 编程和仿真5.1、keil编程软件.115.2、proteus.115.3、仿真界面.116、 总结.127、 附录 附录1、原理图.12 附录2、程序清单.131、绪论在信息高速发展的21世纪,科学技术的发

2、展日新月异,科技的进步带动了测量技术的发展,现代控制设备的性能和结构发生了翻天覆地的变化。我们已经进入了高速发展的信息时代,测量技术也成为当今科技的一个主流,广泛地深入到研究和应用工程的各个领域。温度和人们的生活息息相关,温度的测量也就变得很重要。2、系统方案选择2.1 主控芯片选择方案一:stc89c52rcstc89c52rc是采用8051核的isp在线可编程芯片,最高工作时钟频率80mhz,片内含8kb的可反复擦写1000次的flash只读存储器,器件兼容mcs-51指令系统及8051引脚结构,芯片内集成了通用8位中央处理器和isp flash存储单元,具有在线可编程特定,配合pc端的控

3、制程序即可将用户的程序代码下载进单片机内部,省去了购买通用编程器,而且速度更快。stc89c52rc系列单片机是单时钟周期、高速、低功耗的新一代8051单片机。方案二:atmega8atmega8是atmal公司在2002年第一季度推出的一款新型avr高档单片机。在avr家族中,atmega8是一种非常特殊的单片机,它的芯片内部集成了较大容量的存储器和丰富强大的硬件接口电路,具备avr高档单片机mega系列的全部性能和特点。但由于采用了小引脚封装(为dip28和tqfp/mlf32),所以其价格仅与低档单片机相当,再加上avr单片机的系统内可编程特性,使得无需购买昂贵的仿真器和编程器也可进行单

4、片机嵌入式系统的设计和开发,同时也为单片机的初学者提供了非常方便和简捷的开发环境。由以上两种方案进行比较,我们选择stc89c52rc作为主控芯片,因为该芯片是入门级单片机,我们对该款单片机比较熟悉,而avr单片机较为高端,这次的设计用stc89c52已经足够使用,引脚也够用,故用stc89c52作为主控芯片。stc89c52rc价格低廉,一般5元以内可以买到,在通银买也很方便。2.2 时钟及显示模块方案一:数码管数码管亮度高,显示大,特别是显示的时间很直观,价格比较便宜,但多位的数码管在动态扫描的时候会出现闪烁。而且数码管占用的位置较大,且比较耗电。方案二: 1602液晶屏1602液晶屏显示

5、清晰且不会闪烁,在需要时还可以输出字符等内容,由于液晶屏是数字式的,因此和单片机系统的接口简单,操作方便。1602lcd液晶显示屏的功耗主要消耗在其内部的电极和驱动ic 上,因而耗电量比其他显示器要少得多,功耗较低。由于其内部集成有显示芯片,程序编写简单,适用于多方面的应用。因此由以上两种方案进行比较,我们选择方案二来设计显示模块。1602液晶显示屏网上可购买的途径较多,价格一般在10元以内,重庆育森电子网店价格为8.5元。通银那也有,不过可能价格要15元左右。2.3 温度检测模块方案一:热敏电阻+ad模块本方案使用热敏电阻之类的器件(如ad590等模拟温度传感器)利用其感温效应,在将随被测温

6、度变化的电压或电流采集出来,进行a/d转换后,就可以利用单片机进行数据的处理,在显示电路上可以将被测温度显示出来,这种设计需要用到a/d转换电路,感温电路比较麻烦。方案二:ds18b20ds18b20数字温度传感器是dallas公司生产的1-wire,即单总线器件,具有线路简单,体积小的特点。因此用它来组成一个测温系统,具有线路简单,在一根通信线,可以挂很多这样的数字温度计,十分方便。它在实际应用中不需要外部任何元器件即可实现测温,测量温度范围在-55到+125摄氏度之间,由以上两种方案进行比较,我们选择方案二来设计温度检测模块。其中ds18b20网上报价约为5元,其中,重庆育森电子的网店较为

7、便宜,为4.5元。通银也有卖,价格稍微高点。3、系统硬件设计3.1 51单片机最小系统设计单片机最小系统如下图所示:以stc89c52单片机为核心,选用12m的晶振,这是最常用的选择,外接电容没有特别的要求,但是外接电容的大小会影响振荡器的频率高低、振荡器的稳定性和起振的快速性,因此我们选用30pf的电容作为起振电容。复位电路为按键低电平复位,当按键按下,ret端为高电平,当高电平持续4us的时间就可以使单片机复位。这里尤其要注意的是晶振和电容的位置,它们距离单片机引脚越短越好,因为太长可能无法使单片机起振。另外是ea端一定要接上电源,使单片机能够工作。3.2 电源供电电路设计电源供电电路如下

8、图所示:我们采用4节1.5v的电池作为电源,lm2940为稳压芯片,稳压芯片两端分别接两个0.1uf和100uf的电容进行滤波,以获得更稳定的电压。d1为电源指示灯,当开关打开,显示灯亮,表示给电路供+5v电压。其中,lm2940作为常用的稳压芯片,比7805的转换效率要高,7805直接输入不接输出的情况下,其内部会有3ma的静态电流消耗,而2940的静态电流比7805要小的多,故选择lm2940作为稳压芯片。4节电池装在电池盒中,在电路板下方安装,使用两套螺丝。3.3 lcd显示电路设计1602lcd液晶屏显示电路如下图所示:1602lcd液晶屏为5v电压驱动,带背光,可显示两行,每行16个

9、字符,不能显示汉字。液晶1、2端为电源;15、16为背光电源;为防止直接加5v而烧坏背光灯,在15脚串联一个1k电阻晶3端为液晶对比度调节端,通过一个10k的电位器来调节液晶显示对比度。用于限流。液液晶4端为向液晶控制器写数据/写命令选择端,接单片机p1.0端口。液晶5端为读/写选择端,因为我们不需要从液晶中读取数据,只向其写入命令和数据,因此此端始终选择为写状态,即低电平接地。液晶6端为使能信号,是操作必须的信号,接单片机的p1.1口。3.4 温度检测电路设计温度检测电路如下图所示:ds18b20是美国dallas半导体公司最新推出的一种改进型智能温度传感器,与传统的热敏电阻等测温元件相比,

10、它能直接读出被测温度,并且可根据实际要求通过简单的编程实现位的数字值读数方式。ds18b20的性能特点如下: 独特的单线接口仅需一个端口引脚进行通讯 简单的多点分布应用 无需外部器件 可通过数据线供电 零待机功耗 测温范围-55+125,以0.5递增。华氏器件-67+2570f,以0.90f 递增 温度以9 位数字量读出 温度数字量转换时间200ms(典型值) 用户可定义的非易失性温度报警设置 报警搜索命令识别并标志超过程序限定温度(温度报警条件)的器件。ds18b20内部结构主要由四部分组成:64位光刻rom、温度传感器、非挥发的温度报警触发器th和tl、配置寄存器。ds18b20的管脚排列

11、、各种封装形式如图 3.3.1所示,dq 为数据输入/输出引脚。开漏单总线接口引脚。当被用着在寄生电源下,也可以向器件提供电源;gnd为地信号;vdd为可选择的vdd引脚。当工作于寄生电源时,此引脚必须接地。其电路图如图5.3.1所示.。 图5.3.1 外部封装形式 在仿真软件中如图5.3.2所示 图5.3.2ds18b20的测温原理如图5.3.3所示,图中低温度系数晶振的振荡频率受温度的影响很小用于产生固定频率的脉冲信号送给减法计数器1,高温度系数晶振随温度变化其震荡频率明显改变,所产生的信号作为减法计数器2的脉冲输入,图中还隐含着计数门,当计数门打开时,ds18b20就对低温度系数振荡器产

12、生的时钟脉冲后进行计数,进而完成温度测量.计数门的开启时间由高温度系数振荡器来决定,每次测量前,首先将-55 所对应的基数分别置入减法计数器1和温度寄存器中,减法计数器1和温度寄存器被预置在-55 所对应的一个基数值。减法计数器1对低温度系数晶振产生的脉冲信号进行减法计数,当减法计数器1的预置值减到0时温度寄存器的值将加1,减法计数器 1的预置将重新被装入,减法计数器1重新开始对低温度系数晶振产生的脉冲信号进行计数,如此循环直到减法计数器2计数到0时,停止温度寄存器值的累加,此时温度寄存器中的数值即为所测温图5.3.3中的斜率累加器用于补偿和修正测温过程中的非线性其输出用,于修正减法计数器的预

13、置值,只要计数门仍未关闭就重复上述过程,直至温度寄存器值达到被测温度值,这就是ds18b20的测温原理。另外,由于ds18b20单线通信功能是分时完成的,有严格的时隙概念,因此读写时序很重要。系统对ds18b20的各种操作必须按协议进行。操作协议为:初始化ds18b20(发复位脉冲)发rom功能命令发存储器操作命令处理数据。图5.3.3 在正常测温情况下,ds1820的测温分辨力为0.5。4、 系统软件设计4.1:实验主程序流程图4.2:温度传感器数据读取流程图5、编程和仿真5.1 编程软件keil4keil c51是美国keil software 公司出品的51系列兼容单片机c语言软件开发系

14、统,与汇编相比,c语言在功能上、结构性、可读性、可维护性上有明显的优势,因而易学易用。keil提供了包括c编译器、宏汇编、连接器、库管理和一个功能强大的仿真调试器等在内的完整开发方案,通过一个集成开发环境(uvision)将这些部分组合在一起。运行keil需要win98、nt、win2000、winxp、win7等操作系统。2009年2月发布的keil uvision4,keil uvision4引入灵活的窗口管理系统,使开发人员能够使用多台监视器,并提供了视觉上的表面对窗口位置的完全控制的任何地方,新的用户界面可以更好地利用屏幕空间和更有效地组织多个窗口,提供一个整洁、高效的环境来开发应用程

15、序。5.2 仿真软件proteus7.7proteus软件是labcenter electronics公司出版的eda工具软件(该软件中国总代理为广州风标电子技术有限公司)。它不仅具有其它eda工具软件的仿真功能,还能仿真单片机及外围器件。它是目前最好的仿真单片机及外围器件的工具。虽然目前国内推广刚起步,但已受到单片机爱好者、从事单片机教学的教师、致力于单片机开发应用的科技工作者的青睐。proteus是世界上著名的eda工具(仿真软件),从原理图布图、代码调试到单片机与外围电路协同仿真,一键切换到pcb设计,真正实现了从概念到产品的完整设计。是目前世界上唯一将电路仿真软件、pcb设计软件和虚拟

16、模型仿真软件三合一的设计平台,其处理器模型支持8051、hc11、pic10/12/16/18/24/30/dspic33、avr、arm、8086和msp430等,2010年又增加了cortex和dsp系列处理器,并持续增加其他系列处理器模型。在编译方面,它也支持iar、keil和mplab等多种编译器。5.3仿真界面6、总结1、选择芯片和传感器时,够用易用就可以,综合考虑选择性价比最好的。2、在进行电路实际制作之前,应该用仿真软件进行仿真,可以使开发进程加快。3、在实际制作电路时,需要注意电源端和地端要检测过不导通后才能通电检测,防止烧坏芯片。7、 附录附录1、原理图附录2、程序清单#in

17、clude /头文件#define uchar unsigned char #define uint unsigned intsbit rs=p20;sbit lcden=p21; /液晶使能端sbit data = p37; /ds18b20接入口uchar flag_dis=0;uchar bai_18b20,shi_18b20,ge_18b20,num; /定义变量bit flag_negative_number ;/负数标志uchar code table=tempreture: ; /提示语/*一毫秒定时*/void delay_ms(uint z)uint x,y;for(x=z;

18、x0;x-)for(y=110;y0;y-);/*延时子函数*/void delay(uint num)while(num-) ;/*液晶写命令*/void write_lcd_com(uchar com)rs=0;lcden=0;p0=com;delay_ms(1);lcden=1;delay_ms(1);lcden=0;/*液晶写数据*/void write_lcd_date(uchar date)rs=1;lcden=0;p0=date;delay_ms(1);lcden=1;delay_ms(1);lcden=0;/*液晶初始化程序*/void lcd_init()write_lcd_

19、com(0x38);write_lcd_com(0x0c);write_lcd_com(0x06);write_lcd_com(0x01);/*ds18b20温度传感器函数*/void init_ds18b20(void) /传感器初始化 uchar x=0; data = 1; /dq复位 delay(10); /稍做延时 data = 0; /单片机将dq拉低 delay(80); /精确延时 大于 480us /450 data = 1; /拉高总线 delay(20); x=data; /稍做延时后 如果x=0则初始化成功 x=1则初始化失败 delay(30);/*温度传感器读一个字

20、节*/readonechar(void)uchar i=0;uchar dat = 0;for (i=8;i0;i-) data = 0; / 给脉冲信号 dat=1; data = 1; / 给脉冲信号 if(data) dat|=0x80; delay(8); return(dat);/*温度传感器写一个字节*/void writeonechar(uchar dat) uchar i=0; for (i=8; i0; i-) data = 0; data = dat&0x01; delay(10); data = 1; dat=1; delay(8);/*读取温度传感器温度*/int re

21、adtemperature(void)uchar a=0;uchar b=0;int t=0;float tt=0;init_ds18b20();writeonechar(0xcc); /跳过读序号列号的操作writeonechar(0x44); /启动温度转换init_ds18b20();writeonechar(0xcc); /跳过读序号列号的操作writeonechar(0xbe); /读取温度寄存器等(共可读9个寄存器)前两个就是温度a=readonechar();/低位b=readonechar();/高位t=b;t=8;t=t|a;if(b&0x80) t=t+1;flag_neg

22、ative_number = 1; else flag_negative_number = 0; tt=t*0.0625;t= tt*10+0.5; return(t);/*液晶显示温度*/void dis_d18b20(void)int temp;temp=readtemperature();/读温度bai_18b20=temp%1000/100;/显示十位shi_18b20=temp%100/10;/显示个位ge_18b20=temp%10;/显示十分位if(flag_negative_number) /负数if(bai_18b20=0) /十位为0,则不显示十位write_lcd_com

23、(0x80+0x40);write_lcd_date(0x2d);write_lcd_date(0x30+shi_18b20);write_lcd_date(0x30+ge_18b20);write_lcd_date(0xdf);write_lcd_date(0x43);elsewrite_lcd_com(0x80+0x40);write_lcd_date(0x2d);write_lcd_date(0x30+bai_18b20);write_lcd_date(0x30+shi_18b20);write_lcd_date(0xdf);write_lcd_date(0x43);else /正数if

24、(bai_18b20=0) /十位为0,则不显示十位write_lcd_com(0x80+0x40);write_lcd_date(0x30+shi_18b20);write_lcd_date(0x2e);write_lcd_date(0x30+ge_18b20);write_lcd_date(0xdf);write_lcd_date(0x43);elsewrite_lcd_com(0x80+0x40);write_lcd_date(0x30+bai_18b20);write_lcd_date(0x30+shi_18b20);write_lcd_date(0x2e);write_lcd_dat

25、e(0x30+ge_18b20);write_lcd_date(0xdf);write_lcd_date(0x43);void main()lcd_init();tmod=0x01;th0=(65536-50000)/256; tl0=(65536-50000)%256; tr0=1;et0=1; ea=1; /开总中断write_lcd_com(0x80);for(num=0;num11;num+)write_lcd_date(tablenum);/delay_ms(10);/dis_d18b20();while(1)if(flag_dis=1) flag_dis=0;dis_d18b20(

26、); /读温度并显示timer0() interrupt 1 / uchar count; th0=(65536-50000)/256; tl0=(65536-50000)%256;count+;if(count=60)/每三秒钟读一次温度传感器温度flag_dis=1;count=0;g an employment tribunal claiemployment tribunals sort out disagreements between employers and employees.you may need to make a claim to an employment tribu

27、nal 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, seedismissal.you can make a claim to an employment tribunal, even if you

28、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 most cases you must make an application to an employment tribunal within th

29、ree 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, take advice from one of the organisations listed underfurther help.employ

30、ment 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 you are thinking about making a claim to an employment tribunal, you should

31、 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 if you win the case. this is known as adamages-based agreement. in englan

32、d 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 agreement. it might be best to get advice from an experienced adviser, for ex

33、ample, 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 (lack of) air up there watch mcayman islands-based webb, the head of fifas an

34、ti-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 yaya toure, he told bbc sport.for me its about how he felt and i would like t

35、o 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 body, has also ordered an immediate investigation into the referees action

36、s.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 seems to passing a lot of different life became the appearance of the sam

37、e 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 years of life trajectory deeply shallow, suddenly feel something, do it.一字开头

38、的年龄已经到了尾声。或许是愧疚于自己似乎把转瞬即逝的很多个不同的日子过成了同一天的样子;或许是追溯过去,对自己那些近乎偏执的怪异信念的醒悟,这些天以来,思绪一直很凌乱,在脑海中不断纠缠。总觉得自己自己似乎应该去做点什么,或者写点什么。二十年的人生轨迹深深浅浅,突然就感觉到有些事情,非做不可了。the end of our life, and can meet many things really do?而穷尽我们的一生,又能遇到多少事情是真正地非做不可?during my childhood, think lucky money and new clothes are necessary fo

39、r 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 writing of alumni in peace, suddenly found that isnt really grow up, it seem

40、s 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, later again stood on the pitch he has sweat profusely, looked at his thr

41、own a basketball hoops, suddenly found himself has already cant remember his appearance.童年时,觉得压岁钱和新衣服是过年必备,但是随着年龄的推进,会越来越发现,那些东西根本就可有可无;初中时,以为要有一场暗恋才意味着真正的成长,但三年过去后,自己心平气和的写同学录的时候,突然就发现是不是真正的成长了,好像并没有那么重要了;然后到了高中,觉得非要吐露出自己的心声才能为高中生涯里的懵懂情愫划上一个句点,但毕业晚会的时候最终还是被梗塞在了咽喉,后来再次站在他曾经挥汗如雨的球场,看着他投过篮球的球框时,突然间发现自

42、己已经想不起他的容颜。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. want, want, line is clear, as if nothing could shake his. also once seemed to

43、 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 years oneself give oneself an arm injection, or is a self-righteous spiri

44、tual.一个人的时候,自己的想法总是特别地清晰。想要的,不想要的,界限明确,好像没有什么可以撼动自己。也曾经好像已经下定了决心去做某件事,但更多的时候是最后又打起了退堂鼓。嫌恶过自己的怯懦,最终却发现有很多缘分,有很多错过,好像冥冥之中真的已经注定。那些曾经所谓的非做不可,只是青葱年华里自己给自己注射的一支强心剂,或者说,是自以为是的精神寄托罢了。at the moment, the sky is dark, the air is fresh factor after just rained. suddenly thought of blue plaid shirt; those were

45、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 our life.此刻,天空是阴暗的,空气里有着刚下过雨之后的清新因子。突然想到那件蓝格子衬衫;那些被折成各种各样形状的信纸;那段从街角深巷伊始的友

46、谊;还有那场还没有开始就宣告了终结的邂逅计划那些年那些天的非做不可,终于和青春一样,都将在我们的人生中谢幕。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 mph, with no precipitation or humidity and limited cloud cover. the balloo

47、n, 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 higher than the cruising altitude of commercial airliners (5.6 miles/9.17 kilometers) and into the stratosphere. as he cr

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论