【求助】关于C语言编程--数字时钟~!
发布网友
发布时间:2022-05-06 10:47
我来回答
共1个回答
热心网友
时间:2022-06-29 19:40
#include <AT89X52.h>
unsigned char X=10,sec,flag;
unsigned char key[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};// 数码管显示数字表
unsigned char key2[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
unsigned char key1[]={0,0,0,0};//key1[0]=9 key1[1]=1 key1[2]=2 key1[3]=3
void delay02s(void);
void dislplay(void);
void dislplay1(void);
void tim1(void);
void main()
{
tim1();
while(1)
{
if(flag==0) dislplay();
else dislplay1();
}
}
void time1(void) interrupt 3
{
TR1=0;
X=X-1;
if(X==0)
{
flag=flag+1;
if(flag==2)
{
flag=0;
sec=sec+1;
if(sec==60)
{
sec=0;
key1[3]=key1[3]+1;
if(key1[3]==10);
{
key1[3]=0;
key1[2]=key1[2]+1;
if(key1[2]==6)
{
key1[2]=0;
key1[1]=key1[1]+1;
if(key[0]!=2)
{
if(key1[1]==10)
{
key1[1]=0;
key1[0]=key1[0]+1;
}
}
if(key[0]==2)
{
if(key[1]==4)
{
key1[1]=0;
key1[0]=0;
}
}
}
}
}
}
X=10;
}
TL1=0xb0;
TH1=0x3c;
TF1=0;
TR1=1;
}
void tim1(void)
{
TMOD =0X10;
TL1=0xb0;
TH1=0x3c;
EA=1;
ET1=1;
TR1=1;
}
void dislplay(void)
{
P2=0xfe;
P0=key[key1[0]];
delay02s();
P2=0xfd;
P0=key[key1[1]];
delay02s();
P2=0xfb;
P0=key[key1[2]];
delay02s();
P2=0xf7;
P0=key[key1[3]];
delay02s();
}
void dislplay1(void)
{
P2=0xfe;
P0=key[key1[0]];
delay02s();
P2=0xfd;
P0=key2[key1[1]];
delay02s();
P2=0xfb;
P0=key[key1[2]];
delay02s();
P2=0xf7;
P0=key[key1[3]];
delay02s();
}
void delay02s(void)
{
unsigned char i,j,k;
for(i=2;i>0;i--)
{
for(j=15;j>0;j--) //198
{
for(k=25;k>0;k--)//248
{
;
}
}
}
}