找回密码
 注册

QQ登录

只需一步,快速开始

搜索

基于51单片机的水温PID控制恒温系统Proteus仿真和C源程序

[复制链接]
eng 发表于 2021-6-14 03:14:42 | 显示全部楼层 |阅读模式
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
1.png

部分C源码,完整程序请下载附件
  1. void lcdnumdisplays(uchar pos,float f)                //(0.001-99999) 精度低 但方便数据更新
  2. {  
  3.    uchar i;
  4.    writecom(pos);
  5.    if(f>65535&&f<0.001) for(i=0;i<5;i++)writedata(0x23);//超出范围 显示#
  6.    else if(f==0){writedata(0x30);for(i=0;i<4;i++)writedata(0x20);}
  7.    else
  8.      {
  9.            if((uint)f/10000!=0)
  10.            {
  11.             writedata((uint)f/10000+0x30);
  12.             writedata((uint)f%10000/1000+0x30);
  13.                 writedata((uint)f%1000/100+0x30);
  14.                 writedata((uint)f%100/10+0x30);
  15.                 writedata((uint)f%10+0x30);
  16.            }
  17.            else
  18.            {
  19.             if((uint)f/1000!=0)
  20.                 {
  21.                 writedata(0+0x30);
  22.             writedata((uint)f/1000+0x30);
  23.                 writedata((uint)f%1000/100+0x30);
  24.                 writedata((uint)f%100/10+0x30);
  25.                 writedata((uint)f%10+0x30);
  26.                 }
  27.                 else
  28.                 {
  29.                   if((uint)f/100!=0)
  30.                   {
  31.                     writedata((uint)f/100+0x30);
  32.                            writedata((uint)f%100/10+0x30);
  33.                     writedata((uint)f%10+0x30);
  34.                         writedata(0x2e);
  35.                         writedata((uint)(f*10)%10+0x30);
  36.                   }
  37.                   else
  38.                   {
  39.                     if((uint)f/10!=0)
  40.                         {
  41.                         writedata((uint)f/10+0x30);
  42.                         writedata((uint)f%10+0x30);
  43.                         writedata(0x2e);
  44.                         writedata((uint)(f*10)%10+0x30);
  45.                         writedata((uint)(f*100)%10+0x30);
  46.                         }
  47.                         else
  48.                         {
  49.                         writedata((uint)f%10+0x30);
  50.                         writedata(0x2e);
  51.                         writedata((uint)(f*10)%10+0x30);
  52.                         writedata((uint)(f*100)%10+0x30);
  53.                         writedata((uint)(f*1000)%10+0x30);
  54.                         }
  55.                   }
  56.                  }
  57.            }
  58.          }
  59. }


  60. //lcd显示数据2
  61. void lcdnumdisplay(uchar pos,float f0)                //(0.00001-99999.99999) 精度高 但数据需刷屏更新
  62. {
  63.    uchar temp;
  64.    ulong    f;
  65.    writecom(pos);
  66.    f=(ulong)f0;
  67.    temp=f/10000;         //整数部分
  68.    if(temp!=0)
  69.      {
  70.             writedata(temp+0x30);
  71.                 writedata(f%10000/1000+0x30);
  72.                 writedata(f%1000/100+0x30);
  73.                 writedata(f%100/10+0x30);
  74.                 writedata(f%10+0x30);
  75.          }
  76.    else
  77.      {
  78.             temp=f%10000/1000;
  79.                 if(temp!=0)
  80.                 {
  81.                    writedata(temp+0x30);
  82.                    writedata(f%1000/100+0x30);
  83.                    writedata(f%100/10+0x30);
  84.                    writedata(f%10+0x30);
  85.                 }
  86.                 else
  87.                 {
  88.                    temp=f%1000/100;
  89.                    if(temp!=0)
  90.                    {
  91.                       writedata(temp+0x30);
  92.                           writedata(f%100/10+0x30);
  93.                       writedata(f%10+0x30);
  94.                    }
  95.                    else
  96.                    {
  97.                       temp=f%100/10;
  98.                           if(temp!=0)
  99.                                 {
  100.                                    writedata(temp+0x30);
  101.                                    writedata(f%10+0x30);     
  102.                                 }
  103.                                 else
  104.                                 {
  105.                                    temp=f%10;
  106.                                    if(temp!=0)
  107.                                    {
  108.                                      writedata(temp+0x30);
  109.                                    }
  110.                                    else writedata(0+0x30);
  111.                                  }
  112.                           }  
  113.                    }
  114.                 }


  115.     if((ulong)(f0*10)%10!=0||(ulong)(f0*100)%10!=0||(ulong)(f0*1000)%10!=0||(ulong)(f0*10000)%10!=0)                  
  116.         {
  117.                       writedata(0x2e);
  118.                    temp=(ulong)(f0*10000)%10;
  119.                    if(temp!=0)
  120.                    {
  121.                      writedata((ulong)(f0*10)%10+0x30);
  122.                          writedata((ulong)(f0*100)%10+0x30);
  123.                          writedata((ulong)(f0*1000)%10+0x30);
  124.                          writedata(temp+0x30);
  125.                    }
  126.                    else
  127.                    {
  128.                        temp=(ulong)(f0*1000)%10;
  129.                        if(temp!=0)
  130.                            {
  131.                              writedata((ulong)(f0*10)%10+0x30);
  132.                              writedata((ulong)(f0*100)%10+0x30);
  133.                                  writedata(temp+0x30);
  134.                            }
  135.                            else
  136.                            {
  137.                               temp=(ulong)(f0*100)%10;
  138.                                   if(temp!=0)
  139.                                   {
  140.                                     writedata((ulong)(f0*10)%10+0x30);
  141.                                         writedata(temp+0x30);
  142.                                   }
  143.                                   else
  144.                                   {
  145.                                     temp=(ulong)(f0*10)%10;
  146.                                         if(temp!=0)
  147.                                           writedata(temp+0x30);
  148.                                   }
  149.                             }            
  150.                       }
  151.                     }
  152. }
复制代码
完整程序代码和proteus仿真文件: 水温控制系统PID可调51单片机仿真.zip (100.06 KB, 售价: 5 E币)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|ELEOK |网站地图

GMT+8, 2024-4-20 15:36

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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