当前位置:   article > 正文

stm32单片机DS18B20智能温控风扇控制系统Proteus仿真全套资料_stm32 风扇控制 参考程序

stm32 风扇控制 参考程序

 一:功能介绍

1、采用stm32单片机+LCD1602+ds18b20温度传感器+按键+蜂鸣器+电机,制作一个多功能可显示温湿度、光照强度的可调时钟闹钟;

2、通过按键设置温度阈值,LCD1602显示设置的温度阈值;

3、当ds18b20检测温度大于设置阈值,蜂鸣器进行报警提醒,风扇自动打开进行散热;

4、LCD1602显示ds18b20采集的温度、和设置的温度阈值;

二:仿真演示视频+程序简要讲解:(程序有中文注释,新手容易看懂)

115-基于stm32单片机DS18B20智能温控风扇控制系统Proteus仿真+程序源码+讲解视频

三:设计软件介绍

本设计使用C语言编程设计,程序代码采用keil5编写,程序有中文注释,新手容易看懂,仿真采用Proteus软件进行仿真演示视频使用的是Proteus8.9版本;资料包里有相关软件包,可自行下载安装。

四:程序打开方法

特别注意:下载资料包以后一定要先解压!(建议解压到桌面上,文件路径太深会导致程序打开异常),解压后再用keil5打开。

3e7503aae38232b7154b91cd954c3f32.png

86096350633c3de7a4a0bc7a1929a800.png

  1. 程序部分展示,有中文注释,新手容易看懂
  2. /*****************引脚配置********************/
  3. void GPIO_Configuration(void)
  4. {
  5. GPIO_InitTypeDef GPIO_InitStructure;
  6. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
  7. //LCD1602 管脚
  8. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8| GPIO_Pin_9| GPIO_Pin_10| GPIO_Pin_11| GPIO_Pin_12| GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15;
  9. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  10. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
  11. GPIO_Init(GPIOB, &GPIO_InitStructure);
  12. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 |GPIO_Pin_6|GPIO_Pin_5;
  13. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  14. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  15. GPIO_Init(GPIOB, &GPIO_InitStructure);
  16. }
  17. void IO_out( void )
  18. {
  19. GPIO_InitTypeDef GPIO_InitStructure;
  20. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOC ,ENABLE);
  21. RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
  22. //按键
  23. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0| GPIO_Pin_1| GPIO_Pin_2| GPIO_Pin_3;
  24. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  25. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;;
  26. GPIO_Init(GPIOC, &GPIO_InitStructure);
  27. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  28. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  29. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  30. GPIO_Init(GPIOC, &GPIO_InitStructure);
  31. }
  32. void Delay_DS18B20(int num)
  33. {
  34. while(num--) ;
  35. }
  36. void anjiansaomiao(void)
  37. {
  38. //表明按下
  39. if(k1 == 1)
  40. {
  41. wenduset++; while(k1!=0);
  42. if(wenduset>100) wenduset=100;
  43. }
  44. //表明按下
  45. if(k2 == 1)
  46. {
  47. wenduset--; while(k2!=0);
  48. if(wenduset<1) wenduset=1;
  49. }
  50. }
  51. int main(void)
  52. {
  53. int t;
  54. short tem,tem1;
  55. GPIO_Configuration();//初始化
  56. Init1602();
  57. IO_out();
  58. delay_init();
  59. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  60. GPIO_InitTypeDef g;
  61. g.GPIO_Mode = GPIO_Mode_Out_PP;
  62. g.GPIO_Speed = GPIO_Speed_10MHz;
  63. g.GPIO_Pin = GPIO_Pin_8 ;
  64. GPIO_Init(GPIOA,&g);
  65. GPIO_SetBits(GPIOA,GPIO_Pin_8); //输出1
  66. t=DS18B20_DQ_IN;
  67. while(t){
  68. DS18B20_IO_OUT(); //SET PG11 OUTPUT
  69. DS18B20_DQ_OUT=0; //拉低DQ
  70. Delay_DS18B20(750); //拉低750us
  71. DS18B20_DQ_OUT=1; //DQ=1
  72. Delay_DS18B20(15); //15US
  73. DS18B20_IO_IN(); //SET PG11 INPUT
  74. Delay_DS18B20(100);
  75. t=DS18B20_DQ_IN;
  76. }
  77. tem=DS18B20_Get_Temp();//读取温度
  78. Delay_DS18B20(1000000);
  79. while(1)
  80. {
  81. tem=DS18B20_Get_Temp();//读取温度
  82. if( tem>0)
  83. {
  84. WrByte1602(0,8,'+');
  85. WrByte1602(0,9,AsciiCode[tem%1000/100]);//显示+温度
  86. WrByte1602(0,10,AsciiCode[tem%100/10]);
  87. WrByte1602(0,12,AsciiCode[tem%10]);
  88. }
  89. else
  90. {
  91. tem1=-(tem);
  92. tem1=tem1+1;
  93. WrByte1602(0,8,'-');
  94. WrByte1602(0,9,AsciiCode[tem1%1000/100]);//显示-温度
  95. WrByte1602(0,10,AsciiCode[tem1%100/10]);
  96. WrByte1602(0,12,AsciiCode[tem1%10]);
  97. }
  98. anjiansaomiao();//扫描按键
  99. WrByte1602(1,10,AsciiCode[wenduset%1000/100]); //显示设置温度
  100. WrByte1602(1,11,AsciiCode[wenduset%100/10]);
  101.   WrByte1602(1,12,AsciiCode[wenduset%10]);  
  102. if(tem/10>wenduset-1) PCout(10)=0;//温度大于等于设置值 风扇自动打开
  103.   else  PCout(10)=1;    
  104. WrByte1602(0,1,' '); //字符显示
  105. WrByte1602(0,2,'T');
  106. WrByte1602(0,3,'E');
  107. WrByte1602(0,4,'M');
  108. WrByte1602(0,5,'P');
  109. WrByte1602(0,6,'=');
  110. WrByte1602(1,1,' '); //字符显示
  111. WrByte1602(1,2,' ');
  112. WrByte1602(1,3,'S');
  113. WrByte1602(1,4,'E');
  114. WrByte1602(1,5,'T');
  115. WrByte1602(1,6,'=');
  116. WrByte1602(0,11,'.');
  117. WrByte1602(0,14,'C');
  118. WrByte1602(1,14,'C');
  119. }
  120. }

:仿真文件(采用Proteus打开)

3ab795d73a1f83889ace13798bd14643.png

f06e2a4e55669079e5b5571a072e4b00.png

061720c610f93e6319c2b9530d8d39bb.png

:资料清单展示(文件中包含的相关资料)

f56421530db59448b8384af8cdc410b1.png

百度云盘下载链接

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/770851
推荐阅读
相关标签
  

闽ICP备14008679号