找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 6283|回复: 2
收起左侧

Si7021温湿度传感器原理图+源码+PCB全套设计资料(24c64存储,按键报警模块)

[复制链接]
ID:314623 发表于 2018-5-1 10:50 | 显示全部楼层 |阅读模式
测控技术与仪器课程设计分享:
这是一个监测Si7021温湿度的课程设计采用stc单片机  带存储模块 按键模块  报警模块    具体程序在附件里面  全套设计

Altium Designer画的Si7021温湿度报警与控制电路原理图和PCB图如下:(51hei附件中可下载工程文件)
XLVL$`A)[111U%O}RV7Y26E.png

0.png
0.jpg

57271+Si7021温湿度传感器+高精度+I2C接口的源码(arduino与单片机各平台的都有)与资料下载:
0.jpg

Si7021温湿度传感器的整个系统单片机源程序如下:
  1.    
  2.         #include "get_data.h"
  3.         //#include "L_lcd1602.h"
  4.          #include <reg52.h>

  5.   unsigned char r_24humid;
  6.   unsigned char w_24humid;
  7.   unsigned char s_24humid[3];//24C64温度量
  8.   unsigned char r_24TemperH;
  9.         unsigned char r_24TemperL;
  10.         unsigned char w_24TemperH;
  11.         unsigned char w_24TemperL;
  12.         unsigned char s_24TemperH[3];
  13.         unsigned char s_24TemperL[2]="11";//24c64湿度量
  14.         unsigned char LC;
  15.                 unsigned char LC1;
  16.                 unsigned int storaddH=0x00;
  17.                 unsigned int storaddL=0x00;
  18.                 unsigned int reaaddH=0x00;
  19.                 unsigned int reaaddL=0x00;
  20.                
  21.                 unsigned char k1value=0;
  22.                 unsigned char k2value=0;
  23.                 unsigned char k3value=0;
  24.                 unsigned char k4value=0;
  25.                
  26.                 unsigned char S_Speed=0;//采样周期档1:5 second
  27.                 unsigned char S_Speeded[2];

  28.                 extern unsigned char pageflag;
  29.                 extern int scal;
  30.                
  31. // unsigned char s_24temperd1[3];//24c64数据         
  32.          
  33. unsigned char temp_array[3]="   ";
  34. unsigned char temp_array1[2]="  ";//存小数位

  35. unsigned char Rf_Rec_Cnt;

  36. unsigned long cal_temp_u32=0;
  37. unsigned int cal_temp_u16=0;
  38. unsigned char RH_value;

  39. unsigned char TEMP_H;
  40. unsigned char TEMP_L;
  41. unsigned char gv_uart_buf[MAX_UART_BUF];
  42. unsigned char gv_uart_buflen;
  43.          
  44.         typedef        struct _si7021_value_{
  45.         union16 temp;
  46.         union16 humi;
  47.         unsigned char crc;
  48.   }si7021_value_ST, *p_si7021_value_ST;

  49. si7021_value_ST gv_si7021_value;


  50.          
  51.          void Get_temper(void)
  52.    {
  53.             measure_si7021 ( TEMP_HOLD_MASTER, (union16 *)(&gv_si7021_value.temp) );
  54.                   gv_uart_buf[2] = gv_si7021_value.temp.unchar[HSB];
  55.                   gv_uart_buf[3] = gv_si7021_value.temp.unchar[LSB];
  56.                        cal_temp_u16 = gv_uart_buf[2];
  57.                  cal_temp_u16 = cal_temp_u16 <<8;
  58.                  cal_temp_u16 += gv_uart_buf[3];
  59.                  cal_temp_u32 =  cal_temp_u16;
  60.                  cal_temp_u32 = 17572* cal_temp_u32;
  61.                  cal_temp_u32 = cal_temp_u32 >>16;
  62.                  cal_temp_u32 = cal_temp_u32 -4685;
  63.                  TEMP_H = cal_temp_u32/100;
  64.                        w_24TemperH = TEMP_H;//24c64存储
  65.                  TEMP_L = cal_temp_u32%100;
  66.                        LC = TEMP_L;//24c64存储///////////////////////
  67.                                    
  68.                  
  69.    }

  70.          
  71.          void Get_humidity()
  72.          {
  73.                   measure_si7021 ( HUMI_HOLD_MASTER, (union16 *)(&gv_si7021_value.humi) );
  74.                   gv_uart_buf[4] = gv_si7021_value.humi.unchar[HSB];
  75.                   gv_uart_buf[5] = gv_si7021_value.humi.unchar[LSB];
  76.                        cal_temp_u16 =(int*)gv_uart_buf[4];
  77.                  cal_temp_u16 = cal_temp_u16 <<8;
  78.                  cal_temp_u16 += gv_uart_buf[5];
  79.                  cal_temp_u32 =  cal_temp_u16;
  80.                  cal_temp_u32 = 125* cal_temp_u32;
  81.                  cal_temp_u32 = cal_temp_u32 >>16;
  82.                        cal_temp_u32 = cal_temp_u32-6;
  83.                  RH_value = (unsigned char*)cal_temp_u32;
  84.                        w_24humid=RH_value;//24c64存数据
  85.                        //hex_to_assic1(RH_value,temp_array);
  86.                        //write_string(0,0,"Humidity:");
  87.                        //write_string(9,0,temp_array);
  88.                         
  89.    }
  90.          
  91.          
  92.          
  93.          void showdata()
  94.          {
  95.                        hex_to_assic1(RH_value,temp_array);
  96.                        write_string(0,0,"Humidity:");
  97.                        write_string(9,0,temp_array);//湿度
  98.                        write_string(12,0,"%   ");
  99.                        hex_to_assic1(TEMP_H,temp_array);
  100.                        write_string(0,1,"Temper:");
  101.                        write_string(7,1,temp_array);////////////////////////////
  102.                                          write_string(10,1,".");
  103.                                          
  104.                                          hex_to_assic2(TEMP_L,temp_array1);
  105.                                          write_string(11,1,temp_array1);///////////温度
  106.                        write_string(13,1,"du ");
  107.    }
  108.          
  109.               void L_24c64stor(void)
  110.              {
  111.                           w_24c64_data(storaddH,storaddL,w_24humid);
  112.                          if( storaddL!=0xff )
  113.                                                    {
  114.                             storaddL=storaddL+1;
  115.                                                    }
  116.                           if( storaddL==0xff&&storaddH!=0xff )
  117.                                              {
  118.                                                      storaddH=storaddH+1;
  119.                }
  120.                                            if( storaddH==0xff)
  121.                                             {
  122.                                                       storaddH=0x00;
  123.                                                                   storaddL=0x00;
  124.               }
  125.                  //r_24c64_data(0x00,0x00,&r_24humid);
  126.                        //hex_to_assic1(r_24humid, s_24humid);
  127.                        
  128.                          w_24c64_data(storaddH,storaddL,w_24TemperH);
  129.                           if( storaddL!=0xff )
  130.                                                    {
  131.                             storaddL=storaddL+1;
  132.                                                    }
  133.                           if( storaddL==0xff&&storaddH!=0xff )
  134.                                              {
  135.                                                      storaddH=storaddH+1;
  136.                }
  137.                                             if( storaddH==0xff )
  138.                                              {
  139.                                                       storaddH=0x00;
  140.                                                                   storaddL=0x00;
  141.                }
  142.                      
  143.                        w_24c64_data(storaddH,storaddL,LC);//存温度低八位
  144.                                                          if( storaddL!=0xff )
  145.                                                    {
  146.                             storaddL=storaddL+1;
  147.                                                    }
  148.                           if( storaddL==0xff&&storaddH!=0xff )
  149.                                              {
  150.                                                      storaddH=storaddH+1;
  151.                }
  152.                                             if( storaddH==0xff )
  153.                                              {
  154.                                                       storaddH=0x00;
  155.                                                                   storaddL=0x00;
  156.                }
  157.                                                          
  158.                                                          
  159.                        //r_24c64_data(0x00,0x01,&r_24TemperH);
  160.                   
  161.                        //r_24c64_data(0x00,0x02,&LC1);////读温度低八位
  162.                        //hex_to_assic1(r_24TemperH, s_24TemperH);
  163.                        
  164.                        //hex_to_assic2(LC1, s_24TemperL);//显示温度低八位
  165.                        
  166.                  
  167.                  
  168.                  
  169.                        /*write_string(0,1,s_24humid);
  170.                        write_string(5,1,s_24TemperH);
  171.                        write_string(8,1,".");
  172.                        write_string(9,1,s_24TemperL);*/
  173.                      
  174.                     
  175.        }
  176.                         
  177.                         
  178.                          void L_24c64read(void)
  179.                          {
  180.                                  r_24c64_data(reaaddH,reaaddL,&r_24humid);
  181.                                       if( reaaddL!=0xff)
  182.                                                    {
  183.                             reaaddL=reaaddL+1;
  184.                                                    }
  185.                           if( reaaddL==0xff&&reaaddH!=0xff )
  186.                                              {
  187.                                                      reaaddH=reaaddH+1;
  188.                }
  189.                                             if(reaaddH==0xff )
  190.                                              {
  191.                                                       reaaddH=0x00;
  192.                                                                   reaaddL=0x00;
  193.                }
  194.                                                         hex_to_assic1(r_24humid, s_24humid);
  195.                                                         
  196.                                                         r_24c64_data(reaaddH,reaaddL,&r_24TemperH);//读温度高位
  197.                                      if( reaaddL!=0xff )
  198.                                                    {
  199.                             reaaddL=reaaddL+1;
  200.                                                    }
  201.                           if( reaaddL==0xff&&reaaddH!=0xff )
  202.                                              {
  203.                                                      reaaddH=reaaddH+1;
  204.                }
  205.                                            if( reaaddH==0xff )
  206.                                             {
  207.                                                       reaaddH=0x00;
  208.                                                                   reaaddL=0x00;
  209.               }
  210.                                                         hex_to_assic1(r_24TemperH, s_24TemperH);
  211.                                                         
  212.                                                         r_24c64_data(reaaddH,reaaddL,&LC1);////读温度低八位
  213.                                                          if( reaaddL!=0xff )
  214.                                                    {
  215.                             reaaddL=reaaddL+1;
  216.                                                    }
  217.                           if( reaaddL==0xff&&reaaddH!=0xff )
  218.                                              {
  219.                                                      reaaddH=reaaddH+1;
  220.                }
  221.                                             if( reaaddH==0xff )
  222.                                              {
  223.                                                       reaaddH=0x00;
  224.                                                                   reaaddL=0x00;
  225.                }
  226.                                                         hex_to_assic2(LC1, s_24TemperL);//生成显示字符串--温度低八位
  227.                                                         
  228.                          }
  229.                         
  230.                          void datapage()
  231.                          {
  232.                                  write_com(0x01);
  233.                //delayms(1);
  234.                
  235.                                  L_24c64read();
  236.                                  
  237.                                  write_string(0,0,"data:");
  238.                                  write_string(5,0,s_24humid);
  239.                                  write_string(8,0,"%");
  240.                                  write_string(9,0,s_24TemperH);
  241.                                  write_string(12,0,".");
  242.                                  write_string(13,0,s_24TemperL);
  243.                                  write_string(15,0,"D");
  244.                                  //delayms(1);
  245.                                  L_24c64read();
  246.                                  write_string(0,1,"data:");
  247.                                  write_string(5,1,s_24humid);
  248.                                  write_string(8,1,"%");
  249.                                  write_string(9,1,s_24TemperH);
  250.                                  write_string(12,1,".");
  251.                                  write_string(13,1,s_24TemperL);
  252.                                  write_string(15,1,"D");
  253.                                  //while((!k1value)||(!k4value));
  254.                                  k3value=0;
  255.                                  k4value=0;
  256.                                  while((!k3value)&&(!k4value))//K4 fanye K-3结束
  257.                                  {
  258.                                                            keyvalue();
  259.          }
  260.        }
  261.                         
  262.                         
  263.                         
  264.                          void speedpage()
  265. {
  266.                                  write_com(0x01);
  267.                delayms(1);
  268.                                  write_string(0,0,"Sample_Speed:");
  269.                                  hex_to_assic2(S_Speed, S_Speeded);
  270.                                  write_string(6,1,S_Speeded);
  271.                                  //write_string(0,1,"Back_light:");
  272.                                  //write_string(12,1,"off");
  273.                         while((!k1value))
  274.                                 {
  275.                                          //k1value
  276.                                    keyvalue();
  277.                                          if(k2value==1)
  278.                                  {
  279.                                          k2value=0;
  280.                                          if(S_Speed==3) S_Speed=0;
  281.                                          else S_Speed=S_Speed+1;
  282.                                          hex_to_assic2(S_Speed, S_Speeded);
  283.                                          write_string(6,1,S_Speeded);
  284.                                           if(S_Speed==0) scal=100;
  285.                                                 if(S_Speed==1) scal=6000;         
  286.                                     if(S_Speed==2) scal=12000;
  287.                                                 if(S_Speed==3) scal=36000;
  288.                                          
  289.          }
  290.                                   /*if(k4value==1)
  291.                                  {
  292.                                          k4value=0;
  293.                                          if(S_Speed>=1)
  294.                                          {
  295.                                          S_Speed=S_Speed-1;
  296.                                          }
  297.                                          hex_to_assic2(S_Speed, S_Speeded);
  298.                                          write_string(12,0,S_Speeded);
  299.          }
  300.                                  if(k2value==1)
  301.                                  {
  302.                                          k2value=0;
  303.                                          Back_light=1;
  304.                                          //hex_to_assic2(S_Speed, S_Speeded);
  305.                                         write_string(12,1,"on ");
  306.          }*/
  307.                                  
  308.                                  delayms(200);
  309.                                          
  310.                         }
  311.                                  
  312.                                 
  313.                                  
  314.         
  315.                                  
  316. }
  317.                         
  318.                 void Timer0Init(void)                //500??@11.0592MHz
  319.   {
  320.             TMOD = 0x01;  //???16???????
  321.             TH0 =0x4b;
  322.             TL0 =0xfd; //50ms
  323.             ET0 = 1; //????0??
  324.             TR0 = 1;//?????0
  325.             EA = 1;        //????
  326. }


  327. void keyint()
  328. {
  329.          K1=1;
  330.          K2=1;
  331. ……………………

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

所有资料51hei提供下载:
温湿度传感器设计.rar (9.38 MB, 下载次数: 129)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:328033 发表于 2018-5-12 10:42 | 显示全部楼层
这个有介绍哪个部分是什么功能的吗
回复

使用道具 举报

ID:185372 发表于 2020-6-29 13:08 | 显示全部楼层
先下载来瞧瞧,感谢一下
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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