(1)主函数
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
各功能模块的程序如下:
(1)主函数
#include
#include
#include "warning.h"
#include "disp.h"
#include "temp.h"
#include "humi.h"
#include "light.h"
#include "key.h"
#define uchar unsigned char
#define uint unsigned int
uchar alter_flag=1;
uchar alter_num=1;
uint count=0,Time_Out=0;
uchar change_flag=0;
void main(void)
{
WDTCR|=0XE0;
init_lcd12864();//初始化LCD12864
init_key();//初始化按键
init_warning();//初始化LED和蜂鸣器
init_adc_port();//初始化ADC输入端
init_adc(5);//初始化ADC寄存器
write_str(0x80,
write_str(0x90,
write_str(0x88,
write_str(0x98,
lcd_delay(30000);
clear_screen();
while(1)
{
while(alter_flag)//(while一级嵌套)
{
write_str(0x80,按OK按键进行系统);
write_str(0x90,运行参数修改!!);
write_str(0x88,按BACK键跳过修改);
write_str(0x98,选项!);
count++;
if(count==50000)
{
Time_Out++;
}
if((Time_Out>65000)||((key_ value==BACK)))
{
key_value=0;
clear_screen();//清屏
alter_flag=0;
break;//超时或者按BACK退出参数修改
}
else if(key_value==OK)//修改参数
{
key_value=0;
clear_screen();//清屏 while(alter_flag)//(while二级嵌套)
{
if(key_value==LEFT)
{
key_value=0;
alter_num--;
if(alter_num==0)
alter_num=4;
}
else if(key_value==RIGHT) {
key_value=0;
alter_num++;
if(alter_num==5)
alter_num=1;
}
else if(key_value==BACK) {
key_value=0;
clear_screen();//清屏
write_str(0x90,保存设置好的数据);
write_str(0x88,并退出,请按OK键);
while(key_value!=OK);
clear_screen();//清屏
key_value=0;
alter_flag=0;
break;
}
write_flag(alter_num);//修改项指示
disp_parament("湿度阈值:", H_threshold,0x81);
disp_parament("温度阈值:", T_threshold,0x91);
disp_parament("光强阈值:", L_threshold,0x89);
disp_parament("风速阈值:", W_threshold,0x99);
if(key_value==OK)
{
key_value=0;
clear_screen();//清屏
change_flag=1;
}
while(change_flag)//(while 三级嵌套)修改标志置位时,开始修改参数
{
switch(alter_num)
{
case 1 :disp_parament("湿度阈值:",H_threshold,0x81);break;
case 2 :disp_parament("温度阈值:",T_threshold,0x81);break;
case 3 :disp_parament("光强阈值:",L_threshold,0x81);break;
case 4 :disp_parament("风速阈值:",W_threshold,0x81);break;
default:break;
}
write_str(0x88,"设置好后请按OK键");
write_str(0x98,"保存并返回!!!");
if(alter_num==1)//修改湿度阈值
{ if(key_value==LEFT)
{
key_value=0;
H_threshold-=5;
}
if(key_value==RIGHT)
{
key_value=0;
H_threshold+=5;
}
}
if(alter_num==2)//修改温度阈值
{
if(key_value==LEFT)
{
key_value=0;
T_threshold--;
}
if(key_value==RIGHT)
{
key_value=0;
T_threshold++;
}
}
if(alter_num==3)//修改光强阈值
{ if(key_value==LEFT)
{
key_value=0;
L_threshold-=5;
}
if(key_value==RIGHT)
{
key_value=0; L_threshold+=5;
}
}
if(alter_num==4)//修改风速阈值
{ if(key_value==LEFT)
{
key_value=0;
W_threshold--;
}
if(key_value==RIGHT)
{
key_value=0;
W_threshold++;
}
}
if(key_value==OK)//保存退出
{
key_value=0;
change_flag=0;
clear_screen();//清屏
}
}
}
}
else;;
}
//------------------数据处理--------------------
pro_humi_data();//处理湿度数据
H_printf("H1:",DHT1a,0X80);
H_printf("H2:",DHT2a,0X84); //显示
pro_temp_data();//处理温度数据
T_printf("T1:",temp_data[0], 0X90);
T_printf("T2:",temp_data[3],0X94); pro_light_data();//处理光照数据
L_printf("L1:",Lux1,0X88);
L_printf("L2:",Lux2,0X8C);//显示 L_printf("W:",wind_speed_data,0x98);//显示模拟风速
if(key_value==BACK)//重新设置系统运行参数
{
key_value=0;
clear_screen();//清屏
write_str(0x80,"你想重新设置系统");
write_str(0x90,"运行参数吗?");
write_str(0x88,"如果是,请按OK键");
write_str(0x98,"进入设置界面!")
while(key_value!=OK);
clear_screen();//清屏
key_value=0;
alter_flag=1;
}
}
}