手上有个SHT11温湿度模块,看了一下说明书还挺方便使用。就抽空测试了一下。不保证精度,因为手头也没有什么其它温湿度计对比。保证能把数据获取。
顺便还做了STC的指令自动重启下载代码。
请注意图中的设置项
- /*******************************************************************************
- * @brief None
- * @param None
- * @retval None
- ****************************************************************Author:Liming**/
- void main(void)
- {
- SHT11_VALUE Temp,Humi;
- unsigned int Humidity,Temperature;
- unsigned char SHT11_CRC;
- unsigned char SHT11_Error;
- Timer0_Init();
- Uart_Init();
- EA = 1;
- SendString("STC15W408AS Uart Test !\r\n");
- sht11_init();
- while(1)
- {
- SHT11_Error = sht11_get_data((unsigned char*)&Temp.i,&SHT11_CRC,TEMP);
- SHT11_Error = sht11_get_data((unsigned char*)&Humi.i,&SHT11_CRC,HUMI);
- if(SHT11_Error) sht11_init();
- else
- {
- Temp.f = (float)Temp.i;
- Humi.f = (float)Humi.i;
- calc_sht11(&Humi.f,&Temp.f);
- }
- Temperature = Temp.f*10;
- Humidity = Humi.f*10;
- if(Humidity == 0) sht11_init();
- else
- {
- SendString("温度:");
- SendData(Temperature/1000+'0');
- SendData(Temperature%1000/100+'0');
- SendData(Temperature%100/10+'0');
- SendData('.');
- SendData(Temperature%10+'0');
- SendString("℃");
- SendString("湿度:");
- SendData(Humidity/100+'0');
- SendData(Humidity%100/10+'0');
- SendData('.');
- SendData(Humidity%10+'0');
- SendString("%\r\n");
- }
- Delay_ms(700);
- }
- }
复制代码 下面是原工程文件
Template.zip
(90.57 KB, 下载次数: 83)
|