两位数码管动态显示C语言程序+电路图
2020-09-05 17:11:12
用c语言编写的 51单片机数码管驱动程序 下面是电路图:
#include
#define uint unsigned int
void delay7ms(void) //误差 -0.217013888891us
{
unsigned char a,b;
for(b=208;b>0;b--)
for(a=14;a>0;a--);
}
void delay2ms(void) //误差 -0.217013888889us
{
unsigned char a,b;
for(b=80;b>0;b--)
for(a=10;a>0;a--);
}
#define uint unsigned int
void delay7ms(void) //误差 -0.217013888891us
{
unsigned char a,b;
for(b=208;b>0;b--)
for(a=14;a>0;a--);
}
void delay2ms(void) //误差 -0.217013888889us
{
unsigned char a,b;
for(b=80;b>0;b--)
for(a=10;a>0;a--);
}
void main(void)
{
uint led[10]={0xc0,0xf9,0xa4, 0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uint m,n=0,a=0;
for(m=0;m<=10;m++)
{
while(a<30)
{
if(m==10)
{
m=0;
n++ ;
if(n==10)
n=0;
}
{
uint led[10]={0xc0,0xf9,0xa4, 0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uint m,n=0,a=0;
for(m=0;m<=10;m++)
{
while(a<30)
{
if(m==10)
{
m=0;
n++ ;
if(n==10)
n=0;
}
P0=led[m];
P2=0x40;
delay7ms();
P2=0x00;
delay2ms();
P0=led[n];
P2=0x80;
delay7ms();
P2=0x00;
delay2ms();
a++;
}
a=0;
P2=0x40;
delay7ms();
P2=0x00;
delay2ms();
P0=led[n];
P2=0x80;
delay7ms();
P2=0x00;
delay2ms();
a++;
}
a=0;
}
}
}