赞
踩
#include
typedef unsigned char u8;
typedef unsigned int u16;
sbit led3=P2^2;
sbit led2=P2^3;
sbit led1=P2^4;
sbit key1=P3^2;
sbit key2=P3^3;
sbit beep=P1^5;
void delay(u16 i)
{
u8 a;
while(i--)
{
for(a=0;a<125;a++)
{
;
}
}
}
u16 code duanxuan[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void weixuan(u16 i)
{
switch(i)
{
case (0) : led1=0;led2=0;led3=0;break;
case (1) : led1=0;led2=0;led3=1;break;
case (2) : led1=0;led2=1;led3=0;break;
case (3) : led1=0;led2=1;led3=1;break;
case (4) : led1=1;led2=0;led3=0;break;
case (5) : led1=1;led2=0;led3=1;break;
case (6) : led1=1;led2=1;led3=0;break;
case (7) : led1=1;led2=1;led3=1;break;
}
}
void display(u16 i,u16 j)
{
weixuan(i);
P0=duanxuan[j];
}
u16 a=0; //判断是否有选手按下
void saomiao ()
{
P1=0xf0;
if(P1!=0xf0)
{
delay(10);
if (P1!=0xf0)
{
P1=0X7f;
switch(P1)
{
case(0x77) : a=1;break;
case(0x7b) : a=2;break;
case(0x7d) : a=3;break;
case(0x7e) : a=4;break;
}
P1=0xf0;
while(P1!=0xf0);
}
}
}
u16 i=0,j=0,n=10,m=0,k,weigui[3],v=0; //m=1表示按下开始
void daojishi()
{
P0=0x00;
display(0,n%10);
delay(1);
P0=0x00;
display(1,n/10);
delay(1);
if(n==0)
{
TR0=0;
}
}
void main()
{
EA=1;
EX0=1;
IT0=1;
EX1=1;
IT1=1;
ET0=1;
TMOD=0X01;
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
while(1)
{
v=0;
P0=0x00;
if(m==0)
{
saomiao();
if(a!=0)
{
while(1)
{
if(v==1)
{
break;
}
saomiao();
if(a!=0)
{
weigui[j]=a;
if(j>0)
{
if(weigui[j]!=weigui[j-1])
{
j++;
}
}
if(j<1)
{
j++;
}
}
a=0;
for(k=0;k
{
P0=0x00;
display(k,weigui[k]);
beep=~beep;
delay(10);
}
if(j==3)
{
while(1)
{
for(k=0;k
{
P0=0x00;
display(k,weigui[k]);
beep=~beep;
delay(1);
}
if(v==1)
{
break;
}
}
}
}
}
}
if(m==1)
{
daojishi(); //开始倒计时
saomiao();
if(a!=0)
{
while(1)
{
P0=0x00;
display(0,a);
delay(10);
if(v==1)
{
break;
}
}
}
}
}
}
void zhongduan0() interrupt 0
{
delay(10);
if(key1==0)
{
TR0=1;
m=1;
while(key1==0);
}
}
void zhongduan1() interrupt 2
{
delay(10);
if(key2==0)
{
n=10;
m=0;
a=0;
j=0;
v=1;
TR0=0;
while(key2==0);
}
}
void dingshiqi() interrupt 1
{
i++;
if(i==1000)
{
i=0;
n--;
}
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。