//按钮P1;灯P0;数码管P2; P3^0主持人控制开关
#include#define uc unsigned char
sbit li1=P0^0;
sbit li2=P0^1;
sbit li3=P0^2;
sbit li4=P0^3;
sbit li5=P0^4;
sbit li6=P0^5;
sbit li7=P0^6;
sbit li8=P0^7; //定义灯
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 zhuchi=P3^0;
uc code table[]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delay(uc xms);
void main()
{P2=0x00; //共阴数码管全灭
while(1)
{
if(key1==0) //选手1
{
delay(10);//去抖延时
if(key1==0)
{P2=table[1];li1=0;}
while(1)
{
if(zhuchi==0)
{delay(10);
if(zhuchi==0)
{P2=0x00;li1=1;break;}}
}
} //选手1
if(key2==0) //选手2
{
delay(10);//去抖延时
if(key2==0)
{P2=table[2];li2=0;}
while(1)
{
if(zhuchi==0)
{delay(10);
if(zhuchi==0)
{P2=0x00;li2=1;break;}}
}
} //选手2
if(key3==0) //选手3
{
delay(10);//去抖延时
if(key3==0)
{P2=table[3];li3=0;}
while(1)
{
if(zhuchi==0)
{delay(10);
if(zhuchi==0)
{P2=0x00;li3=1;break;}}
}
} //选手3
if(key4==0) //选手4
{
delay(10);//去抖延时
if(key4==0)
{P2=table[4];li4=0;}
while(1)
{
if(zhuchi==0)
{delay(10);
if(zhuchi==0)
{P2=0x00;li4=1;break;}}
}
} //选手4
if(key5==0) //选手5
{
delay(10);//去抖延时
if(key5==0)
{P2=table[5];li5=0;}
while(1)
{
if(zhuchi==0)
{delay(10);
if(zhuchi==0)
{P2=0x00;li5=1;break;}}
}
} //选手5
if(key6==0) //选手6
{
delay(10);//去抖延时
if(key6==0)
{P2=table[6];li6=0;}
while(1)
{
if(zhuchi==0)
{delay(10);
if(zhuchi==0)
{P2=0x00;li6=1;break;}}
}
} //选手6
if(key7==0) //选手7
{
delay(10);//去抖延时
if(key7==0)
{P2=table[7];li7=0;}
while(1)
{
if(zhuchi==0)
{delay(10);
if(zhuchi==0)
{P2=0x00;li7=1;break;}}
}
} //选手7
if(key8==0) //选手8
{
delay(10);//去抖延时
if(key8==0)
{P2=table[8];li8=0;}
while(1)
{
if(zhuchi==0)
{delay(10);
if(zhuchi==0)
{P2=0x00;li8=1;break;}}
}
} //选手8
}
}
void delay(uc xms) //延时函数
{
uc i,j;
for(i=xms;i>0;i–)
for(j=110;j>0;j–);
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/179878.html原文链接:https://javaforall.cn