#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar code table[10] ={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code led[8] = {0,1,2,3,4,5,6,7};
uchar num,second,temp,count,start_flag = 0,reset_flag,keyflag = 0,stop_flag=0,keylock,sounderflag;
sbit start= P3^2;
sbit fu= P3^1;
sbit stop= P3^4;
sbit key1 = P1^0;
sbit key2 = P1^1;
sbit key3 = P1^2;
sbit key4 = P1^3;
sbit key5 = P1^4;
sbit key6 = P1^5;
sbit key7 = P1^6;
sbit key8 = P1^7;
sbit buzzer = P3^5;
void delay(uchar z)
{
uchar x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void display(uchar num,uchar second)
{
uchar shi,ge;
shi=second/10;
ge=second%10;
P2=led[0];
P0=table[num];
delay(2);
P2=led[6];
P0=table[shi];
delay(2);
P2=led[7];
P0=table[ge];
delay(2);
}
void sounder()
{
buzzer=1;
delay(10);
buzzer=0;
delay(10);
buzzer=1;
delay(10);
buzzer=0;
delay(10);
buzzer=1;
delay(10);
buzzer=0;
delay(10);
}
uchar keyscan()
{
P1=0xfe;
temp=P1;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(2);
temp=P1;
temp=temp&0xf0;
while(temp!=0xf0)
{
keyflag=1;
temp=P1;
switch(temp)
{
case 0xee: num=1;
break;
case 0xde: num=2;
break;
case 0xbe: num=3;
break;
case 0x7e: num=4;
break;
}
while(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
}
//
P1=0xfd;
temp=P1;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(2);
temp=P1;
temp=temp&0xf0;
while(temp!=0xf0)
{
keyflag=1;
temp=P1;
switch(temp)
{
case 0xed: num=5;
break;
case 0xdd: num=6;
break;
case 0xbd: num=7;
break;
case 0x7d: num=8;
break;
}
while(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
}
//
P1=0xfb;
temp=P1;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(2);
temp=P1;
temp=temp&0xf0;
while(temp!=0xf0)
{
keyflag=1;
temp=P1;
switch(temp)
{
case 0xeb: num=9;
break;
case 0xdb: num=10;
break;
case 0xbb: num=11;
break;
case 0x7b: num=12;
break;
}
while(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
}
//
P1=0xf7;
temp=P1;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(2);
temp=P1;
temp=temp&0xf0;
while(temp!=0xf0)
{
keyflag=1;
temp=P1;
switch(temp)
{
case 0xe7: num=13;
break;
case 0xd7: num=14;
break;
case 0xb7: num=15;
break;
case 0x77: num=16;
break;
}
while(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
}
return num;
}
void start1()
{
if(start==0)
{
delay(5);
{
if(start==0)
{
start_flag=1;
TR0=1;
}
}
}
}
void stop1()
{
if(stop==0)
{
delay(5);
{
if(stop==0)
{
stop_flag=1;
TR0=0;
}
}
}
}
void init()
{
start_flag=0;
stop_flag=0;
num=0;
second=20;
count=0;
fu=0;
TMOD=0X01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=0;
P1=0XFF;
}
void main()
{
init();
while(1)
{
stop1();
start1();
if((start_flag==1)&&(keyflag==0)&&(stop_flag!=1))
{
num=keyscan();
}
display(num,second);
if((num==0)&&(sounderflag==1))
sounder();
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count==20)
{
count=0;
if(second!=0)
second--;
if(second==5)
sounderflag=1;
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>