找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2270|回復: 0
打印 上一主題 下一主題
收起左側

STM32單片機DTH11源程序Proteus仿真帶℃報警

[復制鏈接]
跳轉到指定樓層
樓主
ID:387687 發(fā)表于 2022-3-18 16:32 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
STM32芯片DTH11 PROTEUS 仿真帶℃報警

溫度超過40度 自動報警,低于40 度恢復。
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)


單片機源程序如下:
  1. #include "stm32f10x.h"
  2. #include "LQ12864.h"
  3. #include "adc.h"
  4. #include "dth11.h"

  5. void main_delay(u32 ms)
  6. {
  7.         int i, j;
  8.         for(i = 0; i < ms; i++)
  9.         {
  10.                 for(j = 0; j < 1000; j++)
  11.                 {
  12.                         ;
  13.                 }
  14.         }
  15. }

  16. void GPIO_Configuration(void)
  17. {
  18.   GPIO_InitTypeDef GPIO_InitStructure;
  19.         
  20.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOC, ENABLE);
  21.         
  22.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //LED0-->PA.8 ????
  23.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //????
  24.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO ???? 50MHz
  25.         GPIO_Init(GPIOA, &GPIO_InitStructure); //????????? GPIOA.8
  26.         
  27.         GPIO_SetBits(GPIOA,GPIO_Pin_8); //PA.8 ???
  28. }
  29. int main(void)
  30. {         

  31.         u8 temp = 0, hum = 0;
  32.         unsigned char buf[100] = { 0 };
  33. //        delay_init()        ;
  34.         LCD_Init() ;         
  35.         Adc_Init();
  36.         DHT11_Init();
  37. GPIO_Configuration();
  38.         while(1)
  39.         {
  40.                 DHT11_Read_Data(&temp, &hum);
  41.                 sprintf(buf, "temp: %d  hum:%d", temp, hum);
  42.                 LCD_P6x8Str(2, 3, buf);
  43.   if (temp>40)
  44.         {
  45.                     GPIO_ResetBits(GPIOA, GPIO_Pin_8);
  46.                  delay(2000);
  47.                 delay(2000);

  48.         }
  49.         else
  50.         {  GPIO_SetBits(GPIOA, GPIO_Pin_8);
  51.         delay(200);
  52.         }
  53.                 }
  54.         }
復制代碼

Keil代碼與Proteus仿真下載:
STM32 DTH11.7z (263.66 KB, 下載次數: 92)

評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表