dht11怎么写程序( 三 )


uchar T_H,T_L,R_H,R_L,check,num_check;
【dht11怎么写程序】uchar count;
start();//开始信号
io=1;
if(!io)//读取DHT11响应信号
{
count=2;
while((!io)&&count++);//DHT11高电平80us是否结束
count=2;
while((io)&&count++);
R_H=receive_byte();
R_L=receive_byte();
T_H=receive_byte();
T_L=receive_byte();
check=receive_byte();
io=0;//拉低延时50us
delay1();delay1();delay1();delay1();delay1();
io=1;
num_check=R_H+R_L+T_H+T_L;
if(num_check=check)
{
RH=R_H;
RL=R_L;
TH=T_H;
TL=T_L;
check=num_check;
}
}
}
5.谁用at89c51单片机控制dht11程序急需#include <reg52.h>#include <intrins.h>#include <DHT11.h>#include <DS1302.h>unsigned char DataBuff[5]="0";unsigned char DissBuff_WS[4]={0};void delayms(unsigned int z){ unsigned int x,y; for(x=z;x>0;x--) for(y=125;y>0;y--);}void MCU_Start_Delay() //28us { _nop_();_nop_();_nop_(); _nop_();_nop_();_nop_(); _nop_();_nop_();_nop_(); _nop_();_nop_();_nop_(); _nop_();_nop_();_nop_(); _nop_();_nop_();_nop_(); _nop_();_nop_();_nop_(); _nop_();_nop_();_nop_();}bit MCU_Start(){ bit Start_Flag=0; unsigned char tmp=0xff; Dout=1;_nop_(); Dout=0; delayms(23); Dout=1; MCU_Start_Delay();while(Dout==1); while(Dout==0);Start_Flag=1; while(Dout==1); return Start_Flag;}void Read_DHT11(){ unsigned char i,j; unsigned char tmp; unsigned char Count=0x00;for(i=0;i<4;i++) { tmp=0; for(j=0;j<8;j++) { while(!Dout); while(Dout) { Count++; } tmp=tmp<<1; if(Count>45) //52单片机>5 12C5A60S2>40 { tmp=tmp|0x01; } else { tmp=tmp&0xfe; } Count=0; } DataBuff[i]=tmp; }}void Data_Pro(){DissBuff_WS[0]=DataBuff[0]/10; DissBuff_WS[1]=DataBuff[0]%10; DissBuff_WS[2]=DataBuff[2]/10; DissBuff_WS[3]=DataBuff[2]%10;}void DHT11_DisPlay_WX(unsigned char i){ switch(i){ case '0':P24=1;P25=1;P26=1;P27=0;break; case '1':P24=1;P25=1;P26=0;P27=1;break; case '2':P24=1;P25=0;P26=1;P27=1;break; case '3':P24=0;P25=1;P26=1;P27=1;break; }} void delay_DHT11(){ unsigned char tem=50; while(tem--);}void DHT11_DisPlay(){ unsigned char i; for(i=0;i<4;i++) { DHT11_DisPlay_WX(i); P2=Disscode[DissBuff_WS[i]]; delay_DHT11(); }}有什么不懂的就问我 。
6.dht11程序#include #include //typedef unsigned char U8; /* defined for unsigned 8-bits integer variablexd 无符号8位整型变量 */typedef signed char S8; /* defined for signed 8-bits integer variablexd 有符号8位整型变量 */typedef unsigned int U16; /* defined for unsigned 16-bits integer variablexd 无符号16位整型变量 */typedef signed int S16; /* defined for signed 16-bits integer variablexd 有符号16位整型变量 */typedef unsigned long U32; /* defined for unsigned 32-bits integer variablexd 无符号32位整型变量 */typedef signed long S32; /* defined for signed 32-bits integer variablexd 有符号32位整型变量 */typedef float F32; /* single precision floating point variablexd (32bits) 单精度浮点数(32位长度) */typedef double F64; /* double precision floating point variablexd (64bits) 双精度浮点数(64位长度) *///#define uchar unsigned char#define uint unsigned int#define Data_0_time 4//----------------------------------------------////----------------IO口定义区--------------------////----------------------------------------------//sbit P2_0 = P2^0 ;//----------------------------------------------////----------------定义区--------------------////----------------------------------------------//U8 U8FLAG,k;U8 U8count,U8temp;U8 U8T_data_H,U8T_data_L,U8RH_data_H,U8RH_data_L,U8checkdata;U8 U8T_data_H_temp,U8T_data_L_temp,U8RH_data_H_temp,U8RH_data_L_temp,U8checkdata_temp;U8 U8comdata;U8 outdata[5]; //定义发送的字节数 U8 indata[5];U8 count, count_r=0;U8 str[5]={"RS232"};U16 U16temp1,U16temp2;SendData(U8 *a){ outdata[0] = a[0]; outdata[1] = a[1]; outdata[2] = a[2]; outdata[3] = a[3]; outdata[4] = a[4]; count = 1; SBUF=outdata[0];} void Delay(U16 j) { U8 i; for(;j>0;j--) { for(i=0;i