您的位置 首页 新品

8位数码管动态显现时刻,可调理,调理的数闪耀显现

//8位数码管动态显示时间,可调节,//调节时间时,调节的数闪烁显示;//比较两种闪烁的方法;#includereg51.h>#defineuintunsignedi…

//8位数码管动态显现时刻,可调理,

//调理时刻时,调理的数闪耀显现;
//比较两种闪耀的办法;

#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;
}
}

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

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/xinpin/266122.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部