下面是代码
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code weixuan[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
uchar code duanxuan[12]={0xc0,0xf9,0xa4,0xb0,0x99,0x82,0xf8,0x80,0x90,0xbf,0xff};
uchar data
timedata[3]={0x00,0x00,0x00};
uchar data datetime[8]={0xc0,0xc0,0xbf,0xc0,0xc0,0xbf,0xc0,0xc0}; //ʱ¼ä»º³åÇø£¬³õʼ»¯ÏÔʾ00-00-00
uchar tt1,tt2,tt,tt0,num=0;
uchar flag,flag1,flag2,flash;
sbit key1=P1^3;
sbit key2=P1^5;
sbit key3=P1^7;
/****************ÑÓʱº¯Êý*************/
void delay(uint del)
{
uchar i,j;
for(i=0;i<del;i++)
for(j=0;j<=148;j++);
}
/*************µ÷ÓÃÏÔʾ*************/
void display()
{
datetime[0]=timedata[0]%10;datetime[1]=timedata[0]/10;//Ãë
datetime[3]=timedata[1]%10;datetime[4]=timedata[1]/10;//·Ö
datetime[6]=timedata[2]%10;datetime[7]=timedata[2]/10;//ʱ
if(!flag)
{
P2=0x80;//ÃëÏÔʾ
P0=duanxuan[datetime[0]];
delay(2);
P2=0x40;
P0=duanxuan[datetime[1]];
delay(2);
}
else
{
P2=0x80;//ÃëÏÔʾ
P0=duanxuan[datetime[0]]|flash;
delay(2);
P2=0x40;
P0=duanxuan[datetime[1]]|flash;
delay(2);
}
P0=0x20;
P0=duanxuan[10];
delay(2);
if(!flag1)
{
P2=0x10;//·ÖÏÔʾ
P0=duanxuan[datetime[3]];
delay(2);
P2=0x08;
P0=duanxuan[datetime[4]];
delay(2);
}
else
{
P2=0x10;//·ÖÏÔʾ
P0=duanxuan[datetime[3]]|flash;
delay(2);
P2=0x08;
P0=duanxuan[datetime[4]]|flash;
delay(2);
}
P2=0x04;//СʱÏÔʾ
P0=duanxuan[10];
delay(2);
if(!flag2)
{
P2=0x02;//СʱÏÔʾ
P0=duanxuan[datetime[6]];
delay(2);
P2=0x01;
P0=duanxuan[datetime[7]];
delay(2);
}
else
{
P2=0x02;
P0=duanxuan[datetime[6]]|flash;
delay(2);
P2=0x01;
P0=duanxuan[datetime[7]]|flash;
delay(2);
}
}
/*************°´¼üµ÷½Úʱ¼ä**************/
void keyscan()
{
if(key1==0)
{
delay(10);
if(key1==0)
{
num++;
while(!key1);
while(1)
{
if(num==1)
{
flag=1;
flag1=0;
flag2=0;
if(key2==0)
{
delay(10);
if(key2==0)
{
delay(10);
if(key2==0)
{
timedata[0]--;
if(timedata[0]==-1)
timedata[0]=60;
while(!key2);
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
timedata[0]++;
if(timedata[0]==60)
timedata[0]=0;
while(!key3);
}
}
}
if(key1==0)
{
delay(10);
if(key1==0)
num++;
while(!key1);
}
if(num==2)
{
flag=0;
flag1=1;
flag2=0;
if(key2==0)
{
delay(10);
if(key2==0)
{
delay(10);
if(key2==0)
{
timedata[1]--;
if(timedata[1]==-1)
timedata[1]=60;
while(!key2);
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
timedata[1]++;
if(timedata[1]==60)
timedata[1]=0;
while(!key3);
}
}
}
if(num==3)
{
flag=0;
flag1=0;
flag2=1;
if(key2==0)
{
delay(10);
if(key2==0)
{
timedata[2]--;
if(timedata[2]==-1)
timedata[2]=24;
while(!key2);
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
timedata[2]++;
if(timedata[2]==25)
timedata[2]=0;
while(!key3);
}
}
}
if(num==4)
{
num=0;
flag=0;
flag1=0;
flag2=0;
break;
}
}
}
}
}
/**********Ö÷º¯Êý**************/
void main()
{
TMOD=1;
ET0=1;
TR0=1;
TH0=0x40;
TL0=0x00;
EA=1;
while(1)
{
keyscan();
}
}
/*************¶¨Ê±Æ÷º¯Êý*********/
void timer1() interrupt 1
{
TH0=0x40;
TL0=0x00;
P3=100;
display();
if((flag||flag1||flag2))
{
tt0++;
if(tt0==10)
{
flash=-flash;
tt0=0;
}
}
else
{
tt++;
if(tt=20)
{
tt=0;
timedata[0]++;
if(timedata[0]==60)
{
timedata[0]=0;
timedata[1]++;
if(timedata[1]==60)
{
timedata[1]=0;
timedata[2]++;
if(timedata[2]==24)
{
timedata[2]=0;
}
}
}
}
}
}
-
最后面那张图片那里不是说明么
一周热门 更多>