?
?
左下角的独立按键k1控制开始和暂停 ,k2按一下加一小时,k3按一下加十分钟,k4按一下加一分钟
#include<reg52.h>
typedef unsigned int u16;
typedef unsigned char u8;
char mb[8],key2biao=0,key3biao=0,key4biao=0,key1biao=0;
u16 n=10,ss;
long temp,aa,s;
sbit key1=P3^1;
sbit key2=P3^0;
sbit key3=P3^2;
sbit key4=P3^3;
sbit weixuan1=P2^2;
sbit weixuan2=P2^3;
sbit weixuan3=P2^4;
char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40,0x00};
void delay(int z);
void display();
void init();
void keyscan();
void main()
{
init();
while(1)
{
keyscan();
if(s==20)
{
s=0;
temp++;
}
mb[7]=temp/36000;
mb[6]=temp/3600%10;
mb[5]=n;
mb[4]=temp/600%6;
mb[3]=temp/60%10;
mb[2]=n;
mb[1]=temp/10%6;
mb[0]=temp%10;
display();
}
}
void display ()
{
u8 i;
for(i=0;i<8;i++)
{
switch(i)
{
case(0):
weixuan1=0;weixuan2=0;weixuan3=0;break;
case(1):
weixuan1=1;weixuan2=0;weixuan3=0;break;
case(2):
weixuan1=0;weixuan2=1;weixuan3=0;break;
case(3):
weixuan1=1;weixuan2=1;weixuan3=0;break;
case(4):
weixuan1=0;weixuan2=0;weixuan3=1;break;
case(5):
weixuan1=1;weixuan2=0;weixuan3=1;break;
case(6):
weixuan1=0;weixuan2=1;weixuan3=1;break;
case(7):
weixuan1=1;weixuan2=1;weixuan3=1;break;
}
P0=table[mb[i]];
delay(1);
P0=0x00;
}
}
void init()
{
TMOD|=0x11;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
EA=1;
ET0=1;
TR0=0;
ET1=1;
TR1=0;
IT0=1;
EX0=1;
}
void te () interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
s++;
}
void tee() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
ss++;
if(ss==10)
{
ss=0;
if(n==10)
{
n=11;
}
else n=10;
}
}
void delay (int xms)
{
int x,y;
for (x=xms;x>0;x--)
for (y=123;y>0;y--);
}
void keyscan()
{
if((key1==0)&&(!key1biao))
{
delay(1);
key1biao=1;
if(key1==0)
{
if (TR0==0)
{
TR0=1;
TR1=1;
}
else if(TR0==1)
{
TR0=0;
TR1=0;
}
}
}
else if(key1!=0)
{
key1biao=0;
}
if((key2==0)&&(!key2biao))
{
delay(1);
key2biao=1;
if(key2==0)
{
TR0=0;
temp=temp+3600;
if (temp>86400)
{
temp = 0;
}
}
}
else if(key2!=0)
{
key2biao=0;
}
if((key3==0)&&(!key3biao))
{
delay(1);
key3biao=1;
if(key3==0)
{
TR0=0;
temp=temp+600;
}
}
else if(key3!=0)
{
key3biao=0;
}
if((key4==0)&&(!key4biao))
{
delay(1);
key4biao=1;
if(key4==0)
{
TR0=0;
temp=temp+60;
}
}
else if(key4!=0)
{
key4biao=0;
}
}
|