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

 一:功能介绍

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

程序部分展示,有中文注释,新手容易看懂
/*****************引脚配置********************/
void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);


  //LCD1602 管脚      
  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;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;  
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 |GPIO_Pin_6|GPIO_Pin_5;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;  
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOB, &GPIO_InitStructure);  


}
void IO_out( void )
{
  GPIO_InitTypeDef GPIO_InitStructure;
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOC ,ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
  //按键
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0| GPIO_Pin_1| GPIO_Pin_2| GPIO_Pin_3;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;  
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;;
  GPIO_Init(GPIOC, &GPIO_InitStructure);  


  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;  
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOC, &GPIO_InitStructure);  


}
void Delay_DS18B20(int num)
{
  while(num--) ;
}


void anjiansaomiao(void)
{


  //表明按下 
  if(k1 == 1)
  {  
    wenduset++;  while(k1!=0);  
    if(wenduset>100) wenduset=100;        
  }
    
  //表明按下 
  if(k2 == 1)
  {
    wenduset--;  while(k2!=0);  
    if(wenduset<1) wenduset=1;
  }  


}
int main(void)
{
  int t;
  short tem,tem1;
  GPIO_Configuration();//初始化     
  Init1602(); 
  IO_out();
  delay_init();
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  GPIO_InitTypeDef g;
  g.GPIO_Mode = GPIO_Mode_Out_PP;
  g.GPIO_Speed = GPIO_Speed_10MHz;
  g.GPIO_Pin = GPIO_Pin_8  ;
  GPIO_Init(GPIOA,&g);
   GPIO_SetBits(GPIOA,GPIO_Pin_8);    //输出1


   t=DS18B20_DQ_IN;
while(t){
    DS18B20_IO_OUT();   //SET PG11 OUTPUT


    DS18B20_DQ_OUT=0;   //拉低DQ
    Delay_DS18B20(750);       //拉低750us
    DS18B20_DQ_OUT=1;   //DQ=1 
    Delay_DS18B20(15);       //15US
    DS18B20_IO_IN();  //SET PG11 INPUT   
    Delay_DS18B20(100);
    t=DS18B20_DQ_IN;
}
     tem=DS18B20_Get_Temp();//读取温度


  Delay_DS18B20(1000000);
  while(1)
  {
    tem=DS18B20_Get_Temp();//读取温度
if(  tem>0)         
  {  
  WrByte1602(0,8,'+'); 
  WrByte1602(0,9,AsciiCode[tem%1000/100]);//显示+温度
  WrByte1602(0,10,AsciiCode[tem%100/10]);
  WrByte1602(0,12,AsciiCode[tem%10]);
        
  }
  else 
  {  
    tem1=-(tem);
    tem1=tem1+1;
  WrByte1602(0,8,'-'); 
  WrByte1602(0,9,AsciiCode[tem1%1000/100]);//显示-温度
  WrByte1602(0,10,AsciiCode[tem1%100/10]);
  WrByte1602(0,12,AsciiCode[tem1%10]);
    
  }
      anjiansaomiao();//扫描按键  
  
  WrByte1602(1,10,AsciiCode[wenduset%1000/100]);  //显示设置温度
  WrByte1602(1,11,AsciiCode[wenduset%100/10]);
  WrByte1602(1,12,AsciiCode[wenduset%10]);  
  if(tem/10>wenduset-1)  PCout(10)=0;//温度大于等于设置值  风扇自动打开
  else  PCout(10)=1;    
  WrByte1602(0,1,' '); //字符显示
  WrByte1602(0,2,'T'); 
  WrByte1602(0,3,'E'); 
  WrByte1602(0,4,'M'); 
  WrByte1602(0,5,'P'); 
  WrByte1602(0,6,'='); 
  WrByte1602(1,1,' '); //字符显示
  WrByte1602(1,2,' '); 
  WrByte1602(1,3,'S'); 
  WrByte1602(1,4,'E'); 
  WrByte1602(1,5,'T'); 
  WrByte1602(1,6,'='); 


  WrByte1602(0,11,'.');   
  WrByte1602(0,14,'C'); 
  WrByte1602(1,14,'C'); 
  }
}

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

3ab795d73a1f83889ace13798bd14643.png

f06e2a4e55669079e5b5571a072e4b00.png

061720c610f93e6319c2b9530d8d39bb.png

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

f56421530db59448b8384af8cdc410b1.png

百度云盘下载链接

  • 14
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
STM32F407单片机读写 DS18B20温度传感器 并串口屏显示DEMO软件例程源码,可以做为你的学习设计参考。 int main(void) { uint8_t DS18B20ID[8]; float temperature; /* 复位所有外设,初始化Flash接口和系统滴答定时器 */ HAL_Init(); /* 配置系统时钟 */ SystemClock_Config(); /* 初始化串口并配置串口断优先级 */ MX_DEBUG_USART_Init(); HMI_USARTx_Init(); while(DS18B20_Init()) { printf("DS18B20温度传感器不存在\n"); HAL_Delay(1000); } printf("检测到DS18B20温度传感器,并初始化成功\n"); DS18B20_ReadId(DS18B20ID); /* 无限循环 */ while (1) { temperature=DS18B20_GetTemp_MatchRom(DS18B20ID); /* 打印通过 DS18B20 序列号获取的温度值 */ printf("获取该序列号器件的温度:%.1f\n",temperature); HMI_value_setting("page1.gross.val",temperature*10); HAL_Delay(1000); } } /** * 函数功能: 向串口屏发送数据 * 输入参数: 无 * 返 回 值: 无 * 说 明: 无 */ void HMI_value_setting(const char *val_str,uint32_t value) { uint8_t tmp_str[30]={0}; uint8_t i; sprintf((char *)tmp_str,"%s=%d",val_str,value); for(i=0;iDR=tmp_str[i]; while(__HAL_UART_GET_FLAG(&husartx_HMI, UART_FLAG_TXE) == RESET); } HMI_USARTx->DR=0xFF; while(__HAL_UART_GET_FLAG(&husartx_HMI, UART_FLAG_TXE) == RESET); HMI_USARTx->DR=0xFF; while(__HAL_UART_GET_FLAG(&husartx_HMI, UART_FLAG_TXE) == RESET); HMI_USARTx->DR=0xFF; while(__HAL_UART_GET_FLAG(&husartx_HMI, UART_FLAG_TXE) == RESET); } /** * 函数功能: 向串口屏发送浮点数据 * 输入参数: 无 * 返 回 值: 无 * 说 明: 无 */ void HMI_string_setting(const char *val_str,int32_t value) { uint8_t tmp_str[50]={0}; uint8_t i; float temp=(float)value; sprintf((char *)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值