您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > 任意时间倒计时加警报(最后2min)
#includereg51.h#defineucharunsignedcharucharcodetable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};ucharnum,num0,benum,flag;charshi=23,fen=59,miao=59;sbitk1=P3^0;sbitk2=P3^1;sbitk3=P3^2;sbitk4=P3^3;sbitk5=P3^4;sbitk6=P3^5;sbitk7=P3^6;sbitk8=P3^7;sbitbeef=P1^5;sbitdeadline=P1^4;sbitdishurry=P1^3;sbitstop=P1^2;sbitplay=P1^1;voiddelay(ucharz){//延时子程序ucharx,y;for(x=z;x0;x--)for(y=110;y0;y--);}voiddisplay()//显示子程序{ucharsshi,sge,fshi,fge,mshi,mge;sshi=shi/10;sge=shi%10;fshi=fen/10;fge=fen%10;mshi=miao/10;mge=miao%10;P0=table[sshi];P2=0x00;delay(1);P0=0;P0=table[sge];P2=0x04;delay(1);P0=0;P0=table[10];P2=0x08;delay(1);P0=0;P0=table[fshi];P2=0x0c;delay(1);P0=0;P0=table[fge];P2=0x10;delay(1);P0=0;P0=table[10];P2=0x14;delay(1);P0=0;P0=table[mshi];P2=0x18;delay(1);P0=0;P0=table[mge];P2=0x1c;delay(1);P0=0;}voidset()//设置子程序{if(flag==1){if(k1==0){delay(5);if(k1==0){shi++;if(shi==24)shi=0;while(!k1);}}if(k2==0){delay(5);if(k2==0){fen++;if(fen==60)fen=0;while(!k2);}}if(k3==0){delay(5);if(k3==0){miao++;if(miao==60)miao=0;while(!k3);}}if(k5==0){delay(5);if(k5==0){shi--;if(shi==-1)shi=23;while(!k5);}}if(k6==0){delay(5);if(k6==0){fen--;if(fen==-1)fen=59;while(!k6);}}if(k7==0){delay(5);if(k7==0){miao--;if(miao==-1)miao=59;while(!k7);}}}if(k4==0){delay(5);if(k4==0)TR0=0;flag=1;while(!k4);}if(k8==0){delay(5);if(k8==0){TR0=1;flag=0;}while(!k8);}}voidalarm()//报警子程序{if(shi==0){if(fen==2){if(miao==0){TR1=1;benum=20;}}if(fen==1){if(miao==30)benum=10;}if(fen==1){if(miao==0)benum=5;}if(fen==0){if(miao==30)benum=2;}if(fen==0){if(miao==0){TR1=0;TR0=0;beef=0;deadline=0;dishurry=1;}}}}voidsecure()//解除{if(stop==0){delay(5);if(stop==0){TR0=0;TR1=0;beef=1;deadline=1;dishurry=0;}while(!stop);}if(play==0)//继续{delay(5);if(play==0){TR0=1;TR1=1;if(shi==0)if(fen==0)if(miao==0){TR0=0;TR1=0;}}while(!play);}}voidinit()//初始化{TMOD=0x11;TH0=(65535-50000)/256;TL0=(65535-50000)%256;TH1=(65535-50000)/256;TL1=(65535-50000)%256;EA=1;ET0=1;ET1=1;TR0=1;dishurry=0;}voidmain(){init();while(1){display();set();alarm();secure();}}voidt0_timer()interrupt1//定时器0中断{TH0=(65535-50000)/256;TL0=(65535-50000)%256;num++;if(num==20){num=0;miao--;if(miao==-1){miao=59;fen--;if(fen==-1){fen=59;shi--;if(shi==-1)shi=23;}}}}voidt1_timer()interrupt3//定时器1中断{TH1=(65535-50000)/256;TL1=(65535-50000)%256;num0++;if(num0=benum){num0=0;beef=~beef;dishurry=~dishurry;}}
本文标题:任意时间倒计时加警报(最后2min)
链接地址:https://www.777doc.com/doc-726740 .html