uchara[]="温湿度传感器";ucharb[]="温度:";ucharc[]="湿度:";uchard[]="0123456789";typedefunsignedcharU8;typedefunsignedintU16;U8U8flag,k;U8U8temp;U8U8WD_H,U8WD_L,U8SD_H,U8SD_L,U8checkdata;U8U8WDH_temp,U8WDL_temp,U8SDH_temp,U8SDL_temp,U8checkdata_temp;U8U8comdata;voiddelay_1ms(uintn){uinti,j;for(i=0;i<=n;i++)for(j=0;j<110;j++);}voiddelay_10us(){U8i;i--;i--;i--;i--;i--;i--;}voidwrite_com(ucharcom){rs=0;rw=0;en=0;P2=com;delay_1ms(1);en=1;delay_1ms(1);en=0;}voidwrite_data(uchardate){rs=1;rw=0;en=0;P2=date;delay_1ms(1);en=1;delay_1ms(1);en=0;}voidpos(ucharx,uchary){ucharpos;if(x==0)x=0x80;elseif(x==1)x=0x90;elseif(x==2)x=0x88;elseif(x==3)x=0x98;pos=x+y;write_com(pos);}voiddisplay(U8WD_H,U8WD_L,U8SD_H,U8SD_L){U8yi,er,san,si;yi=U8WD_H/10;er=U8WD_H;san=U8SD_H/10;si=U8SD_H;pos(1,4);write_data(d[yi]);pos(1,5);write_data(d[er]);pos(2,4);write_data(d[san]);pos(2,5);write_data(d[si]);}voidcom(){U8i;for(i=0;i<8;i++){U8flag=2;while((!SJK)&&U8flag++);delay_10us();delay_10us();delay_10us();U8temp=0;if(SJK)U8temp=1;U8flag=2;while((SJK)&&U8flag++);if(U8flag==1)break;U8comdata<<=1;U8comdata|=U8temp;}}
2024/1/28 1:02:12
26KB
DHT11
1