用stm32F103ZET6精英版,温度传感器是DS18B20,1602液晶显示屏,利用温度来控制转速,液晶显示屏显示实时转速,也可手动调节转速。(采用pi控制)
电路原理图如下:
单片机源程序如下:
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "timer.h"
#include "lcd1602.h"
#include "encoder.h"
#include "control.h"
#include "usart.h"
#include "usart3.h"
#include "hc05.h"
#include "string.h"
#include "usmart.h"
#include "ds18b20.h"
u8 w=0;
int k=0;
extern int real;
vu8 key=0;
u8 reclen=0;
extern int temperature;
int main(void)
{
delay_init();
LCD_GPIO_Configuration();
LCD1602_Init();
KEY_Init();//按键初始化;
ENCODER_Init();
TIM2_Int_Init(19999,35);
TIM3_PWM_Init(7199,0); //不分频。PWM频率=72000000/900=80Khz
DS18B20_Init();
//usmart_dev.init(72); //初始化USMART
delay_ms(5000); //等待蓝牙模块上电稳定
LCDshowNum(0,0,"EV:",SpeedSet);
LCDshowNum(0,1,"RV:", real);
LCDshowTNum(9,1,"T:",temperature);
// while(HC05_Init()) //初始化ATK-HC05模块
//{
// delay_ms(500);
// }
// delay_ms(100);
// USART3_RX_STA=0;
while(1)
{
delay_ms(200);
temperature=(int)DS18B20_Get_Temp();
LCDshowNum(0,0,"EV:",SpeedSet);
LCDshowNum(0,1,"RV:", real);
LCDshowTNum(9,1,"T:",temperature);
key=KEY_Scan(0);
switch(key)
{
case KEY0_PRES:
SpeedSet+=100;
k++;
LCDshowNum(0,0,"EV:",SpeedSet);
break;
case KEY1_PRES:
SpeedSet-=100;
k++;
LCDshowNum(0,0,"EV:",SpeedSet);
break;
default:break;
}
if(k==0&&temperature>270)
{
SpeedSet=2200;
LCDshowNum(0,0,"EV:",SpeedSet);
}
if(k==0&&temperature<270&&temperature>250)
{
SpeedSet=2100;
LCDshowNum(0,0,"EV:",SpeedSet);
}
if(k==0&&temperature<250&&temperature>200&&temperature==200&&temperature==250)
{
SpeedSet=2000;
LCDshowNum(0,0,"EV:",SpeedSet);
}
if(k==0&&temperature<200)
{
SpeedSet=1800;
LCDshowNum(0,0,"EV:",SpeedSet);
}
}
}
上一篇:详细stm32f103c8t6引脚说明中文
下一篇:STM32+SHT30(DS18B20)+0.96寸OLED(IIC)的温度湿度显示程序
推荐阅读最新更新时间:2024-11-10 20:49