温控智能旋转光纤灯
单片机源程序如下:
- #include "stm32f10x.h"
- #include "oled.h"
- #include "delay.h"
- #include "sys.h"
- #include "dht11.h"
- #include "led.h"
- #include "key.h"
- int main(void)
- {
- u8 t=0;
- u8 s=0;
- u8 temperature;
- u8 humidity;
- LED_Init();
- NVIC_Configuration();
- delay_init();
- DHT11_Init();
- OLED_Init();
- OLED_Clear();
- KEY_Init();
- motor=0;
- while(1)
- {
-
- if(t%80==0)//每100ms读取一次
- {
- OLED_Clear();
- delay_ms(10);
- OLED_ShowString(1,1,"WENDU: C",12);
- OLED_ShowString(1,5,"SHIDU: %",20);
- DHT11_Read_Data(&temperature,&humidity); //读取温湿度值
- OLED_ShowNum(50,1,temperature,2,12); //显示温度
- OLED_ShowNum(50,5,humidity,2,12); //显示湿度
- }
- delay_ms(10);
- t++;
- if(KEY1==0)
- {
- s=s+1;
- delay_ms(10);
- }
-
- if(KEY0==0 || s%2==0)
- {
-
- if(temperature<25)
- {
- LED0 = 0;
- LED1 = 1;
- LED2 = 1;
- motor=0;
- }
- else if(temperature>=25 && temperature<27)
- {
- LED0 = 1;
- LED1 = 0;
- LED2 = 1;
- motor=0;
- }
- else if(temperature>27)
- {
- LED0 = 1;
- LED1 = 1;
- LED2 = 0;
- motor=1;
- }
- delay_ms(10);
- }
- else
- {
- LED0 = 1;
- LED1 = 1;
- LED2 = 1;
- motor=0;
- }
- }
- }
复制代码
所有代码51hei提供下载:
OLED.7z
(217.29 KB, 下载次数: 30)
|