温湿度DHT11应用程序12864显示.docx
- 文档编号:9533201
- 上传时间:2023-05-19
- 格式:DOCX
- 页数:9
- 大小:15.21KB
温湿度DHT11应用程序12864显示.docx
《温湿度DHT11应用程序12864显示.docx》由会员分享,可在线阅读,更多相关《温湿度DHT11应用程序12864显示.docx(9页珍藏版)》请在冰点文库上搜索。
温湿度DHT11应用程序12864显示
温湿度DHT11应用程序12864显示
#include
#include
#defineucharunsignedchar
#defineuintunsignedint
sbitdata1=P1^0;
sbitsid=P3^6;//数据口
sbitsclk=P3^7;//时钟
sbitled=P2^0;//测试灯
sbitled1=P2^1;
sbitled2=P2^2;
sbitled3=P2^3;
ucharlcd_x,lcd_y,data_byte=0;
ucharcount;
uintU8T_data_H,U8T_data_L,
U8RH_data_H,U8RH_data_L,U8checkdata;
uintU8T_data_H_temp,U8T_data_L_temp,num,
U8RH_data_H_temp,U8RH_data_L_temp,
U8checkdata_temp;
//unsignedchartable[10]={"0123456789"};
//ucharinttable1[8];
unsignedcharstr1[]={""};
unsignedcharstr2[]={""};
unsignedcharcodelcd[]={"温湿度检测系统"};
unsignedcharcodelcd1[]={"温度:
"};
unsignedcharcodelcd2[]={"湿度:
"};
unsignedcharcodelcd3[]={"℃"};
unsignedcharcodelcd4[]={"%RH"};
voidDelay2(uintz)
{
uinti;
for(i=z;i>0;i--)
{
for(i=0;i>110;i--);
}
}
voidDelay_10us(void)
{
inti=5;
i--;
}
ucharrece()
{
uchari,temp;
for(i=0;i<8;i++)
{
count=2;
while((!
data1)&&count++);
//temp=0;
Delay_10us();
Delay_10us();
Delay_10us();
temp=0;
if(data1==1)
temp=1;
count=2;
while(data1&&count++);
if(count==1)
break;
//temp=0;
data_byte<<=1;
data_byte|=temp;
}
return(data_byte);
}
//12864的串口显示
voiddelay(uintz)
{uintx,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
voidsend(ucharbyte)
{uchari;
for(i=0;i<8;i++)
{sid=byte&0x80;
sclk=0;
sclk=1;
byte<<=1;
}
}
voidwrite_date(uchardate)
{ucharstar_date,hdate,ldate;
//if(star==0)
//star_date=0xf8;//写指令
//else
star_date=0xfa;//写数据
hdate=date&0xf0;//取高4位
ldate=(date<<4)&0xf0;//取低4位
send(star_date);
delay
(1);
send(hdate);
delay
(1);
send(ldate);
delay
(1);
}
voidwrite_com(ucharcom)
{ucharstar_date,hdate,ldate;
//if(star==0)
star_date=0xf8;//写指令
//else
//star_date=0xfa;//写数据
hdate=com&0xf0;//取高4位
ldate=(com<<4)&0xf0;//取低4位
send(star_date);
delay
(1);
send(hdate);
delay
(1);
send(ldate);
delay
(1);
}
voidlcd_dis_code(uintcmd_addr,ucharnum,uchardis[])
{
uinti;
write_com(cmd_addr);
for(i=0;i write_date(dis[i]); } voidlcd_init() {delay(100); write_com(0x30); write_com(0x02); write_com(0x06); write_com(0x0c); write_com(0x01); write_com(0x80); delay(5); } voidlcd_pos(ucharx,uchary) { ucharpos; if(x==1) {x=0x80;} elseif(x==2) {x=0x90;} elseif(x==3) {x=0x88;} else {x=0x98;} write_com(y|pos); } voidmain() { uchark,j; lcd_init(); lcd_dis_code(0x80,16,lcd); lcd_dis_code(0x88,9,lcd1); lcd_dis_code(0x98,9,lcd2); lcd_dis_code(0x8e,2,lcd3); lcd_dis_code(0x9e,5,lcd4); while (1) { //voidRead() //{ led=0; data1=0; Delay2(20); data1=1; Delay_10us(); Delay_10us(); Delay_10us(); Delay_10us(); data1=1; //led=0; if(! data1) { //led=0; //count=2; //while((data1)&&count++); //count=2; led1=0; while(data1&&count++); led2=0; U8RH_data_H_temp=rece(); U8RH_data_L_temp=rece(); U8T_data_H_temp=rece(); U8T_data_L_temp=rece(); U8checkdata_temp=rece(); data1=1; num=(U8T_data_H_temp+U8T_data_L_temp+U8RH_data_H_temp+U8RH_data_L_temp); if(num==U8checkdata_temp) { led3=0; U8RH_data_H=U8RH_data_H_temp; U8RH_data_L=U8RH_data_L_temp; U8T_data_H=U8T_data_H_temp; U8T_data_L=U8T_data_L_temp; U8checkdata=U8checkdata_temp; } str1[0]=(char)(0x30+U8RH_data_H/10); str1[1]=(char)(0x30+U8RH_data_H%10); str2[0]=(char)(0x30+U8T_data_H/10); str2[1]=(char)(0x30+U8T_data_H%10); } } delay(500); } WelcomeTo Download! ! ! 欢迎您的下载,资料仅供参考!
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 温湿度 DHT11 应用程序 12864 显示