用6位数码管显示时间
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
wela=1;
P0=0xfd;
wela=0;
delay(20);
}
void main()//主函数
{
init();
while(1)
{
display(num);
display1(num2);
display2(num3);
//jianpan();
keyscan();
fm=1;
if(num3==11)
{
if(num2==11)
{
if(key4==0)
{
delay(4);
if(key4==0)
TR0=~TR0;
}
}
}
}*/
void t0() interrupt 1 //定时器1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
num1++;
if(num1==20)
{
num1=0;
num++;
{
if(num==11)
TR0=0;
delay(10000);
TR0=1;
}
}
}
}
void init()//初始化函数
{
TMOD=0x01;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
ET0=1;
P3=0xff;
num=0;
num1=0;
num2=0;
if(num==0)
num=60;
}
}
while(!key2);
delay(5);
while(!key2);
if(key3==0)
{
delay(5);
if(key3==0)
num=0;
}
while(!key3);
delay(5);
while(!key3);
if(key4==0)
{
delay(5);
if(key4==0)
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
delay(20);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
wela=0;
delay(20);
}
void display2(uchar numd2)//小时显示函数
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{temp=P3;
TR0=~TR0;
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
}
break;
case 0xbe:num3++;
if(num3==24)
num3=0;
break;
case 0x7e:num3--;
if(num3==0)
num3=24;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xfd;
temp=P3;
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{temp=P3;
switch(temp)
{
case 0xee:num2++;
if(num2==60)
num2=0;
break;
case 0xde:num2--;
ifHale Waihona Puke Baidunum2==0)
num2=60;
{
uchar xshi,xfen;
xshi=numd2/10;
xfen=numd2%10;
dula=1;
P0=table[xshi];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(20);
dula=1;
P0=table1[xfen];
dula=0;
P0=0xff;
delay(20);
dula=1;
P0=table1[miao];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(20);
}
void display(uchar numdis)//分钟显示函数
{
uchar shi,ge;
shi=numdis/10;
ge=numdis%10;
if(num==60)
{
num=0;
num2++;
if(num2==60)
{
num2=0;
fm=0;
delay(1);
num3++ ;
if(num3==24)
{
num3=0;
}
}
}
}
}
void keyscan()//键盘扫描
{
P3=0xfe;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,
};
unsigned char code table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,
}
/*void jianpan()
{
if(key1==0)
{
delay(5);
if(key1==0)
{
num++;
if(num==60)
num=0;
}
}
while(!key1);
delay(5);
while(!key1);
if(key2==0)
{
delay(5);
if(key2==0)
{
num--;
0x87,0xff,0xef};
void display1(uchar numdi) //秒钟显示函数
{
uchar fen,miao;
fen=numdi/10;
miao=numdi%10;
dula=1;
P0=table[fen];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
sbit fm=P2^3;
uchar num,num1,num2,num3,temp;
void init();
void keyscan();
//void jianpan();
void delay(uint a)
{
uint x,z;
for(x=a;x>0;x--)
for(z=10;z>0;z--);
}
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
sbit key1=P3^4;
sbit key2=P3^5;
sbit key3=P3^6;
sbit key4=P3^7;
P0=0xfd;
wela=0;
delay(20);
}
void main()//主函数
{
init();
while(1)
{
display(num);
display1(num2);
display2(num3);
//jianpan();
keyscan();
fm=1;
if(num3==11)
{
if(num2==11)
{
if(key4==0)
{
delay(4);
if(key4==0)
TR0=~TR0;
}
}
}
}*/
void t0() interrupt 1 //定时器1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
num1++;
if(num1==20)
{
num1=0;
num++;
{
if(num==11)
TR0=0;
delay(10000);
TR0=1;
}
}
}
}
void init()//初始化函数
{
TMOD=0x01;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
ET0=1;
P3=0xff;
num=0;
num1=0;
num2=0;
if(num==0)
num=60;
}
}
while(!key2);
delay(5);
while(!key2);
if(key3==0)
{
delay(5);
if(key3==0)
num=0;
}
while(!key3);
delay(5);
while(!key3);
if(key4==0)
{
delay(5);
if(key4==0)
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
delay(20);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
wela=0;
delay(20);
}
void display2(uchar numd2)//小时显示函数
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{temp=P3;
TR0=~TR0;
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
}
break;
case 0xbe:num3++;
if(num3==24)
num3=0;
break;
case 0x7e:num3--;
if(num3==0)
num3=24;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xfd;
temp=P3;
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{temp=P3;
switch(temp)
{
case 0xee:num2++;
if(num2==60)
num2=0;
break;
case 0xde:num2--;
ifHale Waihona Puke Baidunum2==0)
num2=60;
{
uchar xshi,xfen;
xshi=numd2/10;
xfen=numd2%10;
dula=1;
P0=table[xshi];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(20);
dula=1;
P0=table1[xfen];
dula=0;
P0=0xff;
delay(20);
dula=1;
P0=table1[miao];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(20);
}
void display(uchar numdis)//分钟显示函数
{
uchar shi,ge;
shi=numdis/10;
ge=numdis%10;
if(num==60)
{
num=0;
num2++;
if(num2==60)
{
num2=0;
fm=0;
delay(1);
num3++ ;
if(num3==24)
{
num3=0;
}
}
}
}
}
void keyscan()//键盘扫描
{
P3=0xfe;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,
};
unsigned char code table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,
}
/*void jianpan()
{
if(key1==0)
{
delay(5);
if(key1==0)
{
num++;
if(num==60)
num=0;
}
}
while(!key1);
delay(5);
while(!key1);
if(key2==0)
{
delay(5);
if(key2==0)
{
num--;
0x87,0xff,0xef};
void display1(uchar numdi) //秒钟显示函数
{
uchar fen,miao;
fen=numdi/10;
miao=numdi%10;
dula=1;
P0=table[fen];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
sbit fm=P2^3;
uchar num,num1,num2,num3,temp;
void init();
void keyscan();
//void jianpan();
void delay(uint a)
{
uint x,z;
for(x=a;x>0;x--)
for(z=10;z>0;z--);
}
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
sbit key1=P3^4;
sbit key2=P3^5;
sbit key3=P3^6;
sbit key4=P3^7;