#include
#include
#define LeftIR P1_2 //左边红外接收连接到P12
#define RightIR P1_3 //右边红外接收连接到P13
void Forward(int Velocity)
/* Velocity should be between 0 and 200 */
{

``````    P1_1=1;
delay_nus(1500+ Velocity);
P1_1=0;
P1_0=1;
delay_nus(1500- Velocity);
P1_0=0;
delay_nms(80);
``````

}
void Left()
/* Velocity should be between 0 and 200 */
{

``````    P1_1=1;
delay_nms(20);
P1_1=0;
P1_0=0;
P1_0=0;

delay_nus(1300);
``````

}
void Right()
/* Velocity should be between 0 and 200 */
{

``````    P1_1=0;
P1_1=0;
P1_0=1;
delay_nus(1300);
P1_0=0;
delay_nms(20);
``````

}
void Backward(int PulseCount,int Velocity)
/* Velocity should be between 0 and 200 */
{
int i;
for(i=1;i<= PulseCount;i++)
{
P1_1=1;
delay_nus(1500-Velocity);
P1_1=0;
P1_0=1;
delay_nus(1500+ Velocity);
P1_0=0;
delay_nms(20);
}
}
int main(void)
{

``````while(1)
{

uart_Init();
printf("Program Running!\n");

if&&(RightIR==0)&&(LeftIR==0))
{Forward(600);}                                                       //前进

if((RightIR==1)||(RightIR==))                                                //左weitiao
{
Left();
}

if((LeftIR==1)||(LeftIR==1))                                                      //右weitiao
{
Right();
}

}
``````

}

4个回答

91program 特别是类似于 P1_1 的变量，应该是与硬件相关的。想搞清楚，可能需要硬件原理图！