C51单片机数码管显示数字实现

代码部分:
#include
#include

#define Y(n) P2=P2&0x1F|(n<<5)
unsigned char digit[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
unsigned char num[8];
void buzz_off()
{
P0=P0&~(1<<6);
Y(5);
Y(0);
}
void Delay2ms() //@12.000MHz
{
unsigned char i, j;

i = 24;
j = 85;
do
{
	while (--j);
} while (--i);

}

void digit2num(unsigned long n)
{
char i;
for(i=7;i>=0;i–)
{
num[i]=n%10;
n/=10;

}

}

void display()
{
static char i=0;
P0=(1< Y(6);
Y(0);

P0=digit[num[i]];
Y(7);
Y(0);

if(++i==8)
    i=0;

}
int main()
{

unsigned long n=12345678UL; 
buzz_off();    
    
while(1)
{         
    
    digit2num(n--);
    display();
    Delay2ms();       
            
}

}

你可能感兴趣的:(c51单片机)