|
SHT25溫濕度測量仿真原理圖如下(proteus 8.9SP2 仿真工程文件可到本帖附件中下載)
51hei截圖20200720105119882.jpg (189.73 KB, 下載次數(shù): 88)
下載附件
proteus
2020-7-20 11:33 上傳
51hei截圖20200720112959466.jpg (91.24 KB, 下載次數(shù): 65)
下載附件
labview上位機(jī)顯示
2020-7-20 11:34 上傳
51hei截圖20200720113425208.jpg (115.84 KB, 下載次數(shù): 61)
下載附件
代碼
2020-7-20 11:34 上傳
單片機(jī)源程序如下:
- //vender:liaoxj
- //version:v1
- #include "reg8051.h"
- #include <stdio.h>
- #include "drv.h"
- #include "common.h"
- #include "delay.h"
- #include "iic.h"
- #include "SHT20.h"
- int ReadTempFlag;//定義讀時(shí)間標(biāo)志
- char temp_H,temp_L;
- unsigned int temp;
- unsigned int num;
- int a=0;
- int timer0_count=0;
- int v=0;
- char v_h,v_l;
- int uart_flag=0;
- unsigned char receive[4];
- void main()
- {
- uart_init();
- timer0_init();
- SHT20_Init();
- EA=1;
- SHT20_setResolution();
- while(1)
- {
- if(ReadTempFlag==1)
- {
-
- ReadTempFlag=0;
- //SHT25,IIC接口
- temp=SHT20_readTem();
- // temp>>=5;//數(shù)據(jù)是11位的,高位對(duì)齊,所以數(shù)據(jù)右移5位,變低位對(duì)齊
- temp=temp&0xfffc;
- temp_L=temp;//拆分為低8位和高3位,用串口傳輸
- temp_H=temp>>8;
- send(temp_H);
- send(temp_L);
-
- temp=SHT20_readHum();
- // temp>>=5;
- temp=temp&0xfffc;
- temp_L=temp;
- temp_H=temp>>8;
- send(temp_H);
- send(temp_L);
- }
-
- }
- }
- void timer0_isr() interrupt 1
- {
-
- TH0=0xF8;
- TL0=0xCC;
- timer0_count++;
- if(timer0_count==1000)
- {
- P10=~P10;
- timer0_count=0;
- ReadTempFlag=1; //讀標(biāo)志位置1
- }
- }
- void uart_isr() interrupt 4
- {
- static unsigned char count;//串口接收計(jì)數(shù)的變量
- RI=0;//手動(dòng)清某個(gè)寄存器,大家都懂的
- receive[count]=SBUF;
- count++;
- if(count==4)
- {
- ES=0;
- count=0;
- uart_flag =1;//串口接收成功標(biāo)志,為1時(shí)在主程序中回復(fù),然后清零
- //關(guān)中斷,回復(fù)完了再ES=1;
- }
-
- }
復(fù)制代碼
所有資料51hei提供下載:
IIC-SHT25溫濕度傳感器.zip
(183.75 KB, 下載次數(shù): 77)
2020-7-20 11:37 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|