/*数码管动态显示*/
#include<reg52.h>
#define DataPort P0
sbit LATCH1=P2^2;/*段锁存*/
sbit LATCH2=P2^3;/*位锁存*/
unsigned char code dofly_DuanMa[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char code dofly_WeiMa[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char tempdata[8];
void delay(unsigned int t);
void Display(unsigned char FirstBit,unsigned char Num);
main()
{
while(1)
{
unsigned int numA=999;
unsigned int j;
j++;
if(j==10)
{
j=0;
if(numA>0)
numA--;
else
numA=999;
}
if(numA<100)
tempdata[0]=0;
else
tempdata[0]=dofly_DuanMa[numA/100];
if(numA<10)
tempdata[1]=0;
else
tempdata[1]=dofly_DuanMa[(numA%100)/10];
tempdata[2]=dofly_DuanMa[(numA%100)%10];
Display(0,3);
}
}
void delay(unsigned int t)
{
while(--t);
}
void deplay(unsigned char FirstBit,unsigned char Num)
{
unsigned char i;
for(i=0;i<Num;i++)
{
DataPort=0;
LATCH1=1;
LATCH1=0;
DataPort=dofly_WeiMa[i+FirstBit];
LATCH2=1;
LATCH2=0;
DataPort=tempdata[i];
LATCH1=1;
LATCH2=0;
delay(200);
}
} |