#include<reg52.h>
unsigned char code a[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; c[]={0xfe,0xfd,0xf7,0xef,0xbf,0x7f} ;here[6];
void xianshi();
void singsong();
void keydown();
void timer1();
sbit fmq=P1^5;
unsigned char keyvalue,i=0,keypress,miao=0;M=0;minute=0;hour=0;r=0;
void delay(unsigned int i)
{ char j;
for(i; i > 0; i--)
for(j = 115; j> 0; j--);
}
void main()
{
fmq=0;
TMOD=0x01;
TR0=1;
ET0=1;
EA=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
while(1)
{
xianshi();
singsong();
keydown();
switch(keyvalue)
{
case(0xee):
{
{
miao=10;
keyvalue=0xff;
}
break;
}
case(0xed):
{
{
miao++;
keyvalue=0xff;
}
break;
}
case(0xeb):
{
miao--;
break;
}
}
}
miao=0;
}
void timer() interrupt 1
{
M++;
if(M==20)
{
miao++;
if(miao==60)
{
miao=0;
minute++;
if(minute==10)
{
minute=0;
hour++;
if(hour==12)
{
hour=0;
}
}
}
M=0;
}
}
void keydown(void)
{unsigned char key;
P3=0xf0;
key=P3|0x0f;
if(key!=0xff)
{
delay(10);
P3=0xf0;
key=P3|0x0f;
if(key!=0xff)
{ P3=key;
keyvalue=P3;
keypress=1;
}
}
}
void xianshi(void)
{ int b;
for(b=0;b<6;b++)
{
here[1]=miao/10;
here[0]=miao%10;
here[2]=minute%10;
here[3]=minute/10;
here[4]=hour%10;
here[5]=hour/10;
P2=0xff;
P0=0xff;
P2=c;
P0=a[here];
delay(1);
}
}
void singsong()
{ int i;
if(miao==35)
{ for(i=0;i<50;i++)
{ fmq=1;
delay(1);
fmq=0;
delay(1);
}
}
}
为啥 实现加1 减1 时控制不好
|