欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
SHT11溫濕度傳感器仿真和源碼
[打印本頁]
作者:
ann130013
時間:
2018-6-13 09:28
標題:
SHT11溫濕度傳感器仿真和源碼
SHT11仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
0.png
(20.03 KB, 下載次數: 52)
下載附件
2018-6-14 03:32 上傳
0.png
(51.19 KB, 下載次數: 52)
下載附件
2018-6-14 03:32 上傳
單片機源程序如下:
#include <reg52.h> //頭文件
#include <intrins.h>
#include <stdio.h> //
#include <math.h> //Keil library
//**************************************
#define uchar unsigned char //定義一下方便使用
#define uint unsigned int //定義一下方便使用
#define ulong unsigned long //定義一下方便使用
#define TEMP_ML 0x03 //000 0001 1 溫度命令
#define HUMI_ML 0x05 //000 0010 1 溫度命令
unsigned char error ;//全局錯誤變量
unsigned char ack ;//全局應答變量
//float temp_zi ;//全局應答變量
//float humi_zi ;//全局應答變量
unsigned char temp_h ;//全局應答變量
unsigned char temp_LL ;//全局應答變量
unsigned int xianzhi_t=0;//溫度顯值
unsigned int xianzhi_h=0;//濕度顯值
uchar setzhi_h,setzhi_l;
bit setbz_h,setbz_l,setkey;
sbit DATA =P2^6;//數據
sbit SCK=P2^7;//時鐘
sbit hot =P2^0;// 加熱
sbit motor =P2^1;// 電機
sbit speek =P2^2;// 聲音
sbit set =P0^0;// 設置
sbit setup =P0^1;// 設置+
sbit setdown =P0^2;// 設置-
sbit gwei =P3^4;//個位
sbit swei =P3^3;//十位
sbit bwei =P3^2;//百位
sbit qwei =P3^1;//千位
unsigned char code dispcode[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};//共陽
//*******************************基本驅動程
/////////////////
//////////////////////
char read() //讀一個字節 返回應答信號
//----------------------------------------------------------------------------------
// reads a byte form the Sensibus and gives an acknowledge in case of "ack=1"
{
unsigned char i,val=0;
temp_LL=0;
temp_h=0;
DATA=1; //釋放數據總線
for (i=0x80;i>0;i/=2) //位移8位
{ SCK=1; //上升沿讀入
if (DATA) val=(val | i); //確定值
SCK=0;
}
DATA=0; //讀應答信號,有應答為1,為應答為0 通過CPU下拉為應答
SCK=1; //第9個脈沖
_nop_(); _nop_(); _nop_(); //pulswith approx. 5 us
SCK=0;
DATA=1; //釋放數據總線
temp_h=val;
val=0;
////低8位/////////////////////////////
DATA=1; //釋放數據總線
for (i=0x80;i>0;i/=2) //位移8位
{ SCK=1; //上升沿讀入
if (DATA) val=(val | i); //確定值
SCK=0;
}
DATA=1;//0; //不需要應答 通過CPU下拉為應答
SCK=1; //第9個脈沖
_nop_(); _nop_(); _nop_(); //pulswith approx. 5 us
SCK=0;
DATA=1; //釋放數據總線
temp_LL=val;
}
////////////
char write(unsigned char value) //寫一個字節 返回應答信號
//---------------------------------------------------------
{
unsigned char i ;
ack=0;
for (i=0x80;i>0;i/=2) //釋放數據總線
{ if (i & value) DATA=1; //寫入值
else DATA=0;
SCK=1; //上升沿寫入
_nop_(); _nop_(); _nop_(); //延時
SCK=0;
}
DATA=1; //釋放數據總線
SCK=1; //第9個脈沖
if (DATA==1) ack=1;
//讀應答信號
SCK=0;
return ack; //error=1 表示沒有應答
}
////////
void start_sht11(void) //啟動
//--------------------------------------------------------
{
DATA=1; SCK=0; //數據為1,SCK=0
_nop_();
SCK=1; //第一個脈沖
_nop_();
DATA=0; //數據跌落
_nop_ ();
SCK=0; //完成一個脈沖
_nop_(); _nop_(); _nop_();
SCK=1; //再一個脈沖
_nop_();
DATA=1; //數據變為1
_nop_();
SCK=0; //完成該脈沖
}
//////////////////////////////////
void sht_rest(void) //復位
{
unsigned char i;
DATA=1; SCK=0; //數據為1 時鐘為0
for(i=0;i<9;i++) //9 個脈沖為 復位
{ SCK=1;
SCK=0;
}
start_sht11(); //啟動
}
////////////////////////////////
//測量溫度或者是溫度,返回校驗值
text_a(unsigned char ml)
{
unsigned int i;
start_sht11(); //啟動
write(ml);//寫入測溫度
if (ack==1)
{
sht_rest() ;//復位
write(ml);//寫入測溫度
}
//判斷是否處于忙
// DATA=1;//釋放數據總線
//for (i=0;i<65535;i++) if(DATA==0) break;
for (i=0;i<55535;i++){ if(DATA==0) break;else {xianshi();} }
read();//讀溫度
}
/////////溫濕度處理//////
text_jishuan_temp11()
{
error=0;
ack=0;
sht_rest() ;//復位
text_a(TEMP_ML);
text_jishuan_temp();
key();
text_a(HUMI_ML);
text_jishuan_humi();
}
/////
//////////計算溫度////
text_jishuan_temp()
{
float aa=0,bb=0,temp_zi;
int abcd=0;
aa=(float)temp_h*256+(float)temp_LL;
temp_zi=0.01*aa-40;
//
if (temp_zi<0)
{
temp_zi=0;
}
temp_zi=temp_zi*10;
xianzhi_t=(int)temp_zi;//給顯示值
}
///////計算濕度//////
text_jishuan_humi()
{
float aa=0,bb=0,humi_zi;
int abcd=0;
aa=(float)temp_h*256+(float)temp_LL;
bb=aa*aa*2.8/1000000;
aa=0.0405*aa;
aa=aa-4-bb;
humi_zi=aa;
//
humi_zi=humi_zi*10;
xianzhi_h=(int)humi_zi;
}
///////延時///////
delay(int i)
{
while(--i);
}
///////顯示處理///////
xianshi()
{
int abcd=0;
int i;
for (i=0;i<1;i++)
{
abcd=xianzhi_h;
gwei=1;
swei=1;
bwei=1;
qwei=1;
P1=dispcode[abcd/100];
qwei=0;
delay(40);
qwei=1;
abcd=abcd%100 ;
P1=dispcode[abcd/10];
bwei=0;
delay(40);
bwei=1;
if(setbz_h^setbz_l)
{
if(setbz_h) abcd=setzhi_h;
if(setbz_l) abcd=setzhi_l;
P1=dispcode[abcd/10];
swei=0;
delay(40);
swei=1;
P1=dispcode[abcd%10];
gwei=0;
delay(40);
gwei=1;
}
else
{
abcd=xianzhi_t;
P1=dispcode[abcd/100];
swei=0;
delay(40);
swei=1;
abcd=abcd%100 ;
P1=dispcode[abcd/10];
gwei=0;
delay(40);
gwei=1;
}
}
}
doing()
{
char xianzhi_mi;
xianzhi_mi=xianzhi_t/10;
if((xianzhi_mi<setzhi_h)&(xianzhi_t>setzhi_l)) { motor=0;hot=0;speek=0;}
if(xianzhi_mi>setzhi_h) { motor=1;hot=0;speek=1;}
if(xianzhi_mi<setzhi_l) { motor=0;hot=1;speek=1;}
}
key()
{
if(set&setkey)
{
setkey=0;
if(setbz_l) {setbz_l=0;setbz_h=0;}
else
{ if(!setbz_h) setbz_h=1;
else {setbz_h=0;setbz_l=1;}
}
}
if(!set) setkey=1;
if(setup==0)
{
if(setbz_h==1)
{ if (setzhi_h<=99) setzhi_h++;}
if(setbz_l==1)
{ if ((setzhi_l<setzhi_h)&(setzhi_l<=99)) setzhi_l++;}
}
if(setdown==0)
{
if(setbz_h==1)
{ if ((setzhi_h>setzhi_l)&(setzhi_h>=1)) setzhi_h--;}
if(setbz_l==1)
{ if (setzhi_l>=1) setzhi_l--;}
……………………
…………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
SHT11溫濕度傳感器仿真.rar
(76.84 KB, 下載次數: 79)
2018-6-13 09:27 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1