




已阅读5页,还剩19页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
xx职业技术学院课题名称:基于STC89C52RC单片机的数字温度计设计 院系:xxx系 班级:xx班 姓名:xx 学号:xx 201x 年 x月x日摘 要温度是日常生活中无时不在的物理量,温度的控制在各个领域都有积极的意义。很多行业中都有大量的用电加热设备,如用于热处理的加热炉,用于融化金属的坩锅电阻炉及各种不同用途的温度箱等,采用单片机对它们进行控制不仅具有控制方便、简单、灵活性大等特点,而且还可以大幅度提高被控温度的技术指标,从而能够大大提高产品的质量。因此,智能化温度控制技术正被广泛地采用。随着现代信息化技术的飞速发展和传统工业改造的逐步实现,能独立工作的温度检测系统已广泛应用于各种不同的领域。本文介绍了一个基于STC89C52单片机和数字温度传感器DS18B20的测温系统,并用LED数码管显示温度值,易于读数。系统电路简单、操作简便,能任意设定报警温度并可查询最近的10个温度值,系统具有可靠性高、成本低、功耗小等优点。本设计以STC89C52RC单片机为控制核心,由实时时钟芯片DS1302和数字温度传感器DS18B20构成了一个高温和低温时,分别对相应的器件进行控制的系统。详细地介绍了整个系统的硬件组成结构、工作原理和系统的软件程序设计,重点阐述了时钟模块、显示模块、温度检测模块及相关控制模块等的模块化设计思路与制作。系统采用液晶LCD1602作为显示器,具有实时时间显示、环境温度显示,显示系统连续工作前24小时整点的温度值。在本设计中,软件程序均采用C语言编写,便于移植与升级。关键词:单片机 数字温度传感器 温度计21目 录一、设计要求11.1基本要求11.2 扩展功能1二、 总体方案设计12.1 方案论证12.1.1 方案一12.1.2 方案二12.2 总体设计框图1三、 硬件设计23.1 单片机系统23.2 数字温度传感器模块33.2.1 DS18B20性能33.2.2 DS18B20外形及引脚说明43.2.3 DS18B20接线原理图43.2.4 DS18B20时序图43.2.5 数据处理63.3 显示电路73.4 声光报警电路73.5 键盘输入电路8四、软件设计84.1 主程序模块84.2 读温度值模块94.3 中断模块114.4 温度查询模块124.5 温度设定、报警模块134.6 数码管驱动模块15五、总结16参考文献:171一、设计要求1.1基本要求实现实时温度显示,测温范围0500C,误差50C以内。1.2 扩展功能温度报警,能任意设定温度范围实现声光报警;每隔10分钟记录一次温度数据,至少能查询过去10个时刻的温度情况。二、 总体方案设计2.1 方案论证2.1.1 方案一由于本设计是测温电路,可以使用热敏电阻之类的器件,将随被测温度变化的电压或电流采样,进行A/D转换后就可以用单片机进行数据处理,实现温度显示。这种设计需要用到A/D转换电路,增大了电路的复杂性,而且要做到高精度也比较困难。2.1.2 方案二考虑到在单片机属于数字系统,容易想到数字温度传感器,可选用DS18B20数字温度传感器,此传感器为单总线数字温度传感器,起体积小、构成的系统结构简单,它可直接将温度转化成串行数字信号给单片机处理,即可实现温度显示。另外DS18B20具有3引脚的小体积封装,测温范围为-55+125摄氏度,测温分辨率可达0.0625摄氏度,其测量范围与精度都能符合设计要求。以上两种方案相比较,第二种方案的电路、软件设计更简单,此方案设计的系统在功耗、测量精度、范围等方面都能很好地达到要求,故本设计采用方案二。2.2 总体设计框图本方案设计的系统由单片机系统、数字温度传感器、LED显示模块、按键控制模块、温度报警模块组成,其总体架构如下图1。单片机报警电路显示电路驱动电路测温电路按键输入电路时钟、复位电路图1 系统总体方框图三、 硬件设计3.1 单片机系统1. 本设计采用STC89C52单片机作为控制器,完成所有功能的控制,包括:l DS18B20数字温度传感器的初始化和读取温度值l LED数码管显示驱动与控制l 按键识别和响应控制l 温度设置和报警l 温度值的存储和读取2. 单片机系统电路原理图:图2 单片机系统原理图3.2 数字温度传感器模块3.2.1 DS18B20性能l 独特的单线接口仅需一个端口引脚进行通信l 简单的多点分布应用l 无需外部器件l 可通过数据线供电l 零待机功耗l 测温范围-55+125,以0.5递增l 可编程的分辨率为912位,对应的可分辨温度分别为0.5、0.25、0.125和0.0625l 温度数字量转换时间200ms,12位分辨率时最多在750ms内把温度转换为数字l 应用包括温度控制、工业系统、消费品、温度计和任何热感测系统l 负压特性:电源极性接反时,传感器不会因发热而烧毁,但不能正常工作3.2.2 DS18B20外形及引脚说明图3 DS18B20外形及引脚l GND:地l DQ:单线运用的数据输入/输出引脚l VD:可选的电源引脚3.2.3 DS18B20接线原理图单总线通常要求接一个约4.7K左右的上拉电阻,这样,当总线空闲时,其状态为高电平。图4 DS18B20接线原理图3.2.4 DS18B20时序图主机使用时间隙来读写DS18B20的数据位和写命令字的位。1. 初始化时序如下图:图5 DS18B20初始化时序2. DS18B20读写时序:图6 DS18B20读写时序3.2.5 数据处理高速暂存存储器由9个字节组成,其分配如表5所示。当温度转换命令发布后,经转换所得的温度值以二字节补码形式存放在 高速暂存存储器的第0和第1个字节。单片机可通过单线接口读到该数据,读取时低位在前,高位在后。图7 字节分配下表为12位转化后得到的12位数据,存储在18B20的两个8比特的RAM中,二进制中的前面5位是符号位,如果测得的温度大于0, 这5位为0,只要将测到的数值乘于0.0625即可得到实际温度;如果温度小于0,这5位为1,测到的数值需要取反加1再乘于0.0625即可得到实际 温度。 例如+125的数字输出为07D0H,实际温度=07D0H*0.0625=2000*0.0625=125。例如-55的数字输出为FC90H,则应先将11位数据位取反加1得370H(符号位不变,也不作运算),实际温度=370H*0.0625=880*0.0625=55。可见其中低四位为小数位。图8 DS18B20温度数据表3.3 显示电路LED数码管显示采用动态扫描方式,能简化电路布线,节约单片机I/O端口。段码和位码由单片机P0送出,分别用74HC673N锁存。图9 数码管驱动显示电路3.4 声光报警电路当温度超过设定温度值时,实现声光报警,蜂鸣器鸣叫、8个发光二极管点亮。蜂鸣器由单片机P23口控制,用三极管驱动,发光二极管接单片机P1口,由74HC673N锁存。图10 声光报警电路3.5 键盘输入电路四个键分别连接单片机P34、P35、P36、P37构成独立式键盘,分别实现报警温度范围上下限的设定功能。图11 键盘输入电路四、软件设计4.1 主程序模块主程序需要调用3个子程序,分别为:l 实时温度显示子程序:驱动数码管把实时温度值送出在LED数码管显示l 查询记录温度值子程序:查询过去存储的温度值,最多可查询10个值l 温度设定、报警子程序:设定报警温度值,当温度超过该值时产生报警,即驱动蜂鸣器鸣叫、8个发光二极管发光主程序流程图:开始定时器初始化、启动显示实时温度温度设定、报警查询记录温度值图12 主程序流程图4.2 读温度值模块读温度值模块需要调用4个子程序,分别为:l DS18B20初始化子程序:让单片机知道DS18B20在总线上且已准备好操作l DS18B20写字节子程序:对DS18B20发出命令l DS18B20读字节子程序:读取DS18B20存储器的数据l 延时子程序:对DS18B20操作时的时序控制1. 读温度值模块流程图:入口数据转换处理读取温度值高低位跳过读序列号DS18B20初始化延时启动温度转换跳过读序列号DS18B20初始化返回图13 读温度值子程序流程图 2. DS18B20初始化子程序流程图:入口DQ为低电平?延时1560msDQ拉高电平延时480msDQ复位0稍延时DQ置高电平N返回Y图14 DS18B20初始化子程序流程图3. DS18B20写字节和读字节子程序流程图: 图15 DS18B20写字节子程序流程图图16 DS18B20读字节子程序流程图4.3 中断模块中断采用T0方式1,初始值定时为50ms。中断模块需调用两个子程序:l 读温度值子程序:定时读取温度值,实时更新温度值l 记录温度值子程序:定时记录温度值,供查询使用把这两个子程序放在中断的原因是,不会因为调整报警温度或查询历史温度值而停止更新温度值和记录温度值。中断模块流程图:1秒?计数值加1定时器重置初值中断入口读温度值Y中断返回记录温度值 N图17中断模块流程图4.4 温度查询模块温度查询模块需要接受按键输入,进入查询界面后,按加减键分别查询上一个和下一个历史温度值,并驱动数码管显示需要查询的温度值。温度查询模块流程图如下:入口功能键按下? N确认按下?延时消抖 YN显示温度值与位次 Y加键按下?N确认按下?延时消抖 Y查询下一个值Y减键按下? NN查询上一个值确认按下?延时消抖 YY退出功能键按下? NN返回 Y图18 温度查询模块流程图4.5 温度设定、报警模块此模块跟温度查询模块类似,需要接受按键输入,进入模块界面后,按加减键分别上调和下调设定报警温度值,当实时温度值超过设定值时驱动蜂鸣器发声,并点亮8位发光二极管,实现声光报警。温度设定、报警模块流程图如下:入口延时消抖减键按下?确认按下?延时消抖加键按下?显示设定温度值确认按下?延时消抖功能键按下?N YN YN Y上调设定值Y NN Y下调设定值确认按下?Y N声光报警温度超出设定值?Y N取消报警判断退出界面?N Y返回图19 温度设定、报警模块流程图4.6 数码管驱动模块本设计数码管通过锁存器接单片机P0口,采用动态扫描驱动7段LED数码管进行显示,需调用延时子程序以稳定显示。模块流程图如下:P0清零关位选送位码开位选P0置高关段选入口开段选延时关段选送段码返回图20 数码管驱动模块流程图五、总结此次课程设计中,难点在于DS18B20的使用,即对它的时序控制、初始化以及字节读写方法,任何一个环节出错或是时序控制不到位的话就不能得到正确的数据。一旦学会了正确的使用方法,就能感觉到它带来的便利是热电偶不能比拟的,以后再次使用的话就能很快上手了。软件设计中,把程序按功能分模块的话能提高编程效率,把问题一一解决,同时画流程图能帮助理清思路,使问题简单化。定义变量时,尽量定义局部变量,在字符型变量能达到要求的情况下就不用定义成整形变量了,以节省内存空间。同时局部变量应避免与全局变量取同名,否则全局变量将被屏蔽或与局部变量相冲突而达不到设计的效果。另一方面,取变量名时也要讲究技巧,应尽量使其见名知意,同样地,写程序时加注释确是非常必要的,否则隔一段时间后,想再改进或做扩展的话就比较困难了,因为即使是自己写的程序也变得难读难懂了。在做键盘消抖时,延时的时间比较重要,一般为10ms左右,延时太短就会使按键太过灵敏,按一下就使数字跳变几次;而延时过长则可能使按键按下了却无响应,在外部定义初始化一个延时函数的入口参量则能很方便地调整延时时间,以达到比较好的效果。另外,如果对按键进行释放判断的话就能解决长时间按键导致按键重复响应的问题。此设计中没有为温度的单位(摄氏度)准备专用的数码管来显示,若单独用一个数码管显示“C”来代替“”的话,看起来感觉很别扭。偶然想起如若用一个数码管的上半部显“0”,即a、b、f、g段点亮,来代替“”左上角的“度”的话,效果应该不错,便作了一试,发现这是确是一个很好的主意,便在此次设计中采用了这个办法来显示温度单位。另外此次设计也考虑了实时温度显示界面与报警温度设置界面的区别,即在进入报警温度设置界面时,让其余的数码管都显示出一横杠,即g段点亮,这样则不会让两个界面相互混淆。总的来说,自己从这次独立的课程设计中收获了一些知识与经验,一些从书本中学之不来的东西,不是说理论无用,而这恰恰是在理论的土壤中开出的花朵,是在理论的肩膀望见的更宽广的道路!成功来之不易,自主动手动脑实践,小小的成果亦能带来硕大的喜悦!参考文献:1. 徐玮. C51单片机高效入门(第2版). 北京:机械工业出版社,2010.2. 龙脉工作室,刘鲲,孙春亮(修订版). 北京:人们邮电出版社,2010.为你提供优秀的毕业论文参考资料,请您删除以下内容,O(_)O谢谢!2 Many people have the same mixed feelings when planning a trip during Golden Week. With heaps of time, the seven-day Chinese为你提供优秀的毕业论文设计参考资料,请您删除一下内容,O(_)O谢谢!National Day holiday could be the best occasion to enjoy a destination. However, it can also be the easiest way to ruin how you feel about a place and you may become more fatigued after the holiday, due to battling the large crowds. During peak season, a dream about a place can turn to nightmare without careful planning, especially if you travel with children and older people. As most Chinese people will take the holiday to visit domestic tourist destinations, crowds and busy traffic are inevitable at most places. Also to be expected are increasing transport and accommodation prices, with the possibility that there will be no rooms available. It is also common that youllwait in the line for one hour to get a ticket, and another two hours at the site, to only see a tiny bit of the place due to the crowds. Last year, 428 million tourists traveled in China over the week-long holiday in October. Traveling during this period is a matter that needs thorough preparation. If you are short on time to plan the upcoming Golden Week it may not be a bad idea to avoid some of the most crowded places for now. There is always a place so fascinating that everyone yearns for. Arxan is a place like this. The beauty of Arxan is everlasting regardless of the changing of four seasons. Bestowed by nature, its spectacular seasonal landscape and mountains are just beyond word. Arxan is a crucial destination for the recommended travelling route, China Inner Mongolia Arxan Hailar Manzhouli. It is also the joint of the four prairies across the Sino-Mongolian border, where people gravitate towards the exotic atmosphere mixed with Chinese, Russian, and Mongolia elements. As a historic site for the Yitian Battle, Arxan still embodies the spirit of Genghis Khan. Walking into Arxan, you will be amazed by a kaleidoscope of gorgeous colors all the year round - the Spring azaleas blooming red in the snow, the Summer sea wavering blue in the breeze, the Autumn leaves painted in yellow covering volcanic traces, and the Winter woods shining white on the vast alpine snowscape. Hinggan League Arxan city is situated in the far eastern area of Inner Mongolia Autonomous Region. Its full name Haren Arxan means hot holy water in the Mongolian language. Arxan is a tourism city in the northern frontier with a blend of large forest, grand prairies, vast snowfield, heaven lake cluster, thermium, as well as volcanic cluster. It is a rare and unique ecotourism base filled with healthy sunshine, clean air and unspoiled green. Nestled close to the countrys largest virgin forest, and known for its spring and ecological environment, Arxan is marveled at by many tourists as the purest land on earth. You cannot miss out the Autumn of Arxan. It is definitely the best with brightly-colored scenery full of emotions. Autumn in the northern part of the country comes earlier than the South. A September rain followed by the footprints of Autumn brings more colors to the once emerald green mountain and blooming grassland. Shutterbugs flock to see for themselves the marvel of splendid colors around the mountains and waters, many of whom have travel a long distance and even camp here only to capture a moment of the nature wonder. The silver birch turns golden, while the larch is still proudly green. You will find yourself drowned in the intoxicating red of the wild fruits as well as the glamour of flowers in full blown. And your heart will be lingering on the woods as its time for the wild fruits to ripe. The picturesque Arxan in Autumn is indeed a fairyland only exists in a dream that satisfies all your fantasies. If itrains heavily on Saturday night, some elderly Chinese will say it is because Zhinu, or the Weaving Maid, is crying on the day she met her husband Niulang, or the Cowherd, on the Milky Way. Most Chinese remember being told this romantic tragedy when they were children on Qixi, or the Seventh Night Festival, which falls on the seventh day of the seventh lunar month, which is usually in early August. This year it falls on Saturday, August 2. Folklore Story As the story goes, once there was a cowherd, Niulang, who lived with his elder brother and sister-in-law. But she disliked and abused him, and the boy was forced to leave home with only an old cow for company. The cow, however, was a former god who had violated imperial rules and was sent to earth in bovine form. One day the cow led Niulang to a lake where fairies took a bath on earth. Among them was Zhinu, the most beautiful fairy and a skilled seamstress. The two fell in love at first sight and were soon married. They had a son and daughter and their happy life was held up as an example for hundreds of years in China. Yet in the eyes of the Jade Emperor, the Supreme Deity in Taoism, marriage between a mortal and fairy was strictly forbidden. He ordered the heaven troop to catch Zhinu back. Niulang grew desperate when he discovered Zhinu had been taken back to heaven. Driven by Niulangs misery, the cow told him to turn its hide into a pair of shoes after it died. The magic shoes whisked Niulang, who carried his two children in baskets strung from a shoulder pole, off on a chase after the empress. The pursuit enraged the empress, who took her hairpin and slashed it across the sky creating the Milky Way which separated husband from wife. But all was not lost as magpies, moved by their love and devotion, formed a bridge across the Milky Way to reunite the family. Even the Jade Emperor was touched, and allowed Niulang and Zhinu to meet once a year on the seventh night of the seventh month. This is how Qixi came to be. The festival can be traced back to the Han Dynasty (206 BC-AD 220). Traditionally, people would look up at the sky and find a bright star in the constellation Aquila as well as the star Vega, which are identified as Niulang and Zhinu. The two stars shine on opposite sides of the Milky Way. Customs In bygone days, Qixi was not only a special day for lovers, but also for girls. It is also known as the Begging for Skills Festival or Daughters Festival. In this day, girls will throw a sewing needle into a bowl full of water on the night of Qixi as a test of embroidery skills. If the needle floats on top of the water instead of sinking, it proves the girl is a skilled embroiders. Single women also pray for finding a good husband in the future. And the newly married women pray to become pregnant quickly. Tradition transformed The love story of Niulang and Zhinu, and the Qixi Festival have been handed down for generations. Yet these ancient traditions and customs are slowly dying out. Many modern Chinese, particularly youngsters, seem to know more about St Valentines Day on February 14, characterized by bouquets of roses, chocolates and romantic candlelight dinners, than they do about their home-grown day for lovers. Even Qixi is nowadays referred to as the Chinese Valentines Day. More and more young Chinese people begin to celebrate this day in a very similar way as that in western countries. Fewer people than ever will gaze at the heavens on Saturday to pick out the two stars shining bright on either side of the Milky Way, that is, if people even know on which day Qixi falls. There are ready reminders dotted about, in the form of big ads saying Sales on Chinese Valentines Day! in shops, hotels and restaurants. But few young women will mark the festival with their boyfriends, or take part in traditional activities to pray for cleverness. A large-scale of exhibition on the Silk Road opened to the public in the National Museum on Thursday. The exhibition displays more than 400 treasures from Shaanxi province, Gansu province and 14 other regions. It is largest scale exhibition that shows the history of the Silk Road in recent years. AsAPECis going on in Beijing, the exhibit aims to show the world this brilliant section of history. The Silk Road is a series of trade and cultural transmission routes that were central to cultural interaction through regions of the Asian continent. It connected the West and East by linking traders, merchants, pilgrims, monks, soldiers, nomads, and urban dwellers from China and India to the Mediterranean Sea during various periods of time. I met my dear hubby in 2009 the second year I was in my school and it was the first year when he came here. We became colleagues. And there was nothing special happening during that year. He was just a kind and humble brother graduated from the same college as me. But we did not know each other till he became my colleague and his office desk was just in front of me. There was only a glass between us. So actually we could see each other when we both look up. But it is not the main reason that really draws us close. How we become close to each other was something seems quite natural. We went out to play badminton with other colleagues and we sometimes chatted for a while. He is a man of few words but somehow sometimes will say something really humorous. Then one day, to my great surprise, I found a pot of beautiful flower on my desk. It was just the flower I had talked about with my colleague the other day, and I thought it was her who put the flower there. But the truth is not. It was the humble guy sitting in front of me. He just simply said ,”well, I caught sight of this flower and thought that its beautiful and you may like it”. I wonder why I was moved because of these simple words and present. Maybe it is the sincerity and the true self that impress me. I thanked him and some colleagues walked past my desk would appreciate the beautiful flower and they noticed that something romance happened there. Then later on, there were some little surprises once in a while. Once, there was something wrong with my drawer and I had complained about it unconsciously. And he fixed it for me. Then the other day, he placed several pink diamond roses beside the flower with a piece of paper saying” I love you more than I can say! Diamond stands for marriage, rose stand for love. I hope you are mine, become my wife. You are the only girl who I really want to spend the rest of my life to stand by.” Although there were some grammar errors but I got what he meant. He meant so clear and so direct. And actually, I accepted him some days earlier. I was just waiting for him to break the ice. So finally, the common interests and the common understanding brought us together. Some people say the relationship and the feeling will change after getting hitched. You will find that love is no longer strong and there is always lack of passion and whats worse you may find out many bad habits of your partner, which never appear when you are first in love before the marriage. It seems that many faults turn up after you truly living together and see each others face the moment you open your eyes in the ear
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 入职安全生产培训内容课件
- 重庆混凝土管理办法
- 集团相关方管理办法
- 拆迁安置补偿委托合同6篇
- 企业挂牌安全培训课件
- 纪检办案经费管理办法
- 社区私房占用管理办法
- 手术增强现实临床验证-洞察及研究
- 小学法律知识竞赛试题(附答案)
- 2025年应聘书、入职表可视为合同文件吗
- 海天注塑机全参数DOC资料全
- Test Plan Template:测试计划模板
- (完整版)三年级下册数学开学第一课ppt
- 苏教版四年级科学上册全册课件
- JJF1101-2019环境试验设备温度、湿度校准规范-(高清现行)
- 人教版新教材高中物理实验汇总及答案详解
- 中班语言《大狮子和小老鼠》课件
- TSG11-2020 锅炉安全技术规程
- 资助业务工作培训
- 《足球运动发展史》PPT课件
- IPQAM调制器操作说明书(共36页)
评论
0/150
提交评论