求助,数码管时钟程序
时间:10-02
整理:3721RD
点击:
调分的时候想让显示分的数码管闪烁,调时的时候想让显示小时的数码管闪烁
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
sbit key1=P3^4;
sbit key2=P3^5;
sbit key3=P3^6;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar num,num1,num2,num3,numt0;
void delay(uint z);
void display(uchar num,num1,num2)
{
uchar shiwan,qian,wan,bai,shi,ge;
shiwan=num/10;
wan=num%10;
qian=num1/10;
bai=num1%10;
shi=num2/10;
ge=num2%10;
dula=1;
P0=table[shiwan];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(1);
dula=1;
P0=table[wan];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(1);
dula=1;
P0=table[qian];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(1);
dula=1;
P0=table[bai];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(1);
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
delay(1);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
wela=0;
delay(1);
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void init()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void keyscan()
{
if(key1==0)
{
delay(10);
if(key1==0)
{
if(num3==0)
{
TR0=1;
}
if(num3==1)
{
num1++;
if(num1==60)
{
num1=0;
}
while(!key1);
}
if(num3==2)
{
num++;
if(num==24)
{
num=0;
}
while(!key1);
}
}
}
if(key2==0)
{
delay(10);
if(key2==0)
{
if(num3==0)
{
TR0=1;
}
if(num3==1)
{
num1--;
if(num1==0)
{
num1=60;
}
while(!key2);
}
if(num3==2)
{
num--;
if(num3==0)
{
num3=24;
}
while(!key2);
}
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
TR0=0;
num3++;
if(num3==3)
{
num3=0;
}
if(num3==0)
{
TR0=1;
}
while(!key3);
}
}
}
void main()
{
init();
while(1)
{
keyscan();
display(num,num1,num2);
}
}
void T0_time() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
numt0++;
if(numt0==20)
{
numt0=0;
num2++;
if(num2==60)
{
num2=0;
num1++;
if(num1==60)
{
num1=0;
num++;
if(num==24)
num=0;
}
}
}
}
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
sbit key1=P3^4;
sbit key2=P3^5;
sbit key3=P3^6;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar num,num1,num2,num3,numt0;
void delay(uint z);
void display(uchar num,num1,num2)
{
uchar shiwan,qian,wan,bai,shi,ge;
shiwan=num/10;
wan=num%10;
qian=num1/10;
bai=num1%10;
shi=num2/10;
ge=num2%10;
dula=1;
P0=table[shiwan];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(1);
dula=1;
P0=table[wan];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(1);
dula=1;
P0=table[qian];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(1);
dula=1;
P0=table[bai];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(1);
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
delay(1);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
wela=0;
delay(1);
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void init()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void keyscan()
{
if(key1==0)
{
delay(10);
if(key1==0)
{
if(num3==0)
{
TR0=1;
}
if(num3==1)
{
num1++;
if(num1==60)
{
num1=0;
}
while(!key1);
}
if(num3==2)
{
num++;
if(num==24)
{
num=0;
}
while(!key1);
}
}
}
if(key2==0)
{
delay(10);
if(key2==0)
{
if(num3==0)
{
TR0=1;
}
if(num3==1)
{
num1--;
if(num1==0)
{
num1=60;
}
while(!key2);
}
if(num3==2)
{
num--;
if(num3==0)
{
num3=24;
}
while(!key2);
}
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
TR0=0;
num3++;
if(num3==3)
{
num3=0;
}
if(num3==0)
{
TR0=1;
}
while(!key3);
}
}
}
void main()
{
init();
while(1)
{
keyscan();
display(num,num1,num2);
}
}
void T0_time() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
numt0++;
if(numt0==20)
{
numt0=0;
num2++;
if(num2==60)
{
num2=0;
num1++;
if(num1==60)
{
num1=0;
num++;
if(num==24)
num=0;
}
}
}
}