选用stc89c52单片机芯片,四位数码管的接法:P1位选 P0段选
程序:
#include
void delay(unsigned int d);
char t;
unsigned char code duan[] = {0x3f,0x06,
0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};
unsigned char code wei[8]={0xfe,0xfd,0xfb
,0xf7,0xef,0xdF,0xbF,0x7F};
main()
{
unsigned int f=1 ,n=0;
unsigned char i,out[8];
t=0;
while(1)
{
if(++t>=1)
{
t=0;
++f;
if(f==10000)
{f=0;
n++;
}
if(n==10000)
{
n=0;
}
}
out[4]=duan[f%10000/1000];//千位
out[5]=duan[f%1000/100];//百位
out[6]=duan[f%100/10]; //十位
out[7]=duan[f%10]; //个位
out[0]=duan[n%10000/1000];//千万
out[1]=duan[n%1000/100];//百万
out[2]=duan[n%100/10]; //十万
out[3]=duan[n%10]; //万
for( i=0; i<8; i++)
{P1=wei[1];
P0 = out[i];
P1 = wei[i];
delay(10);
}
}
}