基于32的呼吸灯源码,包括一氧化碳检测模块等
单片机源程序如下:
- #include "led.h"
- #include "delay.h"
- #include "key.h"
- #include "sys.h"
- #include "usart.h"
- #include "dht11.h"
- #include "timer.h"
- #include "lcd1602.h"
- #define Buf2_Max 200 //串口2缓存长度
- /************* 本地常量声明 **************/
- /************* 本地变量声明 **************/
- //char Uart1_Buf[Buf1_Max];
- char Uart2_Buf[Buf2_Max];
- u8 Times=0,First_Int = 0,shijian=0;
- vu8 Timer0_start; //定时器0延时启动计数器
- vu8 Uart2_Start; //串口2开始接收数据
- vu8 Uart2_End; //串口2接收数据结束
- u8 temperature = 0;
- u8 humidity = 0;
- u8 cowarn = 0;
- char string[100];
- /************* 本地函数声明 **************/
-
- /************* 外部函数和变量声明*****************/
- void main(void)
- {
- u8 t=0;
- u8 dir=1;
- u16 led0pwmval=0;
- delay_init(); //延时函数初始化
- NVIC_Configuration(); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
- LED_Init(); //LED端口初始化
- KEY_Init();
- GPIO_Configuration();
- LCD1602_Init();
- // LCD1602_Show_Str(2, 1, "I love STM32");
- LCD1602_ClearScreen();
-
- while(DHT11_Init()); //DHT11初始化
-
- TIM4_PWM_Init(100-1,720-1); //不分频。PWM频率=72000000/900=80Khz
-
-
- while(1)
- {
-
- DHT11_Read_Data(&temperature,&humidity); //读取温湿度值
- if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_1)==0)
- {
- GPIO_ResetBits(GPIOB,GPIO_Pin_5); //PB.5 输出高
- TIM_SetCompare3(TIM4,99);
- }
- else
- {
- GPIO_SetBits(GPIOB,GPIO_Pin_5); //PB.5 输出高
- TIM_SetCompare3(TIM4,0);
- }
- //LCD1602_ClearScreen();
-
- memset(string, 0, sizeof(string));
- sprintf(string,"Temperature %d",temperature);
- LCD1602_Show_Str(0, 0,string);
-
- memset(string, 0, sizeof(string));
- sprintf(string,"Humidity %d ",humidity);
- LCD1602_Show_Str(0, 1,string);
-
-
- if(dir)led0pwmval+=10;
- else led0pwmval-=10;
- if(led0pwmval>=99)
- {
- dir=0;
- TIM_SetCompare4(TIM4,99);
- }
- if(led0pwmval<=0)
- {
- dir=1;
- TIM_SetCompare4(TIM4,0);
- }
- // TIM_SetCompare1(TIM4,led0pwmval);
- // TIM_SetCompare2(TIM4,99-led0pwmval);
- TIM_SetCompare1(TIM4,led0pwmval);
- TIM_SetCompare2(TIM4,humidity);
-
-
-
-
- delay_ms(5);
- }
- }
复制代码
所有资料51hei提供下载:
基于STM32F107的呼吸灯.rar
(326.71 KB, 下载次数: 9)
|