比賽計(jì)分系統(tǒng)
1.通過按鍵實(shí)現(xiàn)獨(dú)立實(shí)現(xiàn)雙方得分的加分和減分操作,并顯示在LED數(shù)碼管上:
2.每隊(duì)比賽過程中有6次暫停機(jī)會(huì),雙方各自可用暫停次數(shù)顯示在LED數(shù)碼管上:
3.暫停期間,加分減分按鍵失效,防止誤操作。
#include "reg51.h"
#define uchar unsigned char
#define uint unsigned int
sbit smg1=P2^5;//數(shù)碼管引腳
sbit smg2=P2^6;
sbit smg3=P2^7;
sbit led1=P3^7;//led
sbit led2=P3^6;
sbit k1=P1^0;//按鈕
sbit k2=P1^1;
sbit k3=P1^2;
sbit k4=P1^3;
sbit k5=P1^4;
sbit k6=P1^5;
sbit k7=P1^6;
sbit k8=P1^7;
//數(shù)碼管編碼
uchar code smgduan[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar fena=0,fenb=0,cishu1=6,cishu2=6;//分?jǐn)?shù)
//延時(shí)
void delay(uint i)
{
while(i--);
}
void main() //主函數(shù)
{
uchar k=0;
while(1)
{
if(!k4)//開始
{
delay(10000);//延時(shí)防抖
if(!k4 &&(k!=4))
{
k=4;
led1=0;
}
}
if(!k8)//停止
{
delay(10000);//延時(shí)防抖
if(!k8 &&(k!=8))
{
k=8;
led1=1;
led2=1;
fena=0;
fenb=0;
cishu1=6;
cishu2=6;
}
}
//暫停
if(!led1)
{
if(!k3)//A
{
delay(10000);//延時(shí)防抖
if(!k3 &&(k!=3))
{
k=3;
if((cishu1>0)&& led2)
{
cishu1--;
led2=0;
}
else
?
閱讀全文