#include<reg52.h>
sbit k0=P1^0;
sbit k1=P1^1;
sbit k2=P1^2;
sbit k3=P1^3;
sbit k4=P1^4;
sbit k5=P1^5;
sbit k6=P1^6;
sbit k7=P1^7;
sbit B0=P3^7;
sbit l0=P2^0;
sbit l1=P2^2;
sbit l2=P2^3;
sbit l3=P2^4;
sbit kz=P3^0;
sbit ks=P3^1;
sbit key=P3^2 ;
sbit blue=P2^6;
sbit red=P3^6;
unsigned char qiangdanum=0x3f;
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char ge=0,shi=0; start;
unsigned int num=0,time=30;
void display(); /*显示函数*/
void delay(unsigned int);
void intial();
void delay(unsigned int z) /*延迟函数*/
{unsigned int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void intial()
{TMOD=0X01; /*采用方式一,即十六位计数器*/
TH0=(65536-50000)/256; /*设置初始值,50ms中断一次*/
TL0=(65536-50000)%256;
IT0=0;
EA=1;ET0=1; /*开启总中断源*/
EX0=1; } /*启动外部中断0*/
main()
{
intial();
{while(1)
{display();
if(ks==0)
{delay(5);
if (ks==0)
{ while(!ks)
{TR0=0;time=30;qiangdanum=0;blue=0; start=1;intial();}
}
}
if(kz==0)
{delay(5);
if (kz==0)
{while(!kz)
{ TR0=1;B0=1;delay(50);B0=0; qiangdanum=0;blue=0;intial(); /*开启定时器0中断*/
}
if(key==0)
if(start==0)
{while(!key)
{red=0; B0=1;delay(50);B0=0;intial();}
}
}
}
}
}
}
void exter0() interrupt 0 /*外部中断程序*/
{EA=0;l0=0;
if(k0==0) /*开关0按下*/
{delay(5);
if(k0==0)
{qiangdanum=1;blue=0; B0=1;delay(50);B0=0;}
} /* 1号选手抢答成功,数码管显示1*/
if(k1==0) /*开关1按下*/
{delay(5);
if(k1==0)
{qiangdanum=2; blue=0;B0=1;delay(50);B0=0;}
} /* 2号选手抢答成功,数码管显示2*/
if(k2==0) /*开关2按下*/
{delay(5);
if(k2==0)
{qiangdanum=3;blue=0; B0=1;delay(50);B0=0;blue=0;}
} /* 3号选手抢答成功,数码管显示3*/
if(k3==0) /*开关3按下*/
{delay(5);
if(k3==0)
{qiangdanum=4;blue=0; B0=1;delay(50);B0=0;blue=0;} /* 4号选手抢答成功,数码管显示4*/
}
if(k4==0) /*开关4按下*/
{delay(5);
if(k4==0)
{qiangdanum=5;blue=0; B0=1;delay(50);B0=0;} /* 5号选手抢答成功,数码管显示5*/
}
if(k5==0) /*开关5按下*/
{delay(5);
if(k5==0)
{qiangdanum=6; blue=0;B0=1;delay(50);B0=0;} /* 6号选手抢答成功,数码管显示6*/
}
if(k6==0) /*开关6按下*/
{delay(5);
if(k6==0)
{qiangdanum=7;blue=0; B0=1;delay(50);B0=0;} /* 7号选手抢答成功,数码管显示7*/
}
if(k7==0) /*开关7按下*/
{delay(5);
if(k7==0)
{qiangdanum=8; blue=0;B0=1;delay(50);B0=0;} /* 8号选手抢答成功,数码管显示8*/
}
}
void time0() interrupt 1
{num++;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
if(num==20)
{ num=0;
time--;
if(time==0) /*30秒的倒计时*/
{time=30;TR0=0;
}
}
} /*1秒定时函数,采用方式1重装*/
void display(void)
{shi=time/10;
ge=time%10;
P2=0xf7;
P0=table[ge];
delay(5);
P2=0xfb;
P0=table[shi];
delay(5);
P2=0xFe;
P0=table[qiangdanum];
delay(5); /*显示函数,显示选手号码和倒计时*/
}
|