測控技術與儀器課程設計分享:
這是一個監測Si7021溫濕度的課程設計采用stc單片機 帶存儲模塊 按鍵模塊 報警模塊 具體程序在附件里面 全套設計
Altium Designer畫的Si7021溫濕度報警與控制電路原理圖和PCB圖如下:(51hei附件中可下載工程文件)
XLVL$`A)[111U%O}RV7Y26E.png (21.4 KB, 下載次數: 55)
下載附件
2018-5-1 10:49 上傳
0.png (50.28 KB, 下載次數: 48)
下載附件
2018-5-2 00:46 上傳
0.jpg (22.41 KB, 下載次數: 39)
下載附件
2018-5-2 00:47 上傳
57271+Si7021溫濕度傳感器+高精度+I2C接口的源碼(arduino與單片機各平臺的都有)與資料下載:
0.jpg (25.04 KB, 下載次數: 51)
下載附件
2018-5-2 00:49 上傳
Si7021溫濕度傳感器的整個系統單片機源程序如下:
-
- #include "get_data.h"
- //#include "L_lcd1602.h"
- #include <reg52.h>
- unsigned char r_24humid;
- unsigned char w_24humid;
- unsigned char s_24humid[3];//24C64溫度量
- unsigned char r_24TemperH;
- unsigned char r_24TemperL;
- unsigned char w_24TemperH;
- unsigned char w_24TemperL;
- unsigned char s_24TemperH[3];
- unsigned char s_24TemperL[2]="11";//24c64濕度量
- unsigned char LC;
- unsigned char LC1;
- unsigned int storaddH=0x00;
- unsigned int storaddL=0x00;
- unsigned int reaaddH=0x00;
- unsigned int reaaddL=0x00;
-
- unsigned char k1value=0;
- unsigned char k2value=0;
- unsigned char k3value=0;
- unsigned char k4value=0;
-
- unsigned char S_Speed=0;//采樣周期檔1:5 second
- unsigned char S_Speeded[2];
- extern unsigned char pageflag;
- extern int scal;
-
- // unsigned char s_24temperd1[3];//24c64數據
-
- unsigned char temp_array[3]=" ";
- unsigned char temp_array1[2]=" ";//存小數位
- unsigned char Rf_Rec_Cnt;
- unsigned long cal_temp_u32=0;
- unsigned int cal_temp_u16=0;
- unsigned char RH_value;
- unsigned char TEMP_H;
- unsigned char TEMP_L;
- unsigned char gv_uart_buf[MAX_UART_BUF];
- unsigned char gv_uart_buflen;
-
- typedef struct _si7021_value_{
- union16 temp;
- union16 humi;
- unsigned char crc;
- }si7021_value_ST, *p_si7021_value_ST;
- si7021_value_ST gv_si7021_value;
-
- void Get_temper(void)
- {
- measure_si7021 ( TEMP_HOLD_MASTER, (union16 *)(&gv_si7021_value.temp) );
- gv_uart_buf[2] = gv_si7021_value.temp.unchar[HSB];
- gv_uart_buf[3] = gv_si7021_value.temp.unchar[LSB];
- cal_temp_u16 = gv_uart_buf[2];
- cal_temp_u16 = cal_temp_u16 <<8;
- cal_temp_u16 += gv_uart_buf[3];
- cal_temp_u32 = cal_temp_u16;
- cal_temp_u32 = 17572* cal_temp_u32;
- cal_temp_u32 = cal_temp_u32 >>16;
- cal_temp_u32 = cal_temp_u32 -4685;
- TEMP_H = cal_temp_u32/100;
- w_24TemperH = TEMP_H;//24c64存儲
- TEMP_L = cal_temp_u32%100;
- LC = TEMP_L;//24c64存儲///////////////////////
-
-
- }
-
- void Get_humidity()
- {
- measure_si7021 ( HUMI_HOLD_MASTER, (union16 *)(&gv_si7021_value.humi) );
- gv_uart_buf[4] = gv_si7021_value.humi.unchar[HSB];
- gv_uart_buf[5] = gv_si7021_value.humi.unchar[LSB];
- cal_temp_u16 =(int*)gv_uart_buf[4];
- cal_temp_u16 = cal_temp_u16 <<8;
- cal_temp_u16 += gv_uart_buf[5];
- cal_temp_u32 = cal_temp_u16;
- cal_temp_u32 = 125* cal_temp_u32;
- cal_temp_u32 = cal_temp_u32 >>16;
- cal_temp_u32 = cal_temp_u32-6;
- RH_value = (unsigned char*)cal_temp_u32;
- w_24humid=RH_value;//24c64存數據
- //hex_to_assic1(RH_value,temp_array);
- //write_string(0,0,"Humidity:");
- //write_string(9,0,temp_array);
-
- }
-
-
-
- void showdata()
- {
- hex_to_assic1(RH_value,temp_array);
- write_string(0,0,"Humidity:");
- write_string(9,0,temp_array);//濕度
- write_string(12,0,"% ");
- hex_to_assic1(TEMP_H,temp_array);
- write_string(0,1,"Temper:");
- write_string(7,1,temp_array);////////////////////////////
- write_string(10,1,".");
-
- hex_to_assic2(TEMP_L,temp_array1);
- write_string(11,1,temp_array1);///////////溫度
- write_string(13,1,"du ");
- }
-
- void L_24c64stor(void)
- {
- w_24c64_data(storaddH,storaddL,w_24humid);
- if( storaddL!=0xff )
- {
- storaddL=storaddL+1;
- }
- if( storaddL==0xff&&storaddH!=0xff )
- {
- storaddH=storaddH+1;
- }
- if( storaddH==0xff)
- {
- storaddH=0x00;
- storaddL=0x00;
- }
- //r_24c64_data(0x00,0x00,&r_24humid);
- //hex_to_assic1(r_24humid, s_24humid);
-
- w_24c64_data(storaddH,storaddL,w_24TemperH);
- if( storaddL!=0xff )
- {
- storaddL=storaddL+1;
- }
- if( storaddL==0xff&&storaddH!=0xff )
- {
- storaddH=storaddH+1;
- }
- if( storaddH==0xff )
- {
- storaddH=0x00;
- storaddL=0x00;
- }
-
- w_24c64_data(storaddH,storaddL,LC);//存溫度低八位
- if( storaddL!=0xff )
- {
- storaddL=storaddL+1;
- }
- if( storaddL==0xff&&storaddH!=0xff )
- {
- storaddH=storaddH+1;
- }
- if( storaddH==0xff )
- {
- storaddH=0x00;
- storaddL=0x00;
- }
-
-
- //r_24c64_data(0x00,0x01,&r_24TemperH);
-
- //r_24c64_data(0x00,0x02,&LC1);////讀溫度低八位
- //hex_to_assic1(r_24TemperH, s_24TemperH);
-
- //hex_to_assic2(LC1, s_24TemperL);//顯示溫度低八位
-
-
-
-
- /*write_string(0,1,s_24humid);
- write_string(5,1,s_24TemperH);
- write_string(8,1,".");
- write_string(9,1,s_24TemperL);*/
-
-
- }
-
-
- void L_24c64read(void)
- {
- r_24c64_data(reaaddH,reaaddL,&r_24humid);
- if( reaaddL!=0xff)
- {
- reaaddL=reaaddL+1;
- }
- if( reaaddL==0xff&&reaaddH!=0xff )
- {
- reaaddH=reaaddH+1;
- }
- if(reaaddH==0xff )
- {
- reaaddH=0x00;
- reaaddL=0x00;
- }
- hex_to_assic1(r_24humid, s_24humid);
-
- r_24c64_data(reaaddH,reaaddL,&r_24TemperH);//讀溫度高位
- if( reaaddL!=0xff )
- {
- reaaddL=reaaddL+1;
- }
- if( reaaddL==0xff&&reaaddH!=0xff )
- {
- reaaddH=reaaddH+1;
- }
- if( reaaddH==0xff )
- {
- reaaddH=0x00;
- reaaddL=0x00;
- }
- hex_to_assic1(r_24TemperH, s_24TemperH);
-
- r_24c64_data(reaaddH,reaaddL,&LC1);////讀溫度低八位
- if( reaaddL!=0xff )
- {
- reaaddL=reaaddL+1;
- }
- if( reaaddL==0xff&&reaaddH!=0xff )
- {
- reaaddH=reaaddH+1;
- }
- if( reaaddH==0xff )
- {
- reaaddH=0x00;
- reaaddL=0x00;
- }
- hex_to_assic2(LC1, s_24TemperL);//生成顯示字符串--溫度低八位
-
- }
-
- void datapage()
- {
- write_com(0x01);
- //delayms(1);
-
- L_24c64read();
-
- write_string(0,0,"data:");
- write_string(5,0,s_24humid);
- write_string(8,0,"%");
- write_string(9,0,s_24TemperH);
- write_string(12,0,".");
- write_string(13,0,s_24TemperL);
- write_string(15,0,"D");
- //delayms(1);
- L_24c64read();
- write_string(0,1,"data:");
- write_string(5,1,s_24humid);
- write_string(8,1,"%");
- write_string(9,1,s_24TemperH);
- write_string(12,1,".");
- write_string(13,1,s_24TemperL);
- write_string(15,1,"D");
- //while((!k1value)||(!k4value));
- k3value=0;
- k4value=0;
- while((!k3value)&&(!k4value))//K4 fanye K-3結束
- {
- keyvalue();
- }
- }
-
-
-
- void speedpage()
- {
- write_com(0x01);
- delayms(1);
- write_string(0,0,"Sample_Speed:");
- hex_to_assic2(S_Speed, S_Speeded);
- write_string(6,1,S_Speeded);
- //write_string(0,1,"Back_light:");
- //write_string(12,1,"off");
- while((!k1value))
- {
- //k1value
- keyvalue();
- if(k2value==1)
- {
- k2value=0;
- if(S_Speed==3) S_Speed=0;
- else S_Speed=S_Speed+1;
- hex_to_assic2(S_Speed, S_Speeded);
- write_string(6,1,S_Speeded);
- if(S_Speed==0) scal=100;
- if(S_Speed==1) scal=6000;
- if(S_Speed==2) scal=12000;
- if(S_Speed==3) scal=36000;
-
- }
- /*if(k4value==1)
- {
- k4value=0;
- if(S_Speed>=1)
- {
- S_Speed=S_Speed-1;
- }
- hex_to_assic2(S_Speed, S_Speeded);
- write_string(12,0,S_Speeded);
- }
- if(k2value==1)
- {
- k2value=0;
- Back_light=1;
- //hex_to_assic2(S_Speed, S_Speeded);
- write_string(12,1,"on ");
- }*/
-
- delayms(200);
-
- }
-
-
-
-
-
- }
-
- void Timer0Init(void) //500??@11.0592MHz
- {
- TMOD = 0x01; //???16???????
- TH0 =0x4b;
- TL0 =0xfd; //50ms
- ET0 = 1; //????0??
- TR0 = 1;//?????0
- EA = 1; //????
- }
-
-
- void keyint()
- {
- K1=1;
- K2=1;
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
溫濕度傳感器設計.rar
(9.38 MB, 下載次數: 129)
2018-5-2 00:53 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|