新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 8位數(shù)碼管動態(tài)顯示時(shí)間,可調(diào)節(jié),調(diào)節(jié)的數(shù)閃爍顯示

8位數(shù)碼管動態(tài)顯示時(shí)間,可調(diào)節(jié),調(diào)節(jié)的數(shù)閃爍顯示

作者: 時(shí)間:2016-11-18 來源:網(wǎng)絡(luò) 收藏
//8位數(shù)碼管動態(tài)顯示時(shí)間,可調(diào)節(jié),

//調(diào)節(jié)時(shí)間時(shí),調(diào)節(jié)的數(shù)閃爍顯示;
//比較兩種閃爍的方法;

本文引用地址:http://butianyuan.cn/article/201611/315589.htm


#include
#define uint unsigned int
#define uchar unsigned char
sbit tiaojie=P1^0;
sbit jia=P1^1;
sbit jian=P1^2;
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90,0xbf};
uchar a,b,num1,num2,flag100ms,flag1s,flagtj;
uchar miao,fen,shi,flagjia,flagjian;
bit flag_1s;
uchar code wela[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchar dula[8]={0,0,1,1,2,2,3,3};
void delay(uint z);
void intc();
void keyscan();
void disp();
void main()
{intc();

while(1)
{

keyscan();
disp();

}
}

//================
void intc()
{
TMOD=0x01;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
ET0=1;
EA=1;
TR0=1;
}

void timer0() interrupt 1
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
a++;
if(a==10)
{flag100ms=1;}
if(a==100)
{a=0,flag1s=1,miao++;flag_1s=~flag_1s;}
if(miao==60)
{miao=0,fen++;}
if(fen==60)
{fen=0,shi++;
if(shi>12)
shi=1;}


}
//====================
void disp()
{uchar i,n;
dula[7]=miao%10;
dula[6]=miao/10;
dula[5]=0x0a;
dula[4]=fen%10;
dula[3]=fen/10;
dula[2]=0x0a;
dula[1]=shi%10;
dula[0]=shi/10;

for(i=0;i<8;i++)
{
switch(flagtj)
{
case 1 : n=6;
break;
case 2 : n=3;
break;
case 3 : n=0;
break;
default:break;

}
if(flagtj!=0)
if((n==i)||(n+1==i))
{if(flag_1s==1)
P0=0xff;
else
P0=table[dula[i]];}
else
P0=table[dula[i]];
if(flagtj==0)
P0=table[dula[i]];

P2=wela[i];
delay(5);
P0=0xff;
}

/*第二種顯示的方法。相對來說比較代碼長些
for(i=0;i<8;i++)
{

switch(flagtj)
{
case 1:
if(i>5&&i<8)
{if(flag_1s==1)
P0=0xff;
else
P0=table[dula[i]];}
else
P0=table[dula[i]];break;
case 2:
if(i>2&&i<5)
{if(flag_1s==1)
P0=0xff;
else
P0=table[dula[i]];}
else
P0=table[dula[i]];break;
case 3:
if(i>=0&&i<2)
{if(flag_1s==1)
P0=0xff;
else
P0=table[dula[i]];}
else
P0=table[dula[i]];break;
case 0:
P0=table[dula[i]];break;
}
P2=wela[i];
delay(10);
P0=0xff;
}


*/

}
//=====================
void delay(uint z)
{
uint x;
uchar y;
for(x=0;x for(y=0;y<112;y++);
}

//===========================
void keyscan()
{
if(tiaojie==0)
delay(100);
if(tiaojie==0)
{while(!tiaojie);
flagtj++;
if(flagtj>3)
flagtj=0;
}
if(jia==0)
delay(100);
if(jia==0)
{while(!jia);
flagjia=1;
}
if(jian==0)
delay(100);
if(jian==0)
{while(!jian);
flagjian=1;
}
if(flagtj!=0)
switch(flagtj)
{ case 1: if(flagjia==1)
{flagjia=0;miao++;
if(miao>60)
miao=0;
}

if(flagjian==1)
{flagjian=0;
if(miao<1)
miao=1;
miao--;
}
break;
case 2: if(flagjia==1)
{flagjia=0;fen++;
if(fen>60)
fen=0;
}

if(flagjian==1)
{flagjian=0;
if(fen<1)
fen=1;
fen--;
}
break;
case 3: if(flagjia==1)
{flagjia=0;shi++;
if(shi>12)
shi=1;
}

if(flagjian==1)
{flagjian=0;
if(shi<1)
shi=1;
shi--;
}
break;
}
}

//===============



評論


技術(shù)專區(qū)

關(guān)閉