int main(void) { u8 t=0; u8 temperature; u8 humidity; uart_init(115200); //´®¿Ú³õʼ»¯Îª115200 delay_init(); //ÑÓʱº¯Êý³õʼ»¯ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//ÉèÖÃÖжÏÓÅÏȼ¶·Ö×éΪ×é2£º2λÇÀÕ¼ÓÅÏȼ¶£¬2λÏìÓ¦ÓÅÏȼ¶ LED_Init(); //³õʼ»¯ÓëLEDÁ¬½ÓµÄÓ²¼þ½Ó¿Ú LCD_Init(); //³õʼ»¯LCD POINT_COLOR=GREEN; LCD_ShowString(30,50,200,16,16,"dpj"); LCD_ShowString(30,70,200,16,16,"6.10"); while(DHT11_Init()) //DHT11³õʼ»¯ { LCD_ShowString(30,100,200,16,16,"DHT11 Error"); delay_ms(200); LCD_Fill(30,130,239,130+16,WHITE); delay_ms(200); } LCD_ShowString(30,130,200,16,16,"DHT11 OK"); LCD_ShowString(30,150,200,16,16,"Temp: C"); LCD_ShowString(30,170,200,16,16,"Humi: %"); POINT_COLOR=YELLOW;根据以上代码,写一段与上述改吗实现功能相同,但代码不同的代码
时间: 2024-03-25 15:38:48 浏览: 186
以下是一段与上述代码实现相同功能但不同的代码:
```c
int main(void) {
u8 t = 0;
u8 temperature;
u8 humidity;
uart_init(115200);
delay_init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
LED_Init();
LCD_Init();
POINT_COLOR = GREEN;
LCD_ShowString(30, 50, 200, 16, 16, "dpj");
LCD_ShowString(30, 70, 200, 16, 16, "6.10");
while (DHT11_Init()) {
LCD_ShowString(30, 100, 200, 16, 16, "DHT11 Error");
delay_ms(200);
LCD_Fill(30, 130, 239, 130 + 16, WHITE);
delay_ms(200);
}
LCD_ShowString(30, 130, 200, 16, 16, "DHT11 OK");
LCD_ShowString(30, 150, 200, 16, 16, "Temp: C");
LCD_ShowString(30, 170, 200, 16, 16, "Humi: %");
POINT_COLOR = YELLOW;
while (1) {
if (t++ % 10 == 0) {
DHT11_Read_Data(&temperature, &humidity);
LCD_ShowNum(30 + 40, 150, temperature, 2, 16);
LCD_ShowNum(30 + 40, 170, humidity, 2, 16);
}
delay_ms(10);
if (t == 200) {
t = 0;
LED0 = !LED0;
}
}
}
```
这段代码与原代码相比,最大的改动是将主程序的部分移动到了 while 循环中,使得程序可以不断地读取 DHT11 的数据并更新 LCD 显示。另外,将 POINT_COLOR 的颜色从绿色改为黄色,用于显示温度和湿度的数值。
阅读全文