基于STM32f103zet6的智能樓宇程序- #include "stm32f10x.h"
- #include "delay.h"
- #include "led.h"
- #include "key.h"
- #include "bsp_lcd.h"
- #include "dht11.h"
- #include "GY30.h"
- #include "qc.h"
- void display(void);
- extern const unsigned char gImage_tu1[153608];
- extern const unsigned char gImage_two[153608];
- u8 yema=0;
- u8 s=0;
- u8 key_num;
- int num=30;
- char str[50];
- int ws = 40,wx = 6,ss = 70,sx = 30,gs = 1000,gx = 9;
- u8 wd,sd;
- u32 gz;
- void bj(void)
- {
- if(wd>ws || wd<wx)
- {
- BEEP_ON;
- }
- else
- {
- BEEP_OFF;
- }
- if(sd>ss || sd<sx)
- {
- LED4_ON;
- }
- else
- {
- LED4_OFF;
- }
- if(gz>gs)
- {
- LED2_ON;
- }
- else
- {
- LED2_OFF;
- }
- if(gz<gx)
- {
- LED1_ON;
- }
- else
- {
- LED1_OFF;
- }
- }
- void jiemian1(void)
- {
- yema = 1;//記錄當前頁碼
- display();
- //
- // BACK_COLOR = GRAY; //背景灰色
- // POINT_COLOR = BLACK; //字體黑色
- // LCD_ShowButton(70,20,168,65,"LED_ON");//16號字體
- // LCD_ShowButton(70,100,168,145,"LED_OFF");//16號字體
- //
- // LCD_ShowButton(70,180,168,225,"光照:");//16號字體
- //
- // LCD_ShowButton(70,260,168,305,"PM2.5:");//16號字體
- // LCD_ShowButton(162,284,239,319,"下一頁");//16號字體
- }
- void jiemian2(void)
- {
- yema = 2;//記錄當前頁碼
-
- Paint_Bmp(0,0,240,320,gImage_two); //畫圖
- BACK_COLOR = GRAY; //背景灰色
- POINT_COLOR = BLACK; //字體黑色
-
- sprintf(str,"%3d ",ws);//將濕度值轉換成字符串
- LCD_ShowString(120,10,500,500,24,str,0);//將字符串的內容顯示出來
- LCD_ShowString(155,15,500,500,16,"℃",0);//將字符串的內容顯示出來
-
- sprintf(str,"%3d ",wx);//將濕度值轉換成字符串
- LCD_ShowString(120,40,500,500,24,str,0);//將字符串的內容顯示出來
- LCD_ShowString(155,45,500,500,16,"℃",0);//將字符串的內容顯示出來
-
- sprintf(str,"%3d ",ss);//將濕度值轉換成字符串
- LCD_ShowString(120,110,500,500,24,str,0);//將字符串的內容顯示出來
- LCD_ShowString(155,110,500,500,24,"%",0);//將字符串的內容顯示出來
-
- sprintf(str,"%3d ",sx);//將濕度值轉換成字符串
- LCD_ShowString(120,140,500,500,24,str,0);//將字符串的內容顯示出來
- LCD_ShowString(155,140,500,500,24,"%",0);//將字符串的內容顯示出來
- sprintf(str,"%3d ",gs);//將濕度值轉換成字符串
- LCD_ShowString(140,180,500,500,24,str,0);//將字符串的內容顯示出來
- // LCD_ShowString(170,180,500,500,24,"lx",0);//將字符串的內容顯示出來
-
- sprintf(str,"%3d ",gx);//將濕度值轉換成字符串
- LCD_ShowString(140,200,500,500,24,str,0);//將字符串的內容顯示出來
- // LCD_ShowString(170,200,500,500,24,"lx",0);//將字符串的內容顯示出來
-
- LCD_ShowButton(70,6,120,36,"溫度上閾");//16號字體
- LCD_ShowButton(70,36,120,66,"溫度下閾");//16號字體
-
- LCD_ShowButton(70,106,120,136,"濕度上閾");//16號字體
- LCD_ShowButton(70,136,120,166,"濕度下閾");//16號字體
-
- LCD_ShowButton(70,176,120,206,"光照上閾");//16號字體
- LCD_ShowButton(70,206,120,236,"光照下閾");//16號字體
-
- LCD_ShowButton(70,266,120,296,"空氣質量");//16號字體
-
- }
- u8 status=0;
- void gongneng(void)
- {
- if(tp_dev.x[0]>162 && tp_dev.y[0]>284 && tp_dev.x[0]<239 && tp_dev.y[0]<319)
- {
- jiemian1();//切換界面
- }
- else if(tp_dev.x[0]>70 && tp_dev.y[0]>6 && tp_dev.x[0]<120 && tp_dev.y[0]<36)
- {
- status=1;
- }
- else if(tp_dev.x[0]>70 && tp_dev.y[0]>36 && tp_dev.x[0]<120 && tp_dev.y[0]<66)
- {
- status=2;
- }
- else if(tp_dev.x[0]>70 && tp_dev.y[0]>106 && tp_dev.x[0]<120 && tp_dev.y[0]<136)
- {
- status=3;
- }
- else if(tp_dev.x[0]>70 && tp_dev.y[0]>136 && tp_dev.x[0]<120 && tp_dev.y[0]<166)
- {
- status=4;
- }
- else if(tp_dev.x[0]>70 && tp_dev.y[0]>176 && tp_dev.x[0]<120 && tp_dev.y[0]<206)
- {
- status=5;
- }
- else if(tp_dev.x[0]>70 && tp_dev.y[0]>206 && tp_dev.x[0]<120 && tp_dev.y[0]<236)
- {
- status=6;
- }
- }
- void LED_Ctrl(void)
- {
- if(tp_dev.x[0]>10 && tp_dev.y[0]>10 && tp_dev.x[0]<55 && tp_dev.y[0]<65)
- {
- LED1_ON;//開燈
- }
- else if(tp_dev.x[0]>70 && tp_dev.y[0]>100 && tp_dev.x[0]<168 && tp_dev.y[0]<145)
- {
- LED1_OFF;//關燈
- }
- else if(tp_dev.x[0]>162 && tp_dev.y[0]>284 && tp_dev.x[0]<239 && tp_dev.y[0]<319)
- {
- jiemian2();//切換界面
- }
- }
- void BEEP_Ctrl(void)
- {
- if(tp_dev.x[0]>70 && tp_dev.y[0]>20 && tp_dev.x[0]<168 && tp_dev.y[0]<65)
- {
- BEEP_ON;//開蜂鳴器
- }
- else if(tp_dev.x[0]>70 && tp_dev.y[0]>100 && tp_dev.x[0]<168 && tp_dev.y[0]<145)
- {
- BEEP_OFF;//關蜂鳴器
- }
- else if(tp_dev.x[0]>162 && tp_dev.y[0]>284 && tp_dev.x[0]<239 && tp_dev.y[0]<319)
- {
- jiemian1();//切換界面
- }
- }
- void display(void)
- {
- Paint_Bmp(0,0,240,320,gImage_tu1); //畫圖
- DHT11_Read_Data(); //讀取溫濕度數據
- wd = Temperature;
- sd = Humidity;
- sprintf(str,"%3d℃",wd);//將溫度值轉換成字符串
- POINT_COLOR = BLACK;
- BACK_COLOR = WHITE;
- LCD_ShowString(145,48,500,500,16,str,0);//將字符串的內容顯示出來
-
- sprintf(str,"%3d %%",sd);//將濕度值轉換成字符串
- LCD_ShowString(145,115,500,500,16,str,0);//將字符串的內容顯示出來
-
- BH1750_ReadDate(); //讀取光照強度
- gz = (u32)BH1750_Value;
- sprintf(str,"%5d lx",gz);//將濕度值轉換成字符串
- LCD_ShowString(145,180,500,500,16,str,0);//將字符串的內容顯示出來
-
- if(KQ == 1)
- {
- LCD_ShowString(145,240,500,500,16,"fine",0);
- }
- else
- {
- LCD_ShowString(145,240,500,500,16,"DANGER",0);
- }
- }
- //主函數
- int main(void)
- {
- delay_init(); //延時初始化,必須初始化
- LED_Init(); //LED初始化
- KEY_Init(); //按鍵初始化
- BEEP_Init();
- TFTLCD_Init(); //屏幕初始化
- TP_Init(); //觸摸初始化
- // TP_Adjust(); //觸摸校準
- DHT11_Init();
- Init_BH1750();
-
- tp_dev.xfac = 0.075815;
- tp_dev.xoff = -32;
- tp_dev.yfac = 0.086930;
- tp_dev.yoff = -17;
-
- jiemian1();
-
-
- while(1)
- {
- if(yema == 1) //判斷是否在第一頁
- {
- jiemian1();
- }
-
- TP_Scan(0);//觸摸掃描
-
- bj();
-
- key_num = key_scan();
- if(status == 1)
- {
- if(key_num == 1)
- {
- ws++;
- sprintf(str,"%3d ",ws);//將濕度值轉換成字符串
- LCD_ShowString(120,10,500,500,24,str,0);//將字符串的內容顯示出來
- LCD_ShowString(155,15,500,500,16,"℃",0);//將字符串的內容顯示出來
- }
- if(key_num == 2)
- {
- ws--;
- sprintf(str,"%3d ",ws);//將濕度值轉換成字符串
- LCD_ShowString(120,10,500,500,24,str,0);//將字符串的內容顯示出來
- LCD_ShowString(155,15,500,500,16,"℃",0);//將字符串的內容顯示出來
- }
- }
-
- if(status == 2)
- {
- if(key_num == 1)
- {
- wx++;
- sprintf(str,"%3d ",wx);//將濕度值轉換成字符串
- LCD_ShowString(120,40,500,500,24,str,0);//將字符串的內容顯示出來
- LCD_ShowString(155,45,500,500,16,"℃",0);//將字符串的內容顯示出來
- }
- if(key_num == 2)
- {
- wx--;
- sprintf(str,"%3d ",wx);//將濕度值轉換成字符串
- LCD_ShowString(120,40,500,500,24,str,0);//將字符串的內容顯示出來
- LCD_ShowString(155,45,500,500,16,"℃",0);//將字符串的內容顯示出來
- }
- }
-
- if(status == 3)
- {
- if(key_num == 1)
- {
- ss++;
- sprintf(str,"%3d ",ss);//將濕度值轉換成字符串
- LCD_ShowString(120,110,500,500,24,str,0);//將字符串的內容顯示出來
- LCD_ShowString(155,110,500,500,24,"%",0);//將字符串的內容顯示出來
- }
- if(key_num == 2)
- {
- ss--;
- sprintf(str,"%3d ",ss);//將濕度值轉換成字符串
- LCD_ShowString(120,110,500,500,24,str,0);//將字符串的內容顯示出來
- LCD_ShowString(155,110,500,500,24,"%",0);//將字符串的內容顯示出來
- }
- }
-
- if(status == 4)
- {
- if(key_num == 1)
- {
- sx++;
- sprintf(str,"%3d ",sx);//將濕度值轉換成字符串
- LCD_ShowString(120,140,500,500,24,str,0);//將字符串的內容顯示出來
- LCD_ShowString(155,140,500,500,24,"%",0);//將字符串的內容顯示出來
- }
- if(key_num == 2)
- {
- sx--;
- sprintf(str,"%3d ",sx);//將濕度值轉換成字符串
- LCD_ShowString(120,140,500,500,24,str,0);//將字符串的內容顯示出來
- LCD_ShowString(155,140,500,500,24,"%",0);//將字符串的內容顯示出來
- }
- }
-
- if(status == 5)
- {
- if(key_num == 1)
- {
- gs++;
- sprintf(str,"%3d ",gs);//將濕度值轉換成字符串
- LCD_ShowString(140,180,500,500,24,str,0);//將字符串的內容顯示出來
- }
- if(key_num == 2)
- {
- gs--;
- sprintf(str,"%3d ",gs);//將濕度值轉換成字符串
- LCD_ShowString(140,180,500,500,24,str,0);//將字符串的內容顯示出來
- }
- }
-
- if(status == 6)
- {
- if(key_num == 1)
- {
- gx++;
- sprintf(str,"%3d ",gx);//將濕度值轉換成字符串
- LCD_ShowString(140,200,500,500,24,str,0);//將字符串的內容顯示出來
- }
- if(key_num == 2)
- {
- gx--;
- sprintf(str,"%3d ",gx);//將濕度值轉換成字符串
- LCD_ShowString(140,200,500,500,24,str,0);//將字符串的內容顯示出來
- }
- }
-
- if(tp_dev.sta & 0x40) //判斷觸摸是否按下
- {
- if(yema == 1) //判斷是否在第一頁
- {
- jiemian1();
- LED_Ctrl();
- }
- else if(yema == 2) //判斷是否在第二頁
- {
- gongneng();
- }
- tp_dev.sta &= 0xbf;//清零第6位
- }
- }
- }
復制代碼 全部資料51hei下載地址:
最終程序.7z
(285.15 KB, 下載次數: 17)
2019-4-9 16:10 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|