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

代码部分:
#include <STC15F2K60S2.H>
#include <INTRINS.H>

#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<<i);
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();       
            
}

}

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页