#include
#include
#define uchar unsigned char
#define uint unsigned int
sbit P2_6=P2^6; //数码管位选74HC573锁存端
sbit P2_7=P2^7; //数码段位选74HC573锁存端
oid delay(uchar xms); //声明函数delay()原型,延时函数
void display(char *ptr);
uchar code seg[]=
{0x3f,0x06,0x5b,0x4f,0x66, //段码表:0,1,2,3,4
0x6d,0x7d,0x07,0x7f,0x6f, //段码表:5,6,7,8,9 0x77,0x7c,0x39,0x5e,0x79, //段码表:A,b,C,d,E 0x71,0x00}; //段码表:F,“熄灭” void main(void)
{
long int number;
char buff[]=
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //显示缓冲数字
buff char *ptr=buff;
number=5211314;
buff[1]=number/1000000; //5211314除以1000000取整 =5
buff[2]=number%1000000/100000; //5211314除以1000000取余211314,除以100000取整=2
buff[3]=number%100000/10000; //5211314除以100000取余11314,除以10000取整=1
buff[4]=number%10000/1000; //5211314除以10000取余1314,除以1000取整=1
buff[5]=number%1000/100; //5211314除以1000取余314,除以100取整=3
buff[6]=number%100/10; //5211314除以100取余14,除以10取整=1
buff[7]=number%10; //5211314除以10取余4
while(1)
{
display(ptr);
}
}
//软件延时函数delay()
void delay(uchar xms) //延时ms子程序
{
uchar i,j,k;
for(i=xms;i>0;i–)
for(j=14;j>0;j–)
for(k=14;k>0;k–);
}
//8为LED数码管动态显示子程序 display()
void display(char *ptr)
{
int i;
for(i=0;i<8;i++)
{ P2_7=0;
P0=seg[ptr[i]];
P2_7=1;
P2_6=0;
P0=~(crol(0x01,i));
delay(500); //延时500ms
P0=0xFF; //灭屏
P2_6=1;
}
}