微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 8位数码管动态显示时间,可调节,调节的数闪烁显示

8位数码管动态显示时间,可调节,调节的数闪烁显示

时间:11-18 来源:互联网 点击:
//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;xfor(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;
}
}

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

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top