用51单片机实现温湿度测控,lcd显示屏不显示
#include<reg52.h>#include"SHT.h"#include"lcd1602.h"unsignedchartable[]="wangyu";unsig...
#include<reg52.h>
#include"SHT.h"
#include"lcd1602.h"
unsigned char table[]="wangyu";
unsigned char shtdatah,shtdatal;
unsigned long shtdata; //为实际数值的100倍
void jisuan_humidity(void)
{
unsigned long aa,bb;
shtdatah&=0x0f;
aa=(unsigned long)(shtdatah*256+shtdatal);
bb=aa;
aa=405*aa;
aa/=100;
bb=bb*bb;
bb=28*bb;
bb/=100000;
shtdata=aa-400-bb;
}
void jisuan_temp(void)
{
unsigned long aa;
shtdatah&=0x3f;
aa=(unsigned long)(shtdatah*256+shtdatal);
shtdata=aa-4000;
}
void sht_all(void)
{
unsigned int j;
read_temp();
jisuan_temp();
j=3;
if(shtdata/10000==0) {lcd_display(1,3,' ');}
else{
lcd_display(1,j,0x30+shtdata/10000);
j++;
}
lcd_display(1,j++,0x30+(shtdata/1000)%10); //显示温度
lcd_display(1,j++,0x30+(shtdata/100)%10);
lcd_display(1,j++,0x30+(shtdata/10)%10);
lcd_display(1,j++,0x30+(shtdata%10));
read_humidity();
jisuan_humidity();
j=11;
if(shtdata/10000==0) lcd_display(1,11,' ');
else lcd_display(1,j++,0x30+shtdata/10000);
lcd_display(1,j++,0x30+(shtdata/1000)%10); //显示湿度
lcd_display(1,j++,0x30+(shtdata/100)%10);
lcd_display(1,j++,0x30+(shtdata/10)%10);
lcd_display(1,j++,0x30+(shtdata%10));
}
void main(void)
{
unsigned char i;
lcd_init();
sht_init();
lcd_display(1,1,'T');
lcd_display(1,2,':');
lcd_display(1,9,'H');
lcd_display(1,10,':');
for(i=0;i<6;i++)
lcd_display(2,i+1,table[i]);
lcd_display(2,12,'S');
lcd_display(2,13,'H');
lcd_display(2,14,'T');
lcd_display(2,15,0X31);
lcd_display(2,16,0X31);
while(1)
{
delay(100);
sht_all();
delay(100);
}
} 展开
#include"SHT.h"
#include"lcd1602.h"
unsigned char table[]="wangyu";
unsigned char shtdatah,shtdatal;
unsigned long shtdata; //为实际数值的100倍
void jisuan_humidity(void)
{
unsigned long aa,bb;
shtdatah&=0x0f;
aa=(unsigned long)(shtdatah*256+shtdatal);
bb=aa;
aa=405*aa;
aa/=100;
bb=bb*bb;
bb=28*bb;
bb/=100000;
shtdata=aa-400-bb;
}
void jisuan_temp(void)
{
unsigned long aa;
shtdatah&=0x3f;
aa=(unsigned long)(shtdatah*256+shtdatal);
shtdata=aa-4000;
}
void sht_all(void)
{
unsigned int j;
read_temp();
jisuan_temp();
j=3;
if(shtdata/10000==0) {lcd_display(1,3,' ');}
else{
lcd_display(1,j,0x30+shtdata/10000);
j++;
}
lcd_display(1,j++,0x30+(shtdata/1000)%10); //显示温度
lcd_display(1,j++,0x30+(shtdata/100)%10);
lcd_display(1,j++,0x30+(shtdata/10)%10);
lcd_display(1,j++,0x30+(shtdata%10));
read_humidity();
jisuan_humidity();
j=11;
if(shtdata/10000==0) lcd_display(1,11,' ');
else lcd_display(1,j++,0x30+shtdata/10000);
lcd_display(1,j++,0x30+(shtdata/1000)%10); //显示湿度
lcd_display(1,j++,0x30+(shtdata/100)%10);
lcd_display(1,j++,0x30+(shtdata/10)%10);
lcd_display(1,j++,0x30+(shtdata%10));
}
void main(void)
{
unsigned char i;
lcd_init();
sht_init();
lcd_display(1,1,'T');
lcd_display(1,2,':');
lcd_display(1,9,'H');
lcd_display(1,10,':');
for(i=0;i<6;i++)
lcd_display(2,i+1,table[i]);
lcd_display(2,12,'S');
lcd_display(2,13,'H');
lcd_display(2,14,'T');
lcd_display(2,15,0X31);
lcd_display(2,16,0X31);
while(1)
{
delay(100);
sht_all();
delay(100);
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询