資源簡介
溫濕度監測通過串口上傳上位機并在液晶屏上顯示溫濕度監測通過串口上傳上位機并在液晶屏上顯示

代碼片段和文件信息
#include
#include
#include
#define?uint?unsigned?int
#define?uchar?unsigned?char?
/*sbit?wela=P2^7;
sbit?dula=P2^6;
sbit?lcd_rs=P3^5;
sbit?lcd_en=P3^4;*/
sbit?ws=P2^4;
sbit?beep=P2^3;
uchar?TH_dataTL_dataRH_dataRL_dataCK_data;
uchar?TH_tempTL_tempRH_tempRL_tempCK_temp;
uchar?com_datauntemptemp;
bit?flag;
float?R_tempT_temp;
uchar?str1[]={“00000“};
uchar?str2[]={“00000“};
void?delayms(uint?z)
{
uint?ij;
for(i=z;i>0;i--)
for(j=110;j>0;j--);
}
void?write_com(uchar?com)
{
lcd_rs=0;
P0=com;
delayms(5);
lcd_en=1;
delayms(5);
lcd_en=0;
}
void?write_dat(uchar?dat)
{
lcd_rs=1;
P0=dat;
delayms(5);
lcd_en=1;
delayms(5);
lcd_en=0;
}
/*void?writestring(uchar?*struchar?length)
{
uint?i;
for(i=0;i {
write_dat(str[i]);
}
}*/
void?lcd_init()
{
write_com(0x38);
write_com(0x06);
write_com(0x0c);
write_com(0x01);
}
uchar?get_temp()
{
uchar?ij;
com_data=0;
for(i=0;i<8;i++)
{
while(!ws);?????????????
for(j=0;j<10;j++);????//延時30us?
if(ws)?????????????????//延時30us后,總線仍為高電平則為1
{
temp=1;
while(ws);
}
else
temp=0;
com_data<<=1;
com_data|=temp;
}
return?com_data;
}
void?read_temp()
{
uint?iR_shuT_shu;
uchar?mn;
ws=1;
ws=0;
delayms(20); ????//主機將總線拉低至少18ms
ws=1;
for(i=0;i<10;i++);
ws=1;
if(!ws)
{
while(!ws);
while(ws);
}
RH_temp=get_temp();
RL_temp=get_temp();
TH_temp=get_temp();
TL_temp=get_temp();
CK_temp=get_temp();
ws=1;
untemp=(RH_temp+RL_temp+TH_temp+TL_temp);
if(untemp==CK_temp)
{
RH_data?=?RH_temp;
????????RL_data?=?RL_temp;
????????TH_data?=?TH_temp;?
????????TL_data?=?TL_temp;
????????CK_data=?CK_temp;
}
????str1[0]=(uchar)(0x30+RH_data/10);
str1[1]=(uchar)(0x30+RH_data%10);
str1[3]=(uchar)(0x30+RH_data/10);
str1[4]=(uchar)(0x30+RH_data%10);
str2[0]=(uchar)(0x30+TH_data/10);
str2[1]=(uchar)(0x30+TH_data%10);
str2[3]=(uchar)(0x30+TH_data/10);
str2[4]=(uchar)(0x30+TH_data%10);
R_shu=(RH_data<<8);
R_shu|=RL_data;
????R_temp=R_shu*0.0039096;
T_shu=(TH_data<<8);
T_shu|=TL_data;
T_temp=T_shu*0.0039096;
m=RH_data;
n=TH_data;
if(m>50||n>60)
{
beep=0;
delayms(1000);
beep=1;
delayms(1000);
}
else
beep=1;
}
void?ws_display()
{
????uchar?i;
write_com(0x80+3);
for(i=0;i<4;i++)
{
write_dat(str1[i]);
if(i==1)
write_dat(‘.‘);
}
write_com(0x80+0x40+3);
for(i=0;i<4;i++)
{
write_dat(str2[i]);
if(i==1)
???? write_dat(‘.‘);
}
flag=1;
}
void?init_com()
{
TMOD=0X21;
SCON=0X50;
PCON=0X00;
TH1=0XFD;
TL1=0XFD;
TR1=1;
EA=1;
ES=1;
}
void?comm()
{
if(flag==1)
{
ES=0;
TI=1;
printf(“shidu:%f??wendu:%f?\n“R_tempT_temp);
while(!TI);
TI=0;
ES=1;
}
}
void?main()
{
wela=0;
dula=0;
lcd_init();
init_com();
while(1)
{
read_temp();
ws_di
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2013-07-26?09:51??dht11(1602液晶)\
?????文件????????6714??2013-07-26?09:28??dht11(1602液晶)\dht11
?????文件????????8379??2013-07-26?09:28??dht11(1602液晶)\dht11.LST
?????文件???????17132??2013-07-26?09:28??dht11(1602液晶)\dht11.M51
?????文件????????5024??2013-07-26?09:28??dht11(1602液晶)\dht11.OBJ
?????文件????????2087??2013-06-02?15:24??dht11(1602液晶)\dht11.Uv2.bak
?????文件????????3063??2013-06-02?14:42??dht11(1602液晶)\dht11.bak
?????文件????????3071??2013-06-02?15:22??dht11(1602液晶)\dht11.c
?????文件????????9458??2013-07-26?09:28??dht11(1602液晶)\dht11.hex
?????文件??????????27??2013-07-26?09:28??dht11(1602液晶)\dht11.lnp
?????文件????????1313??2013-06-02?15:24??dht11(1602液晶)\dht11.opt.bak
?????文件?????????533??2013-07-26?09:51??dht11(1602液晶)\dht11.plg
?????文件???????57367??2013-07-26?09:51??dht11(1602液晶)\dht11.uvopt
?????文件???????13183??2013-06-02?15:24??dht11(1602液晶)\dht11.uvproj
?????文件????????1403??2013-06-02?14:52??dht11(1602液晶)\dht11_Opt.Bak
?????文件????????1649??2013-06-02?14:52??dht11(1602液晶)\dht11_Uv2.Bak
?????文件???????57874??2013-07-26?09:24??dht11(1602液晶)\dht11_uvopt.bak
評論
共有 條評論