找回密码
 立即注册

QQ登录

只需一步,快速开始

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

单片机ne555+HS1101温湿度监测系统仿真电路与代码设计 求帮助

[复制链接]
跳转到指定楼层
楼主
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)程序编译出错


单片机HS1101源程序如下:
  1. #include<reg52.h>
  2. #include <absacc.h>
  3. #define uint unsigned int
  4. #define uchar unsigned char
  5. sbit rs=P2^0;
  6. sbit rw=P2^1;
  7. sbit en=P2^2;
  8. sbit DQ=P3^4;                //     18b20总线
  9. unsigned char  dat[9]={0};                        //温度
  10. unsigned char  shuju1[9]={0};         //湿度


  11. uchar code table1[17]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x54,0x45,0x4d,0x50,0x2d,0x2e,0x20};        //温度调用
  12. uchar code table2[16]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x53,0x48,0x49,0x25,0x2e,0x20};            //湿度调用

  13. /**************1602d调用函数*******************/
  14. void write_com(uchar com);
  15. void write_shuju(uchar shuju);
  16. void init();
  17. void delay(uchar z);

  18. /**************18b20调用函数**************/
  19. unsigned char reset(void);           //18b20初始化//
  20. void write(uchar dat);               //18b20写时序
  21. unsigned char read(void);            //18b20读时序                  
  22. void readtemperature(void);          //18b20读二进制16位温度
  23. void yanshi(unsigned int us);

  24. /****************hs1101调用函数*************************/
  25. void readfrequency(void);                        //        读频率函数//
  26. bit minrange=0;                                                //湿度下限标志位//
  27. bit maxrange=0;                                                //湿度上限标志位//
  28. bit T0Over=0;                                                //定时器结束标记


  29. unsigned char w,x,y;

  30. /******************主函数******************/
  31. void main()                                         
  32. {
  33.         init();
  34.         while(1)        
  35.         {
  36.                 readtemperature();        
  37.                 write_com(0x80);
  38.                 write_shuju(table1[dat[0]]);
  39.                 write_com(0x81);
  40.                 write_shuju(table1[dat[1]]);
  41.                 write_com(0x82);
  42.                 write_shuju(table1[dat[2]]);
  43.                 write_com(0x83);
  44.                 write_shuju(table1[dat[3]]);
  45.                 write_com(0x84);
  46.                 write_shuju(table1[dat[4]]);
  47.                 write_com(0x85);
  48.                 write_shuju(table1[dat[5]]);
  49.                 write_com(0x86);
  50.                 write_shuju(table1[dat[6]]);
  51.                 write_com(0x87);
  52.                 write_shuju(table1[dat[7]]);
  53.                 write_com(0x88);
  54.                 write_shuju(table1[dat[8]]);
  55.                 readfrequency();
  56.         }

  57.         
  58.          
  59.         
  60. }

  61. /*****************1602延时程序*****************/
  62. void delay(uchar z)
  63. {
  64.         uint a,b;
  65.         for(a=0;a<z;a++)
  66.                 for(b=0;b<110;b++);
  67. }

  68. /*******************1602初始化**************/
  69. void init()
  70. {
  71.         en=0;
  72.         write_com(0x38);                //设置为8位并行,显示2行,5*7点阵显示
  73.         write_com(0x0c);                //设置显示开 无光标 光标不闪烁
  74.         write_com(0x01);                  //清屏指令
  75.         write_com(0x80);                 
  76. }

  77. /***************1602写指令*********************/
  78. void write_com(uchar com)
  79. {
  80.         rs=0;
  81.         rw=0;
  82.         P1=com;
  83.         delay(5);
  84.         en=1;
  85.         en=0;
  86. }

  87. /**************1602写数据**********************/
  88. void write_shuju(uchar shuju)
  89. {
  90.         rs=1;
  91.         rw=0;
  92.         P1=shuju;
  93.         delay(5);
  94.         en=1;
  95.         en=0;
  96. }

  97. /*************18b20微秒延时********************/
  98. void yanshi(unsigned int us)
  99. {
  100.         int s;
  101.         for(s=0;s<us;s++);
  102. }

  103. /************************18b20初始化********/
  104. unsigned char reset(void)
  105. {
  106.         unsigned char  presence;
  107.         DQ=0;
  108.         yanshi(60);       //大概480微秒
  109.         DQ=1;
  110.         yanshi(8);                 //延时大概50微秒
  111.         presence=DQ;
  112.         yanshi(14);
  113.         return(presence);
  114. }
  115. /*************18b20写时序*************************/
  116. void write(unsigned char dat)
  117. {
  118.         unsigned char i;
  119.         for(i=8;i>0;i--)
  120.         {
  121.                 DQ=0;
  122.                 DQ=dat&0x01;
  123.                 yanshi(16);
  124.                 DQ=1;
  125.                 dat>>=1;
  126.         }
  127. }

  128. /***************18b20读时序*********************/
  129. unsigned char read(void)
  130. {
  131.         unsigned char i,dat=0;
  132.         for(i=8;i>0;i--)
  133.         {
  134.                 DQ=0;
  135.                 dat>>=1;
  136.                 DQ=1;
  137.                 if(DQ)
  138.                         dat|=0x80;
  139.                 yanshi(7);
  140.         }
  141.         return (dat);
  142. }

  143. /**************18b20读温度**********************/
  144. void readtemperature(void)
  145. {

  146.         unsigned char temp;
  147.         int temperature;
  148.         reset();
  149.         write(0xcc);
  150.         write(0x44);
  151.         reset();
  152.         write(0xcc);
  153.         write(0xbe);
  154.         temperature=read();
  155.         temp=read();
  156.         temperature=temperature|(temp<<8);
  157.         dat[0]=10;
  158.         dat[1]=11;
  159.         dat[2]=12;
  160.         dat[3]=13;
  161.         dat[4]=16;
  162.         if(temperature<0)
  163.         {
  164.                 dat[4]=14;
  165.                 temperature=~temperature+1;
  166.         }
  167.         dat[5]=(temperature*10/16)/100;
  168.         dat[6]=((temperature*10/16)%100)/10;
  169.         dat[7]=15;
  170.         dat[8]=((temperature*10/16)%100)%10;
  171. }


  172. /****************中断*****************************/
  173. void timer0() interrupt 1
  174. {
  175.         TR1=0;
  176.         TR0=0;
  177.         TF0=0;
  178.     ET0=0;
  179.     T0Over=1;
  180. }

  181. /*************湿度传感器频率采集及转换模块***************/
  182. void readfrequency()
  183. {
  184.         unsigned int ftequency,RH;
  185.         TMOD=0x51;
  186.         TH0=0x4C;
  187.         TL0=0X00;
  188.         TH1=0;
  189.         TL1=0;
  190.         TR1=1;
  191.         TR0=1;
  192.     ET0=1;
  193.     ET1=0;
  194.         EA=1;
  195.         T0Over=0;
  196.         while(!T0Over)
  197.         write_com(0x80+0x40);
  198.         write_shuju(table2[shuju1[0]]);
  199.         write_com(0x80+0x41);
  200.         write_shuju(table2[shuju1[1]]);
  201.         write_com(0x80+0x42);
  202.         write_shuju(table2[shuju1[2]]);
  203.         write_com(0x80+0x43);
  204.         write_shuju(table2[shuju1[3]]);
  205.         write_com(0x80+0x44);
  206.         write_shuju(table2[shuju1[4]]);
  207.         write_com(0x80+0x45);
  208.         write_shuju(table2[shuju1[5]]);
  209.         write_com(0x80+0x46);
  210.         write_shuju(table2[shuju1[6]]);
  211.         write_shuju(table2[shuju1[7]]);
  212.         write_shuju(table2[shuju1[8]]);
  213.         ftequency=(TH1*256+TL1)*20;
  214.         minrange=0;
  215.         maxrange=0;
  216.         if(ftequency)
  217.         {
  218.                 if(ftequency<6033)
  219.                         maxrange=1;
  220.                 if(ftequency>7351)
  221.                         minrange=1;                                       
  222. ^^^^^^^^余下见附件
复制代码

程序编译出错,求大神指导我:
温湿度检测.zip (56.43 KB, 下载次数: 58)


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

使用道具 举报

沙发
ID:998853 发表于 2022-1-3 10:16 | 只看该作者
少个大括号吧
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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