dht11怎么写程序( 二 )


2.dht11程序#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 评论0 0 0 。
3.谁用at89c51单片机控制dht11程序急需#include #include #include 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 { tmp=0; for(j=0;j { while(!Dout); while(Dout) { Count++; } tmp=tmp 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 { DHT11_DisPlay_WX(i); P2=Disscode[DissBuff_WS[i]]; delay_DHT11(); } } 有什么不懂的就问我 。
4.谁有用msp430写的DHT11湿度传感器的程序void start()//开始信号
{
io=1;
delay1();
io=0;
delay(20);//>18ms
io=1;
delay1();//20-40us
delay1();
delay1();
delay1();
delay1();
}
uchar receive_byte()//接收一个字节
{
uchar i,temp,count;
for(i=0;i<8;i++)
{
count=2;
while((!io)&&count++)//等待50us低电平结束
temp=0;
delay1();delay1();delay1();delay1();
if(io==1)temp=1;
count=2;
while((io)&&count++);
if(count==1)break;
data_byte<<=1;
data_byte|=temp;
}
return data_byte;
}
void receive()//接收数据
{