#include <reg52.h> #include <stdio.h> #include 'oled.h' #include 'dht11.h'

#define DHT11_PIN P2_0

void main() { unsigned char temp = 0, humi = 0;

OLED_Init();  // OLED初始化

while(1)
{
    if(DHT11_Read_Data(&temp, &humi, DHT11_PIN) == SUCCESS)  // 读取温湿度数据
    {
        char buf[20];
        sprintf(buf, 'Temp:%.3dC Humi:%.3d%%', temp, humi);  // 格式化温湿度数据
        OLED_ShowString(0, 0, buf);  // 在OLED显示温湿度数据
    }
}

}


原文地址: https://www.cveoy.top/t/topic/ojyz 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录