|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区
您需要 登录 才可以下载或查看,没有账号?立即注册
×
#include <reg52.h>
code char seg[10] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
void delay(unsigned int z)
{
while(z--);
}
void single_number()
{
char i;
P0 = seg;
P2 = ~(1 << 0);
i++;
if(i == 10){
i=0;
}
// delay(60000);
// delay(60000);
// delay(60000);
}
/*
void show_number(unsigned int n)
{
char i;
char a[4];
a[0] = n/1000;
a[1] = n%1000/100;
a[2] = n%1000%100/10;
a[3] = n%10;
for(i=0;i<4;i++)
{
P0 = seg[a];
P2 = ~(1 << i);
delay(1000);
P2 = 0xff;
}
}
*/
void show_number(unsigned int n)
{//改进版
char i,j;
char a[4];
j=0;
/*
aa: a[j] = n%10;
n = n / 10;
j++;
if(n != 0)
{
goto aa;
}
*/
do{
a[j++] = n%10;
}while(n/=10);
for(i=0;i<j;i++)
{
P0 = seg[a];
P2 = ~(1 << (3-i));//~(0x80 >> j);
delay(600);
P2 = 0xff;
}
}
void main()
{ unsigned int i,j;
while(1)
{
// single_number();
show_number(j);
// delay(60000);
i++;
if(i == 3)
{
i=0;
j++;
if(j == 9999)j=0;
}
}
} |
|