void main(){
// uchar test_i;
const uchar timp_button=0xfF; //this value is that the button havn't sticked
uchar n_delay; //delay
unsigned char j=0;
unsigned char i;
intend_initiation();
//调用时间设定程序
while(1){
if((hour==alarm_clock_hour)&&(alarm_clock_minute==minute)&&(flag_music==off)){
flag_music=on; //flag_music 是全局变量
EX0=0;
//when havn't any key ,the program will singing incessantly.
while(P1==timp_button){
if(*(Mmusic+j)==0xff) j=0;
k_m=*(Mmusic+j)&0x0f;
l_m=*(Mmusic+j)>>4;
TH0=music[2*l_m];
TL0=music[2*l_m+1];
if((music[2*l_m]==0xff)&&(music[2*l_m+1]==0xff))
TR0=0;
else
TR0=1;
// light=!light;
// delay(20000);
for(i=k_m;i>0;--i){
// light=!light;
// delay(20000);
for(n_delay=0;n_delay<2;n_delay++)
display();
}
TR0=0;
j++;
}
EX0=1;
while((P1!=timp_button)||(alarm_clock_minute==minute)) display();
flag_music=off;
}
else
display();
}
}
void check(uchar flag_opt){ //年月日检查函数 flag_opt是检查静态还是动态的数据
const uchar timp_button=0xfF; //this value is that the button havn't sticked
uchar n_delay=0; //delay
unsigned char j=0;
// unsigned char i;
if(flag_opt==0){
if(secand==0){
/*
if((hour==alarm_clock_hour)&&(alarm_clock_minute==minute)&&(flag_music==off)){
flag_music=on;
EX0=0;
//when havn't any input from buttons,the program will singing incessantly.
while(P1==timp_button){
if(*(Mmusic+j)==0xff) j=0;
k_m=*(Mmusic+j)&0x0f;
l_m=*(Mmusic+j)>>4;
TH0=music[2*l_m];
TL0=music[2*l_m+1];
if((music[2*l_m]==0xff)&&(music[2*l_m+1]==0xff))
TR0=0;
else
TR0=1;
light=!light;
delay(20000);
///////////////////////////////问题所在/////////////////////////////////////////
for(i=k_m;i>0;--i){
light=!light;
delay(20000);
for(n_delay=0;n_delay<2;n_delay++)
display();
}
///////////////////////////////////////////////////////////////////////
TR0=0;
j++;
}
EX0=1;
flag_music=off;
}
*/
}
if((minute>59)||(minute<0)){
minute=0;
++hour;
if((hour>23)||(hour<0)){
hour=0;
++day;
if((day>check_day(month))||(day<0)){
day=0;
++month;
if((month>12)||(month<0)){
month=0;
++year;
}
}
}
}
}
else {
if((min>59)||(min<0)) min=0;
if((h>23)||(h<0)) h=0;
if((d>check_day(m))||(d<0)) d=0;
if((m>12)||(m<0)) m=0;
}
}
/*
上面有两个函数,两个函数中都是有判断语句
if((hour==alarm_clock_hour)&&(alarm_clock_minute==minute)&&(flag_music==off))
;
奇怪的是,在check()函数里面就无法正常工作,而在main()中御用这段判断程序就可以正常运行。
而且,在逻辑上面来说两者都没有错,调试过,但在check()函数里面运用这句话,问题查不出来,请大神解惑*/