用LCD12864实现显示个人信息和空气中颗粒物质量浓度,根据PM2.5质量浓度分析空气质量等级并显示。
1. 第一个屏显示:设计任务名称,姓名,班级,学号后三位;
2. 第二个屏显示:PM1.0、PM2.5、PM10的质量浓度数据(带单位),显示空气质量等级;
3. 空气颗粒物质量浓度数据和学号后三位通过串口从模拟器接收后显示,显示数据可以与模拟器更改值同步;
4. 可通过按键进行屏幕换;
5. 通过串口上传空气质量等级数值给模拟器,等级数值对应为:1-优,2-良,3-轻度污染,4-中度污染,5-重度污染,6-严重污染,模拟器成功接收会自动显示空气质量等级。
信息未改,勿外泄哦
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include <reg51.h>
- #include "lcd12864.h"
- #include "key.h"
- #include "delay.h"
- #include "uart.h"
- void new_flash_dat(void);
- void keyscan(void);
- void pmsqua_anly(void);
- void screen_1(unsigned char a);
- void screen_2(unsigned int PM1,unsigned int PM2,unsigned int PM10,unsigned int denji);
- void Lcd_cleardat(char hang,char lie,char num);
- unsigned char quality=2;
- unsigned int pr_PM1_0=0,pr_PM2_5=0,pr_PM10=0,pr_sno=0;
- unsigned int PM1_0,PM2_5,PM10,sno;
- unsigned char b=104;print_mode=0;
- void main()
- {
- uart_init();
- Lcd_Init();
- Lcd_Clear();
- screen_1(sno);
-
- while(1)
- {
- keyscan();
- new_flash_dat();
- pmsqua_anly();
- uart_sendbyte(quality);
- }
- }
- void keyscan(void)
- {
- if(key1_scan()!=0)
- {
- print_mode++;
- print_mode%=2;
- Lcd_Clear();
- switch(print_mode)
- {
- case 0:screen_1(sno);break;
- case 1:screen_2(PM1_0,PM2_5,PM10,quality);break;
- default:break;
- }
- }
- }
- void new_flash_dat(void)
- {
- if(print_mode==1&&(PM1_0!=pr_PM1_0||PM2_5!=pr_PM2_5||PM10!=pr_PM10))
- {
- Lcd_Clear();
- pmsqua_anly();
- screen_2(PM1_0,PM2_5,PM10,quality);
- pr_PM1_0=PM1_0;
- pr_PM2_5=PM2_5;
- pr_PM10=PM10;
- }
- if(print_mode==0&&pr_sno!=sno)
- {
- Lcd_Clear();
- screen_1(sno);
- pr_sno=sno;
- }
- }
- void pmsqua_anly(void)
- {
- if(PM2_5<35)
- quality=1;
- else if(PM2_5<75)
- quality=2;
- else if(PM2_5<115)
- quality=3;
- else if(PM2_5<150)
- quality=4;
- else if(PM2_5<250)
- quality=5;
- else quality=6;
- }
- void screen_1(unsigned char a)
- {
- char clas[]="17-1";
- Lcd_Show_Chinese(0,16,12);
- Lcd_Show_Chinese(0,32,13);
- Lcd_Show_Chinese(0,48,14);
- Lcd_Show_Chinese(0,64,15);
- Lcd_Show_Chinese(0,80,16);
- Lcd_Show_Chinese(0,96,17);
-
- Lcd_Show_Chinese(2,16,6);
- Lcd_Show_Chinese(2,32,7);
- Lcd_Show_Char(2,48,':');
- Lcd_Show_Chinese(2,56,9);
- Lcd_Show_Chinese(2,72,10);
- Lcd_Show_Chinese(2,88,11);
-
- Lcd_Show_Chinese(4,16,0);
- Lcd_Show_Chinese(4,32,1);
- Lcd_Show_Char(4,48,':');
- Lcd_Show_Chinese(4,56,2);
- Lcd_Show_Chinese(4,72,3);
- Lcd_Show_String(4,88,clas);
-
- Lcd_Show_Chinese(6,16,4);
- Lcd_Show_Chinese(6,32,5);
- Lcd_Show_Char(6,48,':');
- Lcd_Show_Num(6,56,a);
- }
- void screen_2(unsigned int PM1,unsigned int PM2,unsigned int PM10,unsigned int dengji)
- {
- Lcd_Show_String(0,0,"PM1.0:");
- Lcd_Show_Num(0,48,PM1);
- Lcd_Show_String(0,72,"ug/m^3");
-
- Lcd_Show_String(2,0,"PM2.5:");
- Lcd_Show_Num(2,48,PM2);
- Lcd_Show_String(2,72,"ug/m^3");
-
- Lcd_Show_String(4,0,"PM10 :");
- Lcd_Show_Num(4,48,PM10);
- Lcd_Show_String(4,72,"ug/m^3");
-
- Lcd_Show_Chinese(6,16,18);
- Lcd_Show_Chinese(6,32,19);
- Lcd_Show_Char(6,48,':');
- switch(dengji)
- {
- case 0:Lcd_Show_Chinese(6,56,29);break;
- case 1:Lcd_Show_Chinese(6,56,20);
- Lcd_cleardat(6,72,6);break;
- case 2:Lcd_Show_Chinese(6,56,21);
- Lcd_cleardat(6,72,6);break;
- case 3:Lcd_Show_Chinese(6,56,22);
- Lcd_Show_Chinese(6,72,26);
- Lcd_Show_Chinese(6,88,27);
- Lcd_Show_Chinese(6,104,28);break;
- case 4:Lcd_Show_Chinese(6,56,23);
- Lcd_Show_Chinese(6,72,26);
- Lcd_Show_Chinese(6,88,27);
- Lcd_Show_Chinese(6,104,28);break;
- case 5:Lcd_Show_Chinese(6,56,24);
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
空气质量检测.7z
(366.14 KB, 下载次数: 164)
|