找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 5384|回复: 5
打印 上一主题 下一主题
收起左侧

基于C51的数字温度计设计(带protues仿真)

[复制链接]
跳转到指定楼层
楼主
C51的数字温度计仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)



单片机源程序如下:
  1. #include<reg52.h>
  2. #include"1602.h"
  3. #include"ds18b20.h"
  4. #define uint unsigned int
  5. #define uchar unsigned char
  6. sbit speaker=P2^4;
  7. sbit red=P2^5;
  8. sbit green=P2^6;
  9. sbit key1=P3^0;
  10. sbit key2=P3^1;

  11. uint tem;
  12. int htem,ltem;
  13. uchar mode;
  14. uchar code t3[]={" high temp:  . C"};
  15. uchar code t4[]={" low temp:  . C "};

  16. void display(uint dat,uchar add)
  17. {
  18. uchar bai,shi ,ge;
  19. bai=dat/100;
  20. shi=dat%100/10;
  21. ge=dat%10;                                                                                   
  22. writelcd_cmd(add);
  23. writelcd_dat(bai+0x30);
  24. writelcd_dat(shi+0x30);
  25. writelcd_cmd(add+3);
  26. writelcd_dat(ge+0x30);
  27. }
  28. void keyscan()
  29. {  uchar i,j;
  30.    writelcd_cmd(0x80);
  31.    for(i=0;i<16;i++)
  32.    {writelcd_dat(t3[i]);}
  33.    writelcd_cmd(0xc0);
  34.    for(j=0;j<16;j++)
  35.    {writelcd_dat(t4[j]);}
  36.    
  37.    
  38.    while(mode!=0)
  39.    {
  40. display(htem,0x8b);
  41. display(ltem,0xca);
  42.    while(mode!=0)
  43.    {
  44.            switch(mode)
  45.            {
  46.            case 1:writelcd_cmd(0xc0+13);writelcd_cmd(0x0f);break;
  47.            case 2:writelcd_cmd(0xc0+11);writelcd_cmd(0x0f);break;
  48.            case 3:writelcd_cmd(0xc0+10);writelcd_cmd(0x0f);break;
  49.            case 4:writelcd_cmd(0x80+14);writelcd_cmd(0x0f);break;
  50.            case 5:writelcd_cmd(0x80+12);writelcd_cmd(0x0f);break;
  51.            case 6:writelcd_cmd(0x80+11);writelcd_cmd(0x0f);break;
  52.            default:mode=0;break;
  53.            }
  54.           if(key1==0)
  55.           {
  56.           delay(10);
  57.           if(key1==0)
  58.                   {
  59.                   while(key1==0);
  60.                    switch(mode)
  61.                    {
  62.                    case 1:ltem=ltem+1;if(ltem>999)ltem=999;if(ltem>=htem)ltem=htem-1;display(ltem,0xca);writelcd_cmd(0xc0+13);break;
  63.                    case 2:ltem=ltem+10;if(ltem>999)ltem=999;if(ltem>=htem)ltem=htem-1;display(ltem,0xca);writelcd_cmd(0xc0+11);break;
  64.                    case 3:ltem=ltem+100;if(ltem>999)ltem=999;if(ltem>=htem)ltem=htem-1;display(ltem,0xca);writelcd_cmd(0xc0+10);break;
  65.                    case 4:htem=htem+1;if(htem>999)htem=999;if(htem<=ltem)htem=ltem+1;display(htem,0x8b);writelcd_cmd(0xc0+14);break;
  66.                    case 5:htem=htem+10;if(htem>999)htem=999;if(htem<=ltem)htem=ltem+1;display(htem,0x8b);writelcd_cmd(0xc0+12);break;
  67.                    case 6:htem=htem+100;if(htem>999)htem=999;if(htem<=ltem)htem=ltem+1;display(htem,0x8b);writelcd_cmd(0xc0+11);break;
  68.                    default:break;
  69.                    }
  70.                   }
  71.           }
  72.           if(key2==0)
  73.           {
  74.           delay(10);
  75.           if(key2==0)
  76.                   {
  77.                   while(key2==0);
  78.                    switch(mode)
  79.                    {
  80.                    case 1:ltem=ltem-1;if(ltem<0)ltem=0;if(ltem>=htem)ltem=htem-1;display(ltem,0xca);writelcd_cmd(0xc0+13);break;
  81.                    case 2:ltem=ltem-10;if(ltem<0)ltem=0;if(ltem>=htem)ltem=htem-1;display(ltem,0xca);writelcd_cmd(0xc0+11);break;
  82.                    case 3:ltem=ltem-100;if(ltem<0)ltem=0;if(ltem>=htem)ltem=htem-1;display(ltem,0xca);writelcd_cmd(0xc0+10);break;
  83.                    case 4:htem=htem-1;if(ltem<0)htem=0;if(htem<=ltem)htem=ltem+1;display(htem,0x8b);writelcd_cmd(0xc0+14);break;
  84.                    case 5:htem=htem-10;if(ltem<0)htem=0;if(htem<=ltem)htem=ltem+1;display(htem,0x8b);writelcd_cmd(0xc0+12);break;
  85.                    case 6:htem=htem-100;if(ltem<0)htem=0;if(htem<=ltem)htem=ltem+1;display(htem,0x8b);writelcd_cmd(0xc0+11);break;
  86.                    default:break;
  87.                    }
  88.                   }
  89.           }
  90.    }
  91.   }
  92.   lcd_init();
  93. }
  94. void init()
  95. {
  96.   lcd_init();
  97.    speaker=1;
  98.    red=0;
  99.    green=0;
  100.    mode=0;
  101.    htem=360;
  102.    ltem=270;
  103.    EA=1;
  104.    EX0=1;
  105.    ET0=1;
  106.    TMOD=0X01;
  107.    IT0=1;
  108.    TH0=0XFD;
  109.    TL0=0X81;
  110. }

  111. void main()
  112. {  
  113.          init();
  114.         while(1)
  115.         {  
  116.                 if(mode!=0)
  117.                 {keyscan();}
  118.         else if(mode==0)
  119.                 {        
  120.                     delay(100);
  121.                     tmpchange();
  122.                         tem=tmp();
  123.                         if(tem<=ltem){red=0;green=1;TR0=1;}
  124.                         else if(tem>=htem){green=0;red=1;TR0=1;}
  125.                         else
  126.                         {
  127.                         TR0=0;
  128.             red=0;
  129.             green=0;
  130.                         }
  131.                         delay(10);
  132.                     display(tem,0xca);
  133.                     delay(100);
  134. ……………………

  135. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

Keil5代码与Proteus7.8仿真下载:
备份_20130528112004.zip (103.34 KB, 下载次数: 157)


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏2 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:329570 发表于 2018-5-14 14:50 | 只看该作者
这个是Proteus7.8版本的文件
回复

使用道具 举报

板凳
ID:108622 发表于 2019-3-28 20:17 | 只看该作者
下载玩玩:……
回复

使用道具 举报

地板
ID:522603 发表于 2019-5-6 11:39 | 只看该作者
给力!对我和有帮助
回复

使用道具 举报

5#
ID:519483 发表于 2019-5-6 22:23 | 只看该作者
给力,有用
回复

使用道具 举报

6#
ID:742391 发表于 2020-5-27 09:42 | 只看该作者
这个用的是Proteus7.8版本
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表