我用51能够读出来,但是到了STM8S103K3上面就一直有问题s_measure返回的错误值是2,然后就一直重连,请问这会是什么问题
[mw_shl_code=c,true] while (1)
{
error=0;
error+=s_measure((unsigned char*) &humi_val.i,&checksum,HUMI); //measure humidity
error+=s_measure((unsigned char*) &temp_val.i,&checksum,TEMP); //measure temperature
if(error!=0)
s_connectionreset(); //in case of an error: connection reset
else
{ humi_val.f=(float)humi_val.i; //converts integer to float
temp_val.f=(float)temp_val.i; //converts integer to float
calc_sth11(&humi_val.f,&temp_val.f); //calculate humidity, temperature
//dew_point=calc_dewpoint(humi_val.f,temp_val.f); //calculate dew point
printf("temp:%5.1fC humi:%5.1f%% dewpoint:%5.1fC
",temp_val.f,humi_val.f,dew_point);
}
for (i=0;i<40000;i++);
}[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
但是 STM8 常設的頻率好像只有 2MHZ 變更頻率到 16MHZ 或許就可以用了!!
void DHT_Start(void)
{
GPIO_Init(DHT_Port,DHT_data,GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_WriteLow(DHT_Port,DHT_data);
DelayMs(18);//18.17ms
GPIO_WriteHigh(DHT_Port,DHT_data);//10us
Delayus(20);
}
u8 DHT_Read(void)
{
u8 i, j,pulse,k;
pulse=0;
count81=0;
while(!GPIO_ReadInputPin(DHT_Port,DHT_data));
while(GPIO_ReadInputPin(DHT_Port,DHT_data));
for(i=0;i<5;i++)
{
for (j=0;j<8;j++)
{
while(!GPIO_ReadInputPin(DHT_Port,DHT_data));
while(GPIO_ReadInputPin(DHT_Port,DHT_data))
{
count81++;
}
pulse<<=1;
if(count81>20)
pulse +=1;
else
pulse +=0;
count81=0;
}
DHT=pulse;
pulse=0;
}
}
一周热门 更多>