#include<reg51.h> #include<reg51.h>
//#define char signed char
char code dis_7[12]=
{0xc0,0xf9,0xa4,0x4b0,0x99,0x92,0xb2,0xf8,0x80,0x90,0xff,0xbf};
char code scan_con[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
char data dis[8]={0x00,0x00,0x0b,0x00,0x00,0x0b,0x00,0x00};
char data timedata[3]={0x00,0x00,0x00};
char data ms50=0x00,con=0x00,con1=0x00,con2=0x00;
sbit key0=P1^0;
sbit key1=P1^1;
sbit key2=P1^2;
delay1ms(int t)
{
int i, j;
for (i=0; i<t; i++)
for (j=0; j<120; j++)
;
}
keyscan()
{
EA=0;
if (key0 == 0)
{
delay1ms (10);
while (key0 == 0);
con++;TR0=0; ET0=0;
if (con >= 3)
{con=0; TR0=1;ET0=1;}
}
if (con!= 0)
{
if(key1==0)
{
delay1ms(10);
while(key1==0);
timedata[con]++;
if(con==2) con1=24;else con1=60;
if(timedata[con]>=con1)
{timedata[con]=0;}
}
}
if (con!=0)
{
if (key2==0)
{
delay1ms(10);
while(key2==0);
timedata[con]--;
if (con==2) con2=23; else con2=59;
if(timedata[con]<=0)
{timedata[con]=con2;}
}
}
EA=1;
}
scan()
{
char k;
dis[0]=timedata[0]%10;dis[1]=timedata[0]/10;
dis[3]=timedata[1]%10;dis[4]=timedata[1]/10;
dis[6]=timedata[2]%10;dis[7]=timedata[2]/10;
for(k=0;k<8;k++)
{
P0=dis_7[dis[k]]; P2=scan_con[k]; delay1ms(1); P2=0xff;
}
}
main()
{
TH0=0x3c; TL0=0xb0;
TMOD=0x01; ET0=1; TR0=1; EA=1;
while (1)
{
scan();
keyscan();
}
}
void time_intt0(void) interrupt 1
{
ET0=0; TR0=0; TH0=0x3c; TL0=0xb0; TR0=1;
ms50++;
if(ms50==20)
{
ms50=0x00; 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;
}
}
}
}
ET0=1;
}
#define char signed char
char code dis_7[12]=
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00,0x40};
char code scan_con[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
char data dis[8]={0x00,0x00,0x0b,0x00,0x00,0x0b,0x00,0x00};
char data timedata[3]={0x00,0x00,0x00};
char data ms50=0x00,con=0x00,con1=0x00,con2=0x00;
sbit key0=P1^0;
sbit key1=P1^1;
sbit key2=P1^2;
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
delay1ms(int t)
{
int i, j;
for (i=0; i<t; i++)
for (j=0; j<120; j++)
;
}
keyscan()
{
EA=0;
if (key0 == 0)
{
delay1ms (10);
while (key0 == 0);
con++;TR0=0; ET0=0;
if (con >= 3)
{con=0; TR0=1;ET0=1;}
}
if (con!= 0)
{
if(key1==0)
{
delay1ms(10);
while(key1==0);
timedata[con]++;
if(con==2) con1=24;else con1=60;
if(timedata[con]>=con1)
{timedata[con]=0;}
}
}
if (con!=0)
{
if (key2==0)
{
delay1ms(10);
while(key2==0);
timedata[con]--;
if (con==2) con2=23; else con2=59;
if(timedata[con]<=0)
{timedata[con]=con2;}
}
}
EA=1;
}
scan()
{
char k;
dis[0]=timedata[0]%10;dis[1]=timedata[0]/10;
dis[3]=timedata[1]%10;dis[4]=timedata[1]/10;
dis[6]=timedata[2]%10;dis[7]=timedata[2]/10;
for(k=0;k<8;k++)
{
P0=dis_7[dis[k]]; P2=scan_con[k]; delay1ms(1); P2=0xff;
}
}
main()
{
TH0=0x3c; TL0=0xb0;
TMOD=0x01; ET0=1; TR0=1; EA=1;
while (1)
{
scan();
keyscan();
}
}
void time_intt0(void) interrupt 1
{
ET0=0; TR0=0; TH0=0x3c; TL0=0xb0; TR0=1;
ms50++;
if(ms50==20)
{
ms50=0x00; 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;
}
}
}
}
ET0=1;
}
|