小车在下面 芯片AT89S52
这是我自己写的 求把加速减速停止写进去
#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();
}
}
}