#include<reg52.h> #include<reg52.h>
sbit dula=P2^6;
sbit wela=P2^7;
unsigned char code wei[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
unsigned char code duan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x80};
unsigned int s, f, m,
ss, sg,
fs, fg,
ms, mg,
n, x;
void delayms(unsigned int xms)
{
unsigned int i, j;
for(i=0;i<xms;i++)
for(j=0;j<110;j++);
}
void SMG(int i, int j)
{
dula=1;
P0=duan[i];
dula=0;
P0=0xff;
wela=1;
P0=wei[j];
wela=0;
delayms(1);
}
void T0_time() interrupt 1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
n++;
}
void main()
{
TMOD=0x01;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
if(n==20){n=0;m++;}
if(m==60){m=0;f++;}
if(f==60){f=0;s++;}
if(s==24){s=0;}
ms=m/10;
mg=m%10;
fs=f/10;
fg=f%10;
ss=s/10;
sg=s%10;
for(x=0;x<2;x++)
{
SMG(10,1);
SMG(10,3);
SMG(ss,0);
SMG(sg,1);
SMG(fs,2);
SMG(fg,3);
SMG(ms,4);
SMG(mg,5);
}
}
}
程序中用到 數碼管 和 中斷 數碼管 dula wela IO口自行修改 |