本人新學(xué)proteus,經(jīng)過網(wǎng)上搜索,找到了一些代碼。然后經(jīng)過修改。變成了現(xiàn)在的文件。可以實現(xiàn)在LCD1602上顯示溫濕度。但是通過串口顯示的數(shù)據(jù)確是亂碼。之后附上文件代碼,希望各位大佬能夠給我一些建議。萬分感謝。因為代碼一樣是從網(wǎng)上下載的。如果有哪些代碼有異議,請聯(lián)系我,謝謝。ps:proteus上面的dht11,最好使用我文件里面的那個。我之前用的是proteus8.8里面的dht11,一直不顯示數(shù)據(jù)。不知道原因。
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
單片機源程序如下:
- #include "stm32f10x.h"
- #include "bsp-lcd1602.h"
- #include "delay.h"
- #include "led.h"
- #include "sys.h"
- #include "DTH11.h"
- #include "stdlib.h"
- #include "stdio.h"
- #include "usart.h"
- int main(void)
- {
- u8 temperature,humidity;
- unsigned char display[10] ;
- RCC_ClocksTypeDef RCC_Clocks;
- u8 a=7,b=8;
- RCC_Configuration();
-
- RCC_GetClocksFreq(&RCC_Clocks);
- USART1_Init(9600);
- LCD1602_Init();
- delay_init();
- LED_Init();
- DHT11_Init();
- LCD1602_ShowStr(2,0,"stm32f103R6",11);
- delay_s(10);
- LCD1602_Clear();
- while(1)
- {
- DHT11_Read_Data(&temperature,&humidity) ;
-
- sprintf((char *)display,"temp:%d ",temperature) ;
- LCD1602_ShowStr(0,0,display,11) ;
-
- sprintf((char *)display,"humi:%d ",humidity) ;
- LCD1602_ShowStr(1,1,display,11) ;
-
- printf("temp:%c \r\n",temperature);
- printf("humidity:%c \r\n",humidity);
- LED0 = 0;
- LED1 = 1;
- delay_s(2);
- LED0 = 1;
- LED1 = 0;
- delay_s(2);
- USART1_printf("STM32 %d %d ",a,b);
- }
-
- }
復(fù)制代碼
所有資料51hei提供下載:
LCD+LED+USART.7z
(221.02 KB, 下載次數(shù): 699)
2020-4-29 19:18 上傳
點擊文件名下載附件
|