51單片機(jī)控制8位LED數(shù)碼管做9999累加的程序
程序:
#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]; //個(gè)位
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);
}
}
}
評論