#include
#include
#include
#include
#include
#include
#include
sbit heater = P2^3;
sbit k1=P1^0; //选择按键
sbit k2=P1^1; //增加按键
sbit k3=P1^2; //减小按键
sbit k4=P1^3;// 确认按键
sbit k5=P1^4; //加热开关按键
sbit k6=P1^5;// 上水开关
unsigned char x;
unsigned char flag = 0;
unsigned char temp_max = 55; //保存温度变量
unsigned char temp_min = 40; //保存湿度变量
unsigned char presskeynum = 0; //按键次数变量
unsigned char Current_MIN[4];
unsigned char Current_MAX[4];
unsigned char integer,symbol,decimal;
/************更新***************/
void updatatime()
{ systemtime datetime;
dsgettime(&datetime); //获取时间
lcdoutput(0,0,"DATE:"); //日期
datezstr(&datetime,datestring);
lcdoutput(5,0,"20");
lcdoutput(7,0,datestring);
lcdoutput(0,1,"TIME:");
for(x=8;x>0;x--) //循环显示时间
{
converttemp();
dsgettime(&datetime);
timezstr(&datetime,timestring);
lcdoutput(5,1,timestring);
delay_ms(5);
}
}
void updatatemp()
{
lcdoutput(0,0,"SWEN:"); //水温
lcdoutput(0,1,"SWEI:"); //水位
lcdoutput(13,0,Current_MAX); //水温
lcdoutput(13,1,Current_MIN);
for(x=8;x>0;x--) //循环显示时间
{
converttemp();
lcdoutput(5,0,tempstr);
depthprocess();
delay_ms(5);
}
}
void key()
{
if (k1==0) //调整按键检测
{
delay_ms(1);
if (k1==0)
{
presskeynum++; flag = ~flag;
if(presskeynum==4)
presskeynum=0;
while(k1==0); //若一直按下,循环
lcdwrite(command,clear_screen);
}
}
if(presskeynum==1)//设置模式温度上限
{
if(k2==0) // 加
{
delay_ms(1);
temp_max++;
if (temp_max>99)
temp_max=99;
while(k2==0); //加上此句必须松按键才处
lcdwrite(command,clear_screen);
}
if(k3==0)//减
{
delay_ms(1);
temp_max--;
if (temp_max<1)
temp_max=1;
while(k3==0); //加上此句必须松按键
lcdwrite(command,clear_screen);
}
}
if(presskeynum==3)//湿度设置
{
if(k2==0)// 加
{
delay_ms(1);
temp_min++;
if (temp_min>99)
temp_min=100;
while(k2==0);
lcdwrite(command,clear_screen);
}
if(k3==0)//减
{
delay_ms(1);
temp_min--;
if (temp_min<1)
temp_min=1;
while(k3==0); //这句是调试加入的
lcdwrite(command,clear_screen);
}
}
if(k4==0)// 退出键 //设置完初始值以后通过IIC写入24c02并清屏
{
delay_ms(1);
if((k4==0)&&(flag != 0))
{
while(k4==0);
lcdwrite(command,clear_screen);
lcdoutput_delay(0,0,"SAVE DATE...");
}
}
}
/************主函数***************/
void main()
{
ds1302init();
lcdini();
while(1)
{
key();
sprintf(Current_MAX,"+%2d",(int)temp_max);
sprintf(Current_MIN,"-%2d",(int)temp_min);
dsgettemp(&integer,&decimal,&symbol); //获取温度
if(integer
{
heater=0;
}
else if(integer>temp_max)
{
heater=1;
}
if(flag)
{
updatatemp();
}else
{
updatatime(); //关键显示部分
}
}
}
……………………
…………限于本文篇幅 余下代码请从51黑下载附件…………