找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2599|回复: 1
收起左侧

stm32单片机温室开发资料 源程序Proteus仿真 温控补光功能

  [复制链接]
ID:917653 发表于 2021-5-9 16:59 | 显示全部楼层 |阅读模式
具有温控补光功能的 stm32温室开发系统资料分享给大家学习,如有问题,请多多指教
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
51hei.png 文本.png 51hei.png 51hei.png 51hei.png

单片机源程序如下:
  1. #include "stm32f10x.h"
  2. #include "LQ12864.h"
  3. #include "adc.h"
  4. #include "dth11.h"
  5. #define PUSH_UP 1
  6. #define PUSH_DOWN 2
  7. #define PUSH_OK 3
  8. #define PUSH_NONE 4

  9. void main_delay(u32 ms)
  10. {
  11.         int i, j;
  12.         for(i = 0; i < ms; i++)
  13.         {
  14.                 for(j = 0; j < 1000; j++)
  15.                 {
  16.                         ;
  17.                 }
  18.         }
  19. }

  20. //按键初始化函数
  21. void KEY_Init(void) //IO初始化
  22. {
  23.          GPIO_InitTypeDef GPIO_InitStructure;
  24.         //初始化KEY0-->GPIOA.1  上拉输入
  25.          RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//使能PORTA,

  26.         GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2;//PE2~4
  27.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //设置成上拉输入
  28.          GPIO_Init(GPIOB, &GPIO_InitStructure);//初始化GPIOA1
  29. }

  30. int KEY_Read()
  31. {
  32.                 if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_0) == 0)
  33.                 {
  34.                         return PUSH_UP;
  35.                 }
  36.                 else if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_1) == 0)
  37.                 {
  38.                         return PUSH_DOWN;
  39.                 }
  40.                 else if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_2) == 0)
  41.                 {
  42.                         return PUSH_OK;
  43.                 }
  44.                 else
  45.                         return PUSH_NONE;
  46. }

  47. void FAN_Init()
  48. {
  49.         GPIO_InitTypeDef  GPIO_InitStruct;
  50.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  51.         GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
  52.         GPIO_InitStruct.GPIO_Pin=GPIO_Pin_1;
  53.         GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
  54.         GPIO_Init(GPIOA,&GPIO_InitStruct);        
  55.         
  56.         GPIO_SetBits(GPIOA,GPIO_Pin_1);        
  57. }

  58. void Beep_Init()
  59. {
  60.         GPIO_InitTypeDef  GPIO_InitStruct;
  61.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  62.         GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
  63.         GPIO_InitStruct.GPIO_Pin=GPIO_Pin_4;
  64.         GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
  65.         GPIO_Init(GPIOA,&GPIO_InitStruct);        
  66.         
  67.         GPIO_SetBits(GPIOA,GPIO_Pin_4);        
  68. }

  69. void LED_Init()
  70. {
  71.         GPIO_InitTypeDef  GPIO_InitStruct;
  72.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  73.         GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
  74.         GPIO_InitStruct.GPIO_Pin=GPIO_Pin_2 | GPIO_Pin_3;
  75.         GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
  76.         GPIO_Init(GPIOA,&GPIO_InitStruct);        
  77.         
  78.         GPIO_SetBits(GPIOA,GPIO_Pin_2);        
  79.         GPIO_SetBits(GPIOA,GPIO_Pin_3);        
  80. }


  81. int main(void)
  82. {         
  83.         int key;
  84.         int times;
  85.         int status[4] = { 0 };
  86.         uint16_t val;
  87.         u8 temp = 0, hum = 0;
  88.         int i = 2;
  89.         char buf[100] = { 0 };
  90.         delay_init()        ;
  91.         LCD_Init() ;         
  92.         Adc_Init();
  93.         DHT11_Init();
  94.         KEY_Init();
  95.         LED_Init();
  96.         FAN_Init();
  97.         Beep_Init();
  98.         while(1)
  99.         {
  100.                 DHT11_Read_Data(&temp, &hum);
  101.                 sprintf(buf, "temp: %d  hum:%d", temp, hum);
  102.                 LCD_P6x8Str(1, 0, buf);
  103.                 val = Get_Adc();  //得到对应通道的adc值
  104.                 sprintf(buf, "light:%d  ", val);
  105.                 LCD_P6x8Str(1, 1, buf);
  106.                 LCD_P6x8Str(1, 2, "LED1     ");        
  107.                 LCD_P6x8Str(1, 3, "LED2     ");        
  108.                 LCD_P6x8Str(1, 4, "BEEP     ");        
  109.                 LCD_P6x8Str(1, 5, "FAN      ");        
  110.                 LCD_P6x8Str(40, i, "*");        //
  111.                 sprintf(buf, "L1:%d L2:%d BE:%d FAN:%d", status[0], status[1], status[2], status[3]);
  112.                 LCD_P6x8Str(1, 6, buf);        
  113.                 for (times = 0; times < 5000; ++times)
  114.                 {
  115.                         key = KEY_Read();
  116.                         if (key != PUSH_NONE)
  117.                         {               
  118.                                 main_delay(200);
  119.                                 break;
  120.                         }
  121.                 }               
  122.                 if(key == PUSH_DOWN)
  123.                 {
  124.                         i++;
  125.                         if(i > 5)
  126.                                 i = 2;
  127.                 }
  128.                 else if(key == PUSH_UP)
  129.                 {
  130.                         i--;
  131.                         if(i < 2)
  132.                                 i = 5;
  133.                 }
  134.                 else if(key == PUSH_OK)
  135.                 {
  136.                         if(i == 2)
  137.                         {
  138.                                 status[0] = !status[0];
  139.                                 status[0] ? GPIO_ResetBits(GPIOA,GPIO_Pin_2) : GPIO_SetBits(GPIOA,GPIO_Pin_2);               
  140.                         }
  141.                         else if(i == 3)
  142.                         {
  143.                                 status[1] = !status[1];
  144.                                 status[1] ? GPIO_ResetBits(GPIOA,GPIO_Pin_3) : GPIO_SetBits(GPIOA,GPIO_Pin_3);                        
  145.                         }
  146.                         else if(i == 4)
  147.                         {
  148.                                 status[2] = !status[2];
  149.                                 status[2] ? GPIO_ResetBits(GPIOA,GPIO_Pin_4) : GPIO_SetBits(GPIOA,GPIO_Pin_4);                                                
  150.                         }
  151.                         else if(i == 5)
  152.                         {
  153.                                 status[3] = !status[3];
  154.                                 status[3] ? GPIO_ResetBits(GPIOA,GPIO_Pin_1) : GPIO_SetBits(GPIOA,GPIO_Pin_1);                                                                        
  155.                         }
  156.                 }
  157.         }
  158. }
复制代码
51hei.png
所有资料51hei提供下载:
综合.7z (310.36 KB, 下载次数: 140)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:1000026 发表于 2022-1-5 22:18 | 显示全部楼层
能简单描述一下,你这设计的功能吗?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表