#include "led.h"
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "lcd.h"
#include "usart.h"
#include "24cxx.h"
#include "flash.h"
#include "touch.h"
#include "dht11.h"
u8 mode=0;
u8 temperaturelow=18,temperatureup=25;
typedef struct
{
u32 year;
short month;
short day;
short hour;
short minute;
u32 second;
u32 week;
}calendar1;
calendar1 c={2017,7,14,12,45,5};
u32 Isweek(u32 year,u32 month,u32 day);
u32 n,z,w;
u32 m=0;
u32 getMonthdays(u32 year,u32 month);
void clock(void);
void control_task(void);
int main(void)
{
u8 t=0;
u8 temperature;
u8 humidity;
delay_init(); //Ñóê±oˉêy3õê¼»ˉ
NVIC_Configuration(); //éèÖÃNVICÖD¶Ï·Ö×é2:2λÇàÕ¼óÅÏ輶£¬2λÏìó|óÅÏ輶
uart_init(15200); //′®¿ú3õê¼»ˉÎa9600
LED_Init(); //LED¶Ë¿ú3õê¼»ˉ
LCD_Init();
KEY_Init();
POINT_COLOR=RED;//éèÖÃ×ÖìåÎaoìé«
tp_dev.init();
while(DHT11_Init()) //DHT113õê¼»ˉ
{
LCD_ShowString(60,130,200,16,16,"DHT11 Error");//¼ì2éDHT11êÇ·ñᬽó
delay_ms(200);
LCD_Fill(60,130,239,130+16,WHITE);//éèÖÃÎa°×μ×
delay_ms(200);
}
LCD_ShowString(60,70,200,16,16,"DHT11 OK");//èç1ûᬽóÕy3£ ÏÔê¾OK
POINT_COLOR=BLUE;//éèÖÃ×ÖìåÎaà¶é«
LCD_ShowString(60,90,200,16,16,"Temp: C"); //ÔúÆáÄ»éÏÏÔê¾μ±Ç°ÎÂêa¶è
LCD_ShowString(60,110,200,16,16,"Humi: %");
while(1)
{
clock();
if(t%10==0)//ÿ100ms¶áè¡ò»′Î
{
DHT11_Read_Data(&temperature,&humidity); //¶áè¡ÎÂêa¶èÖμ
LCD_ShowNum(60+40,90,temperature,2,16); //ÏÔê¾Î¶è
LCD_ShowNum(60+40,110,humidity,2,16); //ÏÔê¾êa¶è
// printf("ÏÖ3¡Î¶è£o",temperature);
if((30<humidity<50)&&(25>=temperature>=18))
{
LCD_ShowString(35,130,200,16,20,"Humidity suitable");
LCD_Fill(100,130,200,110,WHITE);
}
if((humidity<30&&temperature>=18))
{
LCD_ShowString(35,130,200,16,16,"air dry");
LCD_ShowString(35,150,200,16,16,"add water");
}
if((humidity>40&&temperature>=18))
{
LCD_ShowString(35,130,200,16,16,"air moist");
LCD_ShowString(35,150,200,16,16,"decline water");
}
if(temperature>temperatureup)
{
LCD_ShowString(35,130,200,16,16,"open freeze");
}
if(temperature<temperaturelow)
{
LCD_ShowString(35,130,200,16,16,"central heating");
}
} control_task();
delay_ms(10);
t++;
clock();
if(t==20)
{
t=0;
LED0=!LED0;
}
}
}
void control_task(void)
{
while(1)
{
LCD_ShowString(35,170,200,16,16,"Temp High:");
LCD_ShowString(135,170,200,16,16," + ");
LCD_ShowString(195,170,200,16,16," - ");
LCD_ShowString(35,190,200,16,16,"Temp Low:");
LCD_ShowString(135,190,200,16,16," + ");
LCD_ShowString(195,190,200,16,16," - ");
LCD_ShowNum(165,170,temperatureup,2,16);
LCD_ShowNum(165,190,temperaturelow,2,16);
LCD_ShowString(35,240,200,16,16,"SET");
LCD_ShowString(135,240,200,16,16,"UP");
LCD_ShowString(195,240,200,16,16,"DOWN");
tp_dev.scan(0);
if(tp_dev.sta&TP_PRES_DOWN) //′¥ÃtÆá±»°′ÏÂ
{
if(165>tp_dev.x&&tp_dev.x>135&&135<tp_dev.y&&tp_dev.y<165)
{temperatureup++;}
if(235>tp_dev.x&&tp_dev.x>195&&135<tp_dev.y&&tp_dev.y<165)
{temperatureup--;}
if(165>tp_dev.x&&tp_dev.x>135&&155<tp_dev.y&&tp_dev.y<185)
{temperaturelow++;}
if(235>tp_dev.x&&tp_dev.x>195&&155<tp_dev.y&&tp_dev.y<185)
{temperaturelow--;}
if(80>tp_dev.x&&tp_dev.x>30&&225<tp_dev.y&&tp_dev.y<260)//é趨
{mode++;if(mode>=6)mode=0;}
switch(mode)
{
case 0:
LCD_Fill(60,240,130,320,WHITE);
break;
case 1:
LCD_ShowString(70,240,200,16,16,"minute");
if(165>tp_dev.x&&tp_dev.x>125&&225<tp_dev.y&&tp_dev.y<260)//·Ö
{c.minute++;
if(c.minute>=60)
c.minute=0;}
if(230>tp_dev.x&&tp_dev.x>190&&225<tp_dev.y&&tp_dev.y<260)//·Ö
{c.minute--;
if(c.minute<0)
c.minute=59;}
break;
case 2:
LCD_ShowString(70,240,200,16,16,"HOUR");
if(165>tp_dev.x&&tp_dev.x>125&&225<tp_dev.y&&tp_dev.y<260)//·Ö
{c.hour++;
if(c.hour>=24)
c.hour=0;}
if(230>tp_dev.x&&tp_dev.x>190&&225<tp_dev.y&&tp_dev.y<260)//·Ö
{c.hour--;
if(c.hour<0)
c.hour=23;}
break;
case 3:
LCD_ShowString(70,240,200,16,16,"DATE");
if(165>tp_dev.x&&tp_dev.x>125&&225<tp_dev.y&&tp_dev.y<260)//·Ö
{c.day++;
if (c.day==getMonthdays(c.year,c.month)+1)
c.day=1;}
if(230>tp_dev.x&&tp_dev.x>190&&225<tp_dev.y&&tp_dev.y<260)//·Ö
{ c.day--;
if (c.day==0)
c.day=getMonthdays(c.year,c.month);}
break;
case 4:
LCD_ShowString(70,240,200,16,16,"MONTH");
if(165>tp_dev.x&&tp_dev.x>125&&225<tp_dev.y&&tp_dev.y<260)//·Ö
{c.month++;
if(c.month>=13)
c.month=0;}
if(230>tp_dev.x&&tp_dev.x>190&&225<tp_dev.y&&tp_dev.y<260)//·Ö
{c.month--;
if(c.month<0)
c.month=12;}
break;
case 5:
LCD_ShowString(70,240,200,16,16,"YEAR");
if(165>tp_dev.x&&tp_dev.x>125&&225<tp_dev.y&&tp_dev.y<260)//·Ö
{c.year++;}
if(230>tp_dev.x&&tp_dev.x>190&&225<tp_dev.y&&tp_dev.y<260)//·Ö
{c.year--;}
break;
}
}
}
}
void clock(void)
{ delay_ms(1000);
c.second++;
if(c.second==60) {c.minute++;c.second=0; }
if(c.minute==60) {c.hour++;c.minute=0; }
if (c.hour==24) {c.day++;c.hour=0; }//w
if (c.day==getMonthdays(c.year,c.month)+1) {c.month++;c.day=1; }
if (c.month>12) {c.year++;c.month=1; }
POINT_COLOR=BLUE;
LCD_ShowNum(0,0,c.day,2,16);
LCD_ShowString(20,0,200,16,16,"date.");
LCD_ShowNum(65,0,c.month,2,16);
LCD_ShowString(85,0,200,16,16,"month.");
LCD_ShowNum(150,0,c.year,2,16);
LCD_ShowString(170,0,200,16,16,"yaer.");
LCD_ShowNum(0,30,c.hour,2,16);
LCD_ShowString(20,30,200,16,16,"HOUR:");
LCD_ShowNum(70,30,c.minute,2,16);
LCD_ShowString(100,30,200,16,16,"MINUTE:");
LCD_ShowNum(160,30,c.second,2,16);
LCD_ShowString(180,30,200,16,16,"SECONDS");
}
u32 Isweek(u32 year,u32 month,u32 day)
{
u32 week;
u32 temp=month;
if(temp==1||temp==2)
{
temp+=12; year--;
}
week=(day+2*temp+3*(temp+1)/5+year+year/4-year/100+year/400)%7;
return week;
}
u32 getMonthdays(u32 year,u32 month)
{
switch(month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:return 31;
case 4:
case 6:
case 9:
case 11:return 30;
case 2:
if((c.year%4==0&&c.year%100!=0)||(c.year%100==0&&c.year%400==0))
{
return 29;
}
else{
return 28;
}
default:return 0;
}
}
|