基于51单片机篮球记分牌设计.docx
《基于51单片机篮球记分牌设计.docx》由会员分享,可在线阅读,更多相关《基于51单片机篮球记分牌设计.docx(10页珍藏版)》请在冰豆网上搜索。
基于51单片机篮球记分牌设计
基于51单片机篮球记分牌设计(数码管显示)
#include
unsignedchara1,b1,c1,a2,b2,c2,d1,d2,e3,f3,g3,h3,i,j,flag10,flag11,flag12;
unsignedcharaf,bf,time=24,cnt1,cnt2;
signedinttime1=720;
sbitaj=P1^0;
sbitbj=P1^1;
sbitcn=P1^2;
sbitbn=P1^3;
sbiten=P3^2;
sbitfn=P3^3;
sbithn=P3^0;
sbitgn=P3^4;
sbitset=P1^4;
sbittj=P1^5;
sbittz=P1^6;
sbitot=P1^7;
bitflag1=0,flag2=0,flag3=0,flag4=0,flag5=0,flag6,flag7,flag8,flag9;
unsignedchars[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40,0x7c,0x39,0x5e,0x79,0x3e};
voiddelay(unsignedchari);
voiddisplay();
voidsw();
voidabbfen();
voidesnny();
voidesnne();
voidesnns();
voidesfzw();
voidhfwz();
voidot1();
voidsetj();
voidtimej();
voidtimez();
voidmain()
{TMOD=0x11;
TH0=0x3c;
TL0=0xb0;
TH1=0x3c;
TL1=0xb0;
EA=1;
ET0=1;
ET1=1;
while
(1)
{
display();
abbfen();
sw();
esnny();
esnne();
esnns();
esnne();
esfzw();
hfwz();
timej();
timez();
setj();
ot1();
}
}
voiddelay(unsignedchari)
{
unsignedcharj,k;
for(k=0;k
for(j=0;j<10;j++);
}
voiddisplay()
{
a1=af/100;
b1=af%100/10;
c1=af%100%10;
P2=0x00;
P0=s[a1];
delay
(2);
P2=0x01;
P0=s[b1];
delay
(2);
P2=0x02;
P0=s[c1];
delay
(2);
P2=0x03;
P0=s[10];
delay
(2);
a2=bf/100;
b2=bf%100/10;
c2=bf%100%10;
P2=0x04;
P0=s[10];
delay
(2);
P2=0x05;
P0=s[a2];
delay
(2);
P2=0x06;
P0=s[b2];
delay
(2);
P2=0x07;
P0=s[c2];
delay
(2);
e3=time1/60/10;
f3=time1/60%10;
g3=time1%60/10;
h3=time1%60%10;
P2=0x08;
P0=s[e3];
delay
(2);
P2=0x09;
P0=s[f3];
delay
(2);
P2=0x0a;
P0=s[g3];
delay
(2);
P2=0x0b;
P0=s[h3];
delay
(2);
d1=time/10;
d2=time%10;
P2=0x0c;
P0=s[d1];
delay
(2);
P2=0x0d;
P0=s[d2];
delay
(2);
}
voidabbfen()
{
if(aj==0)
{delay(10);}
if(aj==0)
{flag1=1;}
if(flag1==1&&aj==1)
{flag1=0;
af++;
}
}
voidsw()
{if(bj==0)
{delay(10);}
if(bj==0)
{flag2=1;}
if(flag2==1&&bj==1)
{flag2=0;
bf++;
}
}
voidesnny()
{
if(cn==0)
{delay(10);}
if(cn==0)
{flag3=1;}
if(flag3==1&&cn==1)
{flag3=0;
TR0=1;
}
}
voidesnne()
{
if(bn==0)
{delay(10);}
if(bn==0)
{flag4=1;}
if(flag4==1&&bn==1)
{flag4=0;
TR0=0;
}
}
voidesfzw()
{
if(en==0)
{delay(10);}
if(en==0)
{flag5=1;}
if(flag5==1&&en==1)
{flag5=0;
TR1=1;
}
}
voidesnns()
{
if(fn==0)
{delay(10);}
if(fn==0)
{flag6=1;}
if(flag6==1&&en==1)
{flag6=0;
TR1=0;
}
}
voidhfwz()
{
if(gn==0)
{delay(10);}
if(gn==0)
{flag7=1;}
if(flag7==1&&gn==1)
{flag7=0;
time=24;
}
}
voidsetj()
{
if(set==0)
{delay(10);}
if(set==0)
{flag10=1;}
if(flag10==1&&set==1)
{flag10=0;
j++;
if(j==3)j=0;
}
}
voidot1()
{
if(ot==0)
{delay(10);}
if(ot==0)
{flag12=1;}
if(flag12==1&&ot==1)
{flag12=0;
time1=300;
}
}
voidtimej()
{
if(tj==0)
{delay(10);}
if(tj==0)
{flag8=1;}
if(flag8==1&&tj==1)
{flag8=0;
switch(j)
{
case0x00:
break;
case0x01:
time1--;break;
case0x02:
time1=time1-60;break;
default:
break;
}}
}
voidtimez()
{
if(tz==0)
{delay(10);}
if(tz==0)
{flag9=1;}
if(flag9==1&&tz==1)
{flag9=0;
switch(j)
{
case0x00:
break;
case0x01:
time1++;break;
case0x02:
time1=time1+60;break;
default:
break;
}}
}
voidint1()interrupt1
{
TH0=0x3c;
TL0=0xb0;
cnt1++;
if(cnt1==21)
{
cnt1=0;
time1--;
}
if(time1==-1)
{
time1=720;
}
}
voidint3()interrupt3
{
TH1=0x3c;
TL1=0xb0;
cnt2++;
if(cnt2==21)
{
cnt2=0;
time--;
if(time==-1)
{
time=24;
hn=0;
hn=1;
}
}
}