|
#include<reg52.h> //8位共陰數(shù)碼管動態(tài)掃描顯示計數(shù)數(shù)字00000000-99999999;沒完成的
#define uchar unsigned char
#define uint unsigned int
unsigned char count;
unsigned char i; //定義一個無符號的整數(shù)型單字節(jié)變量 (取值0-255)
unsigned long j; //定義一個無符號的整數(shù)型三字節(jié)變量32位(取值0-4294967295)
sbit du=P2^2;
sbit we=P2^3;
void init();
void display();
void delay(uint z) //帶參數(shù)調整的延時函數(shù),調整變量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]; //分離千萬位數(shù)
temp[1]=table[(j/1000000)%10];//分離百萬位數(shù)
temp[2]=table[(j/100000)%10]; //分離十萬位數(shù)
temp[3]=table[(j/10000)%10]; //分離萬位數(shù)
temp[4]=table[(j/1000)%10];//分離千位數(shù)
temp[5]=table[(j/100)%10];//分離百位數(shù)
temp[6]=table[(j/10)%10];//分離十位數(shù)
temp[7]=table[j%10];////分離個位數(shù)
P0=weima[i];//"11111110" 送位碼,第一位顯示 0
we=1; //開位鎖存使能端
we=0; //關位鎖存使能端
P0=temp[i];//送段碼“0”
du=1; //開段鎖存使能端
du=0;//關段鎖存使能端
delay(0); //延時10ms
}
}
|
評分
-
查看全部評分
|