整个显示分为时、分、秒三部分。时为24时置为0,分为60时置为0并向时进1,秒为60时置为0并向分进1。
程序:
#include#include void delay(unsigned char dly){ unsigned char i,j; for(i=100;i>0;i--) for(j=dly;j>0;j--);}unsigned char num,time1,time2,time3;void timer0()interrupt 1{ TH0=(65535-46080)/256; TL0=(65535-46080)% 256; num++; if(num==20) { num=0; time1++;}}void intial(){ TMOD=0x01; ET0=1; EA=1; TR0=1; num=0; time1=0; time2=0; time3=0;}void main(){ unsigned char table[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; unsigned char shi,fen; intial(); while(1) {if(time1==60) { time1=0;time2++; }if(time2==60) { time2=0; time3++; } if(time3==24) time3=0;shi=time1/10;fen=time1% 10;P2=0xf7;P0=table[shi];delay(2);P2=0xfb;P0=table[fen];delay(2);shi=time2/10;fen=time2% 10;P2=0xdf;P0=table[shi];delay(2);P2=0xef;P0=table[fen];delay(2);shi=time3/10;fen=time3% 10;P2=0x7f;P0=table[shi];delay(2);P2=0xbf;P0=table[fen];delay(2);}}