|
樓主,你的程序簡直是一堆亂碼.在這里誤人子弟,強烈譴責,再不要拿這樣的東西請教別人.做好的東西也不拿出來讓人學習,太自私了.你不公布,我公布;代碼如下:
#include "reg52.h" //此文件中定義了單片機的一些特殊功能寄存器
typedef unsigned int u16; //對數(shù)據(jù)類型進行聲明定義
typedef unsigned char u8;
sbit LSD=P2^0;
sbit LSC=P2^1;
sbit LSB=P2^2;
sbit LSA=P2^3;
//u8 code smgduan[11]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x80};//顯示0~9和橫杠的值//10000000橫杠,0x80?
u8 code smgduan[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x40,0xff};//最后兩位是橫和關(guān)鍛
void delay(u16 i)
{
while(i--);
}
void delayms(u16 x) //改三處 //延時函數(shù)
{
u8 i;
while(x--)
{
for(i=50;i>0;i--); //改一處;
}
}
void Timer0Init()//定時一秒,完成后進行中斷
{
TMOD|=0X01;//0000 0001方式一
TH0=0X15; //給定時器賦初值,定時1s
TL0=0XA0;
ET0=1;//打開定時器0中斷允許
EA=1;//打開總中斷
TR0=1;//打開定時器
}
u8 a=0,b=11,c=11,d=11,e=11,f=0;
u16 l=0;
u16 i;
void display()
{
P0=smgduan[a];
LSA=1;delayms(3);LSA=0; delayms(0); //第一位數(shù)碼關(guān)斷時間
P0=smgduan[b];
LSB=1;delayms(3);LSB=0;delayms(0); //第二位數(shù)碼關(guān)斷時間
P0=smgduan[c];
LSC=1;delayms(3);LSC=0; delayms(0); //第一位數(shù)碼關(guān)斷時間
P0=smgduan[d];
LSD=1;delayms(3);LSD=0;delayms(0); //第二位數(shù)碼關(guān)斷時間
P0=smgduan[e];
LSE=1;delayms(3);LSE=0; delayms(0); //第一位數(shù)碼關(guān)斷時間
if(f!=0)
{
P0=0x7f;
LSC=1;delayms(3);LSC=0; delayms(0);//小數(shù)點;
}
delayms(3);
}
void main()
{
Timer0Init(); //定時器0初始化
while (1)display();
}
void Timer0() interrupt 1//interrupt后面無括號
{//
TH0=0X15;
TL0=0XA0;
i++;
if(i<10)
{//
a=i;
display();
}//
if(i>=10&&i<60)
{//
a=i%10;
b=i/10;
display();
}//
if(i>=60&&i<600)
{//
f=1;
c=i/60;
b=(i-60*c)/10;
a=i-60*c-10*b;
display();
}//
if(i>=600&&i<3600)
{//
f=1;
d=i/600;
c=(i-600*d)/60;
b=(i-600*d-60*c)/10;
a=i-600*d-60*c-10*b;
display();
}//
if(i>=3600&&i<39600)
{//
if(i>=36000)
{//
f=1;
l=36000;
} //
e=(i-l)/3600;
d=(i-l-3600*e)/600;
c=(i-l-3600*e-600*d)/60;
b=(i-l-3600*e-600*d-60*c)/10;
a=i-l-3600*e-600*d-60*c-10*b;
display();
}//點亮小時,十二小時制。
if(i==39600)
{i=0;display();}
}//
|
|