📄 00.c
字号:
#include<reg51.h>
#define uchar unsigned char
uchar j,k,i,a,A1,A2,A3,A4,A5,A6,second,min,hour;
sbit key0=P1^0;
sbit key1=P1^3;
sbit key2=P1^6;
bit L=0;//长溢出标志位
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90};//编码0~9
uchar code select[]={0x01,0x02,0x04,0x08,0x10,0x20};//位选通
uchar time[3];
uchar con=0;
uchar con1=0;
uchar con2=0;
void delay(uchar i)//延时
{
for(j=i;j>0;j--)
for(k=125;k>0;k--);
}
void keyscan(void)//键盘扫描
{EA=0;
if(!key0)
{ delay(10);
while(!key0);
con++;TR0=0;ET0=0;
}
if(con>=3)
con=0;TR0=1;ET0=1;
if(con!=0)
{if(!key1)
{delay(10);
while(!key1);
{time[con]++;
if(con==2)
con1=24;else con1=60;
if(time[con]>con1)
{time[con]=0;}
}
}
}
if(con!=0)
{if(!key2)
{delay(10);
while(!key2);
{time[con]--;
if(con==2)
con2=23;else con2=59;
if(time[con]<0)
{time[con]=con2;}
}
}
}
EA=1;
}
void display(uchar sh_c,uchar g_c,uchar sh_b,uchar g_b,uchar sh_a,uchar g_a)//显示部分
{ P0=table[sh_c];
P3=select[0];
delay(5);
P3=0;
P0=table[g_c];
P3=select[1];
delay(5);
P3=0;
P0=table[sh_b];
P3=select[2];
delay(5);
P3=0;
P0=table[g_b];
P3=select[3];
delay(5);
P3=0;
P0=table[sh_a];
P3=select[4];
delay(5);
P3=0;
P0=table[g_a];
P3=select[5];
delay(5);
P3=0;
}
void main()
{TMOD=0x01;TH0=0x03;TL0=0xb0;
TR0=1;
ET0=1;
EA=1;
time[0]=00;
time[1]=00;
time[2]=12;
A1=time[0]/10;
A2=time[0]%10;
A3=time[1]/10;
A4=time[1]%10;
A5=time[2]/10;
A6=time[2]%10;
display(A1,A2,A3,A4,A5,A6);
while(1)
{keyscan();
if(L)
{
L=0;
time[0]++;
if(time[0]==60)
{time[0]=0;time[1]++;
{if(time[1]==60)
{ time[1]=0;time[2]++;
{if(time[2]==24)
time[2]=0;
}
}
}
}
}
A1=time[0]/10;
A2=time[0]%10;
A3=time[1]/10;
A4=time[1]%10;
A5=time[2]/10;
A6=time[2]%10;
{ display(A1,A2,A3,A4,A5,A6);};
}
}
void t0(void) interrupt 1//1S延时
{ static uchar t;
TF0=0;
t++;
if(t==11)
{t=0;L=1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -