|
想做一个乒乓球游戏机 功能:刚开始通过产生一个随机数来判断谁发球 当球(就是发光二极管)达到两端是按下击球键 球向回走 若未接到 则对方得一分
这是我的程序
#include<reg52.h>
#include<intrins.h>
#include<stdlib.h>
#define uint unsigned int
#define uchar unsigned char
void change();
void display();
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f };
uchar aa,mm;
uint SUM=0;
sbit PA=P1^0;
sbit PB=P1^1;
sbit PC=P1^2;
sbit dula=P2^0;
sbit wela=P2^1;
void delay(uint xms)
{ uint m,n;
for(m=xms;m>0;m--)
for(n=110;n>0;n--) ;
}
void main()
{ int j,i;
P3=0x00;
wela=1;
P0=0x00;
wela=0;
dula=1;
P0=table[0] ;
dula=0;
i=rand();
if(i%2==0)
aa=0x80;
else
aa=0x01;
while(1)//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
{ if(PC==0) //..........................................
{ delay(10);
if(PC==0)
{ P3=aa; //裁判判断谁发球
}
while(~PC);//..........................................
}
if(PB==0) //.........................................
{ delay(10);
if(PB==0)
{ if(P3==0x01)
{ aa=0x01;
for(j=0;j<8;j++)
{ P3=aa;
delay(200);
aa=_crol_(aa,1);//判断为B时B发球
}
mm=0x80;
}
while(~PB);
}
} //.........................................
if(PA==0) //.........................................
{ delay(10);
if(PA==0);
{ if(P3==0x80)
{ aa=0x80;
for(j=0;j<8;j++)
{ P3=aa; //判断为A时A发球
delay(200);
aa=_cror_(aa,1);
}
mm=0x01;
}
while(~PA);
}
} //..................................................
if(mm==0x80&&PA!=0)
{ P3=0x00;
SUM=SUM+1;
}
if(mm==0x01&&PB!=0)
{ P3=0x00;
SUM=SUM+100;
}
display();
} //while()结尾的括号$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
} //main()结尾的括号%%%%%%%%%%%%%%%%%%%%%%%%%%
void display(void)
{ P0=0x0e;
wela=1;
wela=0;
P0=table[SUM%10];
dula=1;
dula=0;
delay(2);
P0=0x0d ;
wela=1;
wela=0;
P0=table[SUM/10%10];
dula=1;
dula=0;
delay(2);
P0=0x0b;
wela=1;
wela=0;
P0=table[SUM/100%10];
dula=1;
dula=0;
delay(2);
P0=0x07;
wela=1;
wela=0;
P0=table[SUM/1000%10];
dula=1;
dula=0;
delay(2);
}
为什么一按按键数码管的灯就灭了 然后按下击球键 数码管就不断地出随机数
|
|