程序是这样的,运行第一次正常,第二次没反应,第三次正常,第四次没反应..............循环
地下是测试结果,显示的是Food_Flag错误,当为1的时候是正确结果。
为什么同样的顺序,第二次的Food_Flag会等于0?
u8 Start_Flag=0;
u16 Start_counter=0;
u8 End_Flag=0; //舵机标志
u16 End_counter=0;
u8 Food_Flag=0; //物品标志
u8 Cross_Flag=0;
u8 Road_Flag=0;
u8 Cross_counter=0;
u32 counter=0;//定时器2计数变量
u32 RFIDdownAddress=0;
u32 RFIDupAddress=0;
extern u8 UART1_RX_BUF[64]; //上边的
extern u8 UART1_RX_STA;
extern u8 UART3_RX_BUF[64]; //下边的
extern u8 UART3_RX_STA;
void PositionProcess(void);
void FoodProcess(void);
u32 wave_counter=0;
void Start(void)
{
if( (ReadRFIDdownAddress())&&(Start_Flag==0)&& (End_Flag==0) )
{
printf("进入 if( (ReadRFIDdownAddress())&&(Start_Flag==0)&& (End_Flag==0) )
");
printf(" ReadRFIDdownAddress: 1
");
printf(" Start_Flag: %d
",Start_Flag);
printf(" End_Flag: %d
",End_Flag);
printf("进入PositionProcess()
");
PositionProcess();
printf(" Stop_Flag: %d
",Stop_Flag);
printf(" Start_Flag: %d
",Start_Flag);
printf(" End_Flag: %d
",End_Flag);
}
if((ReadRFIDupAddress())&&(Start_Flag==1)&&(Food_Flag==0) )
{
printf("进入 if((ReadRFIDupAddress())&&(Start_Flag==1)&&(Food_Flag==0) )
");
Stop_Flag=0;
Start_Flag=0;
printf(" ReadRFIDupAddress: 1
");
printf(" Start_Flag: %d
",Start_Flag);
printf(" Food_Flag: %d
",Food_Flag);
printf("进入FoodProcess()
");
FoodProcess();
printf(" ReadRFIDupAddress: 1
");
printf(" Start_Flag: %d
",Start_Flag);
printf(" Food_Flag: %d
",Food_Flag);
}
//printf("进入 if(End_Flag==1) //延时清除结束标志,避免二次检测
");
if(End_Flag==1) //延时清除结束标志,避免二次检测
{
//printf(" End_counter: %d
",End_counter);
End_counter++;
if(End_counter==50)
{
DuojiQinXie();
}
if (End_counter==150)
{
DuojiPing();
}
if (End_counter>=180)
{
End_Flag=0;
Food_Flag=0;
Stop_Flag=0;
End_counter=0;
printf("进入 Ultrasonic_start(),若小于50cm则右转
");
Ultrasonic_start();
if((int)distance<50)
{
TIM_CCxCmd(TIM3,TIM_Channel_1,TIM_CCx_Enable);//左轮转
TIM_CCxCmd(TIM3,TIM_Channel_2,TIM_CCx_Disable);//右轮不转
TIM_PrescalerConfig(TIM3,49,TIM_PSCReloadMode_Immediate);
delay_ms(4000);
TIM_CCxCmd(TIM3,TIM_Channel_2,TIM_CCx_Enable);
printf(" distance: %f
",distance);
}
printf(" End_Flag: %d
",End_Flag);
printf(" Food_Flag: %d
",Food_Flag);
printf(" Stop_Flag: %d
",Stop_Flag);
printf(" End_counter: %d
",End_counter);
}
}
if(Start_Flag==0&&End_Flag==0)
{
wave_counter++;
//printf("wave_counter: %d
",wave_counter);
if(wave_counter>10)
{
wave_counter=0;
Ultrasonic();
}
}
st188_control(ST188DATA);//直行st188控制
}
void PositionProcess(void)
{
switch(RFIDdownAddress)
{
case 0x1AA5D3AE:
case 0x0AF6D1AE: //检测到起始标签
if (Food_Flag==0)
{
LED2=0;
Stop_Flag=1;
Start_Flag=1;
}
break;
case 0xEAF3CFAE:
case 0xDADACDAE: //中间目标区1
if(Food_Flag==1)
{
LED2=1;
Stop_Flag=1;
End_Flag=1;
}
break;
case 0xFAC6C9AE: //中间目标区2
if(Food_Flag==2)
{
LED2=1;
Stop_Flag=1;
End_Flag=1;
}
break;
case 0x2A37D0AE: //中间目标区3
if(Food_Flag==3)
{
LED2=1;
Stop_Flag=1;
End_Flag=1;
}
break;
default:break;
}
}
void FoodProcess(void)
{printf(" 已经进入FoodProcess
");
switch(RFIDupAddress)
{
case 0xAAF5D1AE: Food_Flag=1; break;
case 0xEA37D0AE: Food_Flag=1; break;
case 0x4AC0CBAE: Food_Flag=1; break;
case 0x4AF5D1AE: Food_Flag=1; break; //水果类
case 0x8A37D0AE: Food_Flag=2; break;
case 0xAA04CAAE: Food_Flag=2; break;
case 0x3A05CAAE: Food_Flag=2; break;
case 0x0A05CAAE: Food_Flag=2; break; //主食类
case 0x0ADBCDAE: Food_Flag=3; break;
case 0xDA28CEAE: Food_Flag=3; break;
case 0x6A29CEAE: Food_Flag=3; break;
case 0x9A10CCAE: Food_Flag=3; break;
case 0x9AC1CBAE: Food_Flag=3; break; //肉类
default:break;
}
}
u8 ReadRFIDdownAddress(void)
{
if((UART3_RX_STA&0x80)==0x80)
{
RFIDdownAddress=UART3_RX_BUF[6]*256*256*256 + UART3_RX_BUF[7]*256*256 + UART3_RX_BUF[8]*256 + UART3_RX_BUF[9];
UART3_RX_STA=0;
return 1;
}
else return 0;
}
u8 ReadRFIDupAddress(void)
{
if((UART1_RX_STA&0x80)==0x80)
{
RFIDupAddress=UART1_RX_BUF[6]*256*256*256 + UART1_RX_BUF[7]*256*256 + UART1_RX_BUF[8]*256 + UART1_RX_BUF[9];
UART1_RX_STA=0;
return 1;
}
else return 0;
}
测试:
第一次,正确
进入 if( (ReadRFIDdownAddress())&&(Start_Flag==0)&& (End_Flag==0) )
ReadRFIDdownAddress: 1
Start_Flag: 0
End_Flag: 0
进入PositionProcess()
Stop_Flag: 1
Start_Flag: 1
End_Flag: 0
进入 if((ReadRFIDupAddress())&&(Start_Flag==1)&&(Food_Flag==0) )
ReadRFIDupAddress: 1
Start_Flag: 0
Food_Flag: 0
进入FoodProcess()
已经进入FoodProcess
ReadRFIDupAddress: 1
Start_Flag: 0
Food_Flag: 1
进入 if( (ReadRFIDdownAddress())&&(Start_Flag==0)&& (End_Flag==0) )
ReadRFIDdownAddress: 1
Start_Flag: 0
End_Flag: 0
进入PositionProcess()
Stop_Flag: 1
Start_Flag: 0
End_Flag: 1
进入 Ultrasonic_start(),若小于50cm则右转
distance: 123.589996
End_Flag: 0
Food_Flag: 0
Stop_Flag: 0
End_counter: 0
*********************************************************************************
第二次,错误
进入 if( (ReadRFIDdownAddress())&&(Start_Flag==0)&& (End_Flag==0) )
ReadRFIDdownAddress: 1
Start_Flag: 0
End_Flag: 0
进入PositionProcess()
Stop_Flag: 1
Start_Flag: 1
End_Flag: 0
进入 if((ReadRFIDupAddress())&&(Start_Flag==1)&&(Food_Flag==0) )
ReadRFIDupAddress: 1
Start_Flag: 0
Food_Flag: 0
进入FoodProcess()
已经进入FoodProcess
ReadRFIDupAddress: 1
Start_Flag: 0
Food_Flag: 0 //这里出错
进入 if( (ReadRFIDdownAddress())&&(Start_Flag==0)&& (End_Flag==0) )
ReadRFIDdownAddress: 1
Start_Flag: 0
End_Flag: 0
进入PositionProcess()
Stop_Flag: 0
Start_Flag: 0
End_Flag: 0
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
舵机连A9,RFID连A10,为什么两者会干扰呢?
一周热门 更多>