如果一号工位有球那么抓一号工位的球,如果2号工位有球抓2号工位的球,如果两个工位都有球,抓白球。
帮我改一下,在主函数里面,谢谢了!
#include<at89x52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]=
{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,
0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff,};
uchar str[8]={16,16,16,16,16,16,16,16,};
uchar xdata DM _at_ 0x7fff;
uchar xdata PX _at_ 0xbfff;
#define key0 P3_0
#define key1 P3_1
#define key2 P3_2
#define key3 P3_3
#define key4 P3_4
#define key6 P3_5
#define key7 P3_7
#define P1_ck P1_0
#define P2_ck P1_1
#define P3_ck P1_2
#define Up_ck P1_3
#define Down_ck P1_4
#define Grab_ck P1_5
#define P1_Get_ck P1_6
#define P2_Get_ck P1_7
#define Left P2_0=0,P2_1=1
#define Right P2_0=1,P2_1=0
#define Stop P2_0=1,P2_1=1
#define Grab P2_2=0,P2_3=1
#define Lose P2_2=1,P2_3=0
#define Up P2_4=1
#define Down P2_4=0
void Init();
void DP();
void fuwei();
uchar keyscan();
uchar dp_h,key;
uint k_time,Mode,num;
bit Mflag,yxflag,ztflag,csflag,Mflag;
void main()
{
Init();
fuwei();
while(1)
{
str[0]=Mode;
str[7]=num;
if(key==1){yxflag=1;ztflag=0;}
if(key==2){Right;}
if(key==4){Left;}
if(key==6){ztflag=1;}
if((yxflag==1)&&(ztflag==0))
{
switch(Mode)
{
/* case 0:Right;if(P1_ck==0){Stop;Mflag=1;}break;
case 1:if(P1_Get_ck==0)Mflag=1;
if((P1_Get_ck==1)&&(P2_Get_ck==0))Mode=4;break;
case 2:Down;if(Down_ck==0){Grab;Mflag=1;}break;
case 3:Up;if(Up_ck==0)Mode=5;break;
case 4:Left;if(P2_ck==0){Stop;Mode=2;}break;
case 5:Left;if(P3_ck==0){Stop;Lose;Mflag=1;}break;
case 6:num++;if(num>=3){Mflag=1;}else{Mode=0;}break;*/
case 0:if((P1_Get_ck==0)&&(P2_Get_ck==1))Mflag=1;
if(Grab_ck==0)Mflag=1;
if(Grab_ck==1)Mode=3;
if((P1_Get_ck==1)&&(P2_Get_ck==0))Mode=3;break;
case 1:Down;if(Down_ck==0){Grab;Mflag=1;}break; // 1
case 2:Up;if(Up_ck==0)Mode=4;break; // 2
case 3:Left;if(P2_ck==0){Stop;if(Grab_ck==0)Mode=1;}break;
case 4:Left;if(P3_ck==0){Stop;Lose;Mflag=1;}break; // 3
}
if(Mflag==1)
{
Mflag=0;
Mode++;
if(Mode>=5)
{
Mode=0;num=0;yxflag=0;ztflag=0;
}
}
}
}
}
void time()interrupt 1
{
TH0=0xf8;
TL0=0xcc;
DP();
key=keyscan();
}
void Init()
{
EA=1;
ET0=1;
TMOD=1;
TH0=0xf8;
TL0=0xcc;
TR0=1;
}
void DP()
{
PX=255;
DM=255;
DM=table[str[dp_h]];
PX=~(0x80>>dp_h);
dp_h++;
dp_h&=0x07;
}
uchar keyscan()
{
if((key0==0)||(key1==0)||(key2==0)||
(key3==0)||(key4==0)||(key6==0)||(key7==0))
{
k_time++;
if(k_time>10)
{
if(key0==0)return 0;
if(key1==0)return 1;
if(key2==0)return 2;
if(key3==0)return 3;
if(key4==0)return 4;
if(key6==0)return 6;
if(key7==0)return 7;
}else return 16;
}else k_time=0;
return 16;
}
void fuwei()
{
Up;
while(Up_ck==1);
Right;
while(P1_ck==1);
Stop;Lose;
Down;
}
此帖出自
小平头技术问答
一周热门 更多>