篮球计分器代码.docx
《篮球计分器代码.docx》由会员分享,可在线阅读,更多相关《篮球计分器代码.docx(9页珍藏版)》请在冰点文库上搜索。
![篮球计分器代码.docx](https://file1.bingdoc.com/fileroot1/2023-5/19/c5eaab98-2e5a-4923-aa9d-1f09e610567d/c5eaab98-2e5a-4923-aa9d-1f09e610567d1.gif)
篮球计分器代码
#include""
#include""
#defineuintunsignedint
#defineucharunsignedchar
intkey;
intnum;
intminute;
intsecond;
intas;
intbs;
mg,ms
uchartemp1[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchartemp2[8];
sbitled=P3^2;
sbitminytes=P2^7;
sbitminyteg=P2^6;
sbitseconds=P2^5;
sbitsecondg=P2^4;
sbita_s=P2^3;
sbita_g=P2^2;
sbitb_s=P2^1;
sbitb_g=P2^0;
voidkscan();
voiddelayms(uintz)//1ms延时
{
uintx,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
voidshow()
{
inti,x;
for(i=0;i<8;i++)
{
P2=temp1[i];
x=temp2[i];
P0=temp[x];
delayms(5);
P0=0xff;
P2=0xff;
}
}
voidtime_s()
{
if(second==0)
{
if(minute==0)
b=0;
else
{
minute=minute-1;
second=59;
}
}
else
second=second-1;
}
voidcopy()
{
temp2[7]=minute/10;
temp2[6]=minute%10;
temp2[5]=second/10;
temp2[4]=second%10;
temp2[3]=as/10;
temp2[2]=as%10;
temp2[1]=bs/10;
temp2[0]=bs%10;
}
voidtime()
{
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
EA=0;
ET0=1;
TR0=1;
}
////////////////////////////////////////////
voidmain()
{
bs=0;
as=0;
minute=10;
second=0;
num=0;
time();
b=1;
led=0;
while
(1)
{
if(b==0)
{EA=0;led=1;}
if(num==20)
time_s();
copy();
show();
kscan();
}
}
////////////////////////////
voidT0_time()interrupt1
{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
if(num==20)
num=0;
else
num++;
}
voidkscan()
{
inttemp,a;
P1=0xfe;
temp=P1;
temp=temp&0xf0;
if(temp!
=0xf0)
{
delayms(8);
if(temp!
=0xf0)
{
switch(temp)
{
case0xe0:
as=as+1;
break;
case0xd0:
as=as+2;
break;
case0xb0:
as=as+3;
break;
case0x70:
as=as-1;
break;
}
while(temp!
=0xf0)//松手检测
{
temp=P1;
temp=temp&0xf0;
}
}
}
P1=0xfd;
temp=P1;
temp=temp&0xf0;
if(temp!
=0xf0)
{
delayms(8);
if(temp!
=0xf0)
{
switch(temp)
{
case0xe0:
bs=bs+1;
break;
case0xd0:
bs=bs+2;
break;
case0xb0:
bs=bs+3;
break;
case0x70:
bs=bs-1;
break;
}
while(temp!
=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
}
P1=0xfb;
temp=P1;
temp=temp&0xf0;
if(temp!
=0xf0)
{
delayms(8);
if(temp!
=0xf0)
{
switch(temp)
{
case0xe0:
as=0;bs=0;
break;
case0xd0:
a=as;as=bs;bs=a;
break;
case0xb0:
EA=0;
break;
case0x70:
minute=10;second=0;
break;
}
while(temp!
=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P1=0xf7;
temp=P1;
temp=temp&0xf0;
if(temp!
=0xf0)
{
delayms(8);
if(temp!
=0xf0)
{
switch(temp)
{
case0xe0:
EA=1;
break;
case0xd0:
if(second==59){second=0;minute=minute+1;}
elsesecond=second+1;
break;
case0xb0:
if(second==0)
{if(minute==0);
else
{minute=minute-1;second=59;}}
elsesecond=second-1;
break;
case0x70:
key=16;
break;
}
while(temp!
=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
}
//返回值是num
}