//有一路报警输出,可设置报警时间
//实间时间请调整TH1,TL1值使更准确
//designed by ljc,gdwm ceramic com,.ltd
#include
#define uchar unsigned char
#define uint unsigned int
#define segment P0 //数码管显示
#define wei P2 //数码管位控制
uchar hour,min,sec; //定义小时,分
uchar ms; //当前毫秒
uchar alARM_h1,alarm_m1;//报警设置,hour,minute;
uchar alarm_h2,alarm_m2;
***it flash=P1^0; //秒闪烁标志
***it seth=P3^0; //小时设置
***it setm=P3^1; //分设置
***it seta1h=P3^2; //alarm1 set
***it seta1m=P3^3; //alarm1 set
***it alarm_out=P1^7; //设定时间到,报警输出
bit hour_min_sign; //时,分设置标志
bit pop_key; //键弹起标志
uchar code design[10]={0x28, 0x7E, 0xA2, 0x62, 0x74, 0x61, 0x21, 0x7A, 0x20, 0x60};//0,1,2,3,4,5,6,7,8,9
//*************************************************
//**********
void delay(uint i)
{ uint j;
for(;i>0;i--)
for(j=0;j<120;j++)
{;}
}
//*************************************************
//**********
void initial()
{ TMOD=0x01;
TH0=0X3C; //50ms定时
TL0=0xc0;
EA=1;
ET0=1;
TR0=1;
//报警时间初使化
alarm_h1=7;
alarm_m1=0;
alarm_h2=14;
alarm_m2=0;
}
//*************************************************
//**********
void time0_int() interrupt 1
{ TH0=0x3c;
TL0=0xc0;
if(ms<20)
{ ms++;}
else
{ ms=0;
sec++;
if(sec>59)
{ sec=0;
min++;
if(min>59)
{ min=0;
hour++;
if(hour>=24)
{ hour=0;}
}
}
}
if(ms>10){flash=1;}
else{flash=0;}
}
//************************************************
//*********
void display(uchar h,m,ah1,am1)
{ uchar hh,hl,mh,ml,hh1,hh2,mm1,mm2;
hh=h/10;
hl=h%10;
mh=m/10;
ml=m%10;
hh1=ah1/10;hh2=ah1%10;mm1=am1/10;mm2=am1%10; //报警时间显示
//
segment=design[hh];
wei=0xef;
delay(2);
//
segment=design[hl];
wei=0xdf;
delay(2);
//
segment=design[mh];
wei=0xbf;
delay(2);
//
segment=design[ml];
wei=0x7f;
delay(2);
//报警显示
segment=design[hh1];
wei=0xfe;
delay(5);
segment=design[hh2];
wei=0xfd;
delay(2);
segment=design[mm1];
wei=0xfb;
delay(2);
segment=design[mm2];
wei=0xf7;
delay(2);
}
//************************************************
//键防拌处理**********
void scan_key(bit set_h_m)
{ if(!set_h_m)
{ delay(30);
if(!set_h_m)
{ delay(10);
hour_min_sign=1;
}
else{hour_min_sign=0;}
}
while(set_h_m&hour_min_sign)//等街键弹起
{ delay(30);
if(set_h_m&hour_min_sign)
{ delay(10);
pop_key=1;
} //键弹起标志
hour_min_sign=0;
}
}
//时间设置****************************************
//**********
void time_set()
{ pop_key=0;
scan_key(seth);
if(pop_key) //小时键按下,小时加1
{
if(hour>23)
{ hour=0;}
else{hour++;}
display(hour,min,alarm_h1,alarm_m1);
}
pop_key=0;
//
scan_key(setm); //分键按下,分加1
if(pop_key)
{
if(min>59)
{ min=0;}
else{min++;}
display(hour,min,alarm_h1,alarm_m1);
}
pop_key=0;
}
//***********************************************
//报警时间设置:小时,分钟*
//有报警时间设置功能,延时关闭功能
void alarm()
{
//报警1
pop_key=0;
scan_key(seta1h); //报警1设置
if(pop_key)
{ alarm_h1++;
if(alarm_h1>23)
{ alarm_h1=0;}
}
pop_key=0;
display(hour,min,alarm_h1,alarm_m1);
scan_key(seta1m);
if(pop_key)
{ alarm_m1++;
if(alarm_m1>59)
{ alarm_m1=0;}
}
display(hour,min,alarm_h1,alarm_m1);
if((hour==alarm_h1)&(min==alarm_m1))//相等
{ alarm_out=0;} //报警输出
}
//***********************************************
//*************************
void main()
{ initial();
for(;;)
{ time_set(); //时间设置
display(hour,min,alarm_h1,alarm_m1);
alarm();
}
}
|