#includereg52.h//#include#includeintrins.h#defineucharunsignedchar#defineuintunsignedintsbitdula=P2^6;sbitwela=P2^7;sbitkey1=P3^4;sbitkey2=P3^5;sbitkey3=P3^6;sbitbeep=P2^3;unsignedcodetable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};ucharnum1,num2,s,s1,m,m1,f,f1,num,numf,nums,dingshi;ucharns,ns1,nf,nf1,numns,numnf;voiddelay(uintz);voidkeyscan();voidkeyscan1();voidalram();voiddisplay(ucharm,ucharm1,ucharf,ucharf1,uchars,uchars1);voiddisplay0(ucharnf,ucharnf1,ucharns,ucharns1);voidmain(){TMOD=0x01;//设定定时器0工作方式1TH0=(65536-46080)/256;TL0=(65536-46080)%256;EA=1;//开总中断ET0=1;//开定时器0中断TR0=1;//启动定时器0中断numns=12;numnf=0;while(1){if(dingshi==0){keyscan();display(m,m1,f,f1,s,s1);alram();}else{keyscan1();display0(nf,nf1,ns,ns1);}}}voidkeyscan(){if(key1==0){delay(10);if(key1==0)nums++;if(nums==24)nums=0;while(!key1);display(m,m1,f,f1,s,s1);}if(key2==0){delay(10);if(key2==0)numf++;if(numf==60)numf=0;while(!key2);display(m,m1,f,f1,s,s1);}if(key3==0){delay(10);if(key3==0){dingshi=~dingshi;while(!key3)display(m,m1,f,f1,s,s1);}}/*if(key4==0){delay(10);if(key4==0){flag=1;while(!key4);display(m,m1,f,f1,s,s1);}}*/}voidkeyscan1(){if(key1==0){delay(10);if(key1==0)numns++;if(numns==24)numns=0;while(!key1);//display(nf,nf1,ns,ns1);}if(key2==0){delay(10);if(key2==0)numnf++;if(numnf==60)numnf=0;while(!key2);//display(nf,nf1,ns,ns1);}if(key3==0){delay(10);if(key3==0){dingshi=0;while(!key3);//display(m,m1,f,f1,s,s1);}}}voidalram(){if((numnf==numf)&&(numns==nums))beep=0;if(((numnf+1==numf)&&(numns==nums))&&(dingshi==0))//一分钟报时提示beep=1;}voiddisplay0(ucharnf,ucharnf1,ucharns,ucharns1)//闹钟显示函数{nf=numnf%10;nf1=numnf/10;ns=numns%10;ns1=numns/10;/*wela=1;P0=0xc0;//送位选数据wela=0;P0=0xff;*/dula=1;P0=table[ns1];dula=0;P0=0xff;wela=1;P0=0xfe;wela=0;delay(1);dula=1;P0=table[ns]|0x80;dula=0;P0=0xff;wela=1;P0=0xfd;wela=0;delay(1);dula=1;P0=table[nf1];dula=0;P0=0xff;wela=1;P0=0xfb;wela=0;delay(1);dula=1;P0=table[nf];dula=0;P0=0xff;wela=1;P0=0xf7;wela=0;delay(1);}voiddisplay(ucharm,ucharm1,ucharf,ucharf1,uchars,uchars1)//时间显示{dula=1;P0=table[m1];//秒位第1位dula=0;P0=0xff;wela=1;P0=0xef;wela=0;delay(1);dula=1;P0=table[m];//秒位第2位dula=0;P0=0xff;wela=1;P0=0xdf;wela=0;delay(1);dula=1;P0=table[s1];//时位第一位dula=0;P0=0xff;wela=1;P0=0xfe;wela=0;delay(1);dula=1;P0=table[s]|0x80;dula=0;P0=0xff;wela=1;P0=0xfd;wela=0;delay(1);dula=1;P0=table[f1];//分位第一位dula=0;P0=0xff;wela=1;P0=0xfb;wela=0;delay(1);dula=1;P0=table[f]|0x80;dula=0;P0=0xff;wela=1;P0=0xf7;wela=0;delay(1);}voidT0_timer()interrupt1{TH0=(65536-46080)/256;TL0=(65536-46080)%256;num2++;if(num2==20){num++;num2=0;m=num%10;m1=num/10;f=numf%10;f1=numf/10;s=nums%10;s1=nums/10;if(num==59){num=0;numf++;if(numf==59){numf=0;nums++;}if(nums==24)nums=0;}}}voiddelay(uintz){uintx,y;for(x=110;x0;x--)for(y=z;y0;y--);}