#include#define uchar unsigned char uchar code shuzi[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xc0};//0 1 2 3 4 5 6 7 8 9 0 uchar code shuza[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0xc0};//0 1 2 3 4 5 0 uchar ss,dd,ff,gg,zz; uchar qq,ww,ee,rr,tt; uchar z,x,qw,qe,qr,as,fe; sbit a=P2^0;//锁存器1 sbit b=P2^1;//锁存器2 sbit c=P2^2;//锁存器3 sbit d=P2^3;//锁存器4 sbit e=P2^4;//秒灯 sbit f=P2^5;//时间指示灯 sbit g=P2^6;//设置指示灯 sbit h=P2^7;//.... sbit i=P1^0;//时间设置按键 sbit j=P1^1;//返回 sbit k=P1^2;//加 sbit l=P1^3;//减 sbit m=P1^4;//定时设置 sbit y=P1^5;//启动定时 void ys(); void main() { EA=1; //打开总中断 TH0=(65535-50000)/256; //定时器复初值 TL0=(65535-50000)%256; ET0=1; // TR0=1; //启动定时器 P0=0xc0; P2=0xff; P2=0xd0; while(1) {f=0;g=1; if(i==0)//设置时间 判断 {g=0;f=1; while(1) {if(j==0){break;} if(i==0){ys();if(i==0){while(i==0){if(i==1){x++;break;}}}} if(x==5){x=1;}if(x==0){x=1;} if(x==1) {if(k==0){ys();if(k==0){ss++;if(k==0)if(ss==10){ss=0;}}} if(l==0){ys();if(l==0){if(ss==0){ss=10;}ss--;}} a=1;P0=0x7f;P0=shuzi[ss];a=0; } if(x==2) {if(k==0){ys();if(k==0){dd++;if(k==0)if(dd==6){dd=0;}}} if(l==0){ys();if(l==0){if(dd==0){dd=6;}dd--;}} b=1;P0=0x7f;P0=shuza[dd];b=0; } if(x==3) {if(k==0){ys();if(k==0){ff++;if(k==0)if(ff==10){ff=0;}}} if(l==0){ys();if(l==0){if(ff==0){ff=10;}ff--;}} c=1;P0=0x7f;P0=shuzi[ff];c=0; } if(x==4) {if(k==0){ys();if(k==0){gg++;if(k==0)if(gg==3){gg=0;}}} if(l==0){ys();if(l==0){if(gg==0){gg=3;}gg--;}} d=1;P0=0x7f;P0=shuzi[gg];d=0; } } } //设置时间完 if(m==0)//定时 判断 {g=0;f=0;as=1; while(1) {if(j==0){as=0;break;} if(m==0){ys();if(m==0){while(m==0){if(m==1){x++;break;}}}} if(x==5){x=1;}if(x==0){x=1;} if(x==1) {if(k==0){ys();if(k==0){qq++;if(k==0)if(qq==10){qq=0;}}} if(l==0){ys();if(l==0){if(qq==0){qq=10;}qq--;}}a=1;P0=0x7f;P0=shuzi[qq];a=0; } if(x==2) {if(k==0){ys();if(k==0){ww++;if(k==0)if(ww==6){ww=0;}}} if(l==0){ys();if(l==0){if(ww==0){ww=6;}ww--;}} b=1;P0=0x7f;P0=shuza[ww];b=0; } if(x==3) {if(k==0){ys();if(k==0){ee++;if(k==0)if(ee==10){ee=0;}}} if(l==0){ys();if(l==0){if(ee==0){ee=10;}ee--;}}c=1;P0=0x7f;P0=shuzi[ee];c=0; } if(x==4) {if(k==0){ys();if(k==0){rr++;if(k==0)if(rr==3){rr=0;}}} if(l==0){ys();if(l==0){if(rr==0){rr=3;}rr--;}}d=1;P0=0x7f;P0=shuzi[rr];d=0;} } } //定时时间完 if(y==0)//启动定时功能 {while(1){if(y==1){h=!h;if(h==0){fe=1;}if(h==1){fe=0;}break;}}} if(fe==1) {if(gg==rr){if(ff==ee){if(dd==ww){if(ss==qq){ g=0;f=0;;ys();g=1;f=1;ys(); }}}}} } } void zhongduan() interrupt 1 //中断函 { TH0=(65535-50000)/256; //定时器复初值 TL0=(65535-50000)%256; z++; if(z==80) {z=0; e=!e; zz++; if(zz==120){zz=0;ss++;} if(ss==10){ss=0;dd++;} if(dd==6){dd=0;ff++;} if(ff==10){ff=0;gg++;} if(gg==2) {if(ff>=4){ff=0;gg=0;}} if(gg>=3) {gg=0;} if(rr==2) {if(ee>=4){ee=0;rr=0;}} if(rr>=3) {rr=0;} if(as==0) {P0=shuzi[ss];a=1;a=0; P0=shuza[dd];b=1;b=0; P0=shuzi[ff];c=1;c=0; P0=shuzi[gg];d=1;d=0; } if(as==1) { a=1;P0=shuzi[qq];a=0; b=1;P0=shuza[ww];b=0; c=1;P0=shuzi[ee];c=0; d=1;P0=shuzi[rr];d=0; } } } void ys() {for(qw=255;qw>0;qw--) for(qe=255;qe>0;qe--); for(qw=255;qw>0;qw--) for(qe=50;qe>0;qe--); }
上一篇:单片机控制电磁阀的程序
下一篇:带存储功能的学习型红外遥控器源代码
推荐阅读最新更新时间:2024-03-16 13:07
- 热门资源推荐
- 热门放大器推荐