|
#include<reg52.h> //8位共阴数码管动态扫描显示计数数字00000000-99999999;没完成的
#define uchar unsigned char
#define uint unsigned int
unsigned char count;
unsigned char i; //定义一个无符号的整数型单字节变量 (取值0-255)
unsigned long j; //定义一个无符号的整数型三字节变量32位(取值0-4294967295)
sbit du=P2^2;
sbit we=P2^3;
void init();
void display();
void delay(uint z) //带参数调整的延时函数,调整变量z,可改变延时时间
{
uint x,y;
for(x=z;x>0;x--)
for(y=0;y>0;y--); //约0.001ms
}
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//0-F共 阴 段码表
unsigned char code weima[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//开位码表
unsigned char temp[8];
void main()
{
count=0;
while(1)
{
/**********************定时器0初始化程序************************/
TMOD=0X01;//使用模式1,16位定时器0;
TH0=(65535-50000)/256;//装初值
TL0=(65535-50000)%256;
EA=1;//开总中断
ET0=1;//开定时器0中断
TR0=1;//启动定时器0
TH0=(65535-50000)/256;//重装初值
TL0=(65535-50000)%256;
count++;
if(count==20)
{
j++;
count=0;
display();
}
/***************************重装初值************************************/
}
}
void display()
{
for(i=0;i<8;i++)
{
temp[0]=table[j/10000000]; //分离千万位数
temp[1]=table[(j/1000000)%10];//分离百万位数
temp[2]=table[(j/100000)%10]; //分离十万位数
temp[3]=table[(j/10000)%10]; //分离万位数
temp[4]=table[(j/1000)%10];//分离千位数
temp[5]=table[(j/100)%10];//分离百位数
temp[6]=table[(j/10)%10];//分离十位数
temp[7]=table[j%10];////分离个位数
P0=weima[i];//"11111110" 送位码,第一位显示 0
we=1; //开位锁存使能端
we=0; //关位锁存使能端
P0=temp[i];//送段码“0”
du=1; //开段锁存使能端
du=0;//关段锁存使能端
delay(0); //延时10ms
}
}
|
评分
-
查看全部评分
|