#includereg52.h#defineuintunsignedint#defineucharunsignedcharsbitw=P2^4;sbitq=P2^3;sbitb=P2^2;sbits=P2^1;sbitg=P2^0;//定义单片机的个、十、百、千、万位选端口sbitflog=P2^5;intn=0;intt=0;intcount=0;ucharcodetable0[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};//单片机共阴数码管段选voiddelay(intk){inti,j;for(i=0;ik;i++)for(j=0;j100;j++);}voidinit(){TMOD=0x01;//定义T0定时方式1TH0=(65536-50000)/256;TL0=(65536-50000)%256;IT0=1;EX0=1;TR0=1;ET0=1;EA=1;}voidinter0()interrupt0{count++;}voidtimer0()interrupt1{t++;if(t==20){t=0;n=count;count=0;}TH0=(65536-50000)/256;TL0=(65536-50000)%256;}voiddisplay(intn)//计数值的显示算法{intge,shi,bai,qian,wan;if(n=10000){flog=0;wan=n/10000;qian=n%10000/1000;bai=n%1000/100;shi=n%100/10;ge=n%10;}else{flog=1;wan=n/10000;qian=n%10000/1000;bai=n%1000/100;shi=n%100/10;ge=n%10;}w=q=b=s=g=1;//数码管显示方法w=0;q=b=s=g=1;P0=table0[wan];delay(4);w=q=b=s=g=1;q=0;w=b=s=g=1;P0=table0[qian];delay(4);w=q=b=s=g=1;b=0;w=q=s=g=1;P0=table0[bai];delay(4);w=q=b=s=g=1;s=0;w=q=b=g=1;P0=table0[shi];delay(4);w=q=b=s=g=1;g=0;w=q=b=s=1;P0=table0[ge];delay(4);}voidmain(){init();while(1)display(n);}