1、 智能小车红外避障 c 语言程序 #include bit RandomFactor = 0 ; bit RandomFactorBuf = 0 ; #include #define FLeftMotor P0_2 = 1 ; P0_3 = 0 #define BLeftMotor P0_2 = 0 ; P0_3 = 1 #define FRightMotor P0_5 = 1 ; P0_4 = 0 #define BRightMotor P0_5 = 0 ; P0_4 = 1 #define LeftStop P0_2 = 0 ; P0_3 = 0 #define RightStop P0_
2、4 = 0 ; P0_5 = 0 #define CarStop P0_2 = 0 ; P0_3 = 0 ; P0_4 = 0 ; P0_5 = 0 #define RightSenser P0_0 #define LeftSenser P0_1 /* / 左转 /* void TurnLeft_1() LeftStop ; FRightMotor ; /* / 快速左转 /* void TurnLeft_Fast() BLeftMotor ; FRightMotor ; /* / 右转 /* void TurnRight_1() RightStop ; FLeftMotor ; /* / 快
3、速右转 /* void TurnRight_Fast() BRightMotor ; FLeftMotor ; /* / 用倒退的方式进行车头右转 /* void BTurnRight_1() LeftStop ; BRightMotor ; /* / 用倒退的方式进行车头左转 /* void BTurnLeft_1() RightStop ; BLeftMotor ; /* / 前进 /* void FCar() FLeftMotor ; FRightMotor ; /* / 后退 /* void BCar() BLeftMotor ; BRightMotor ; /* / 壁障程序 /*
4、void Obstacle_Avoid(void) if(RightSenser if(!RightSenser) if(RightSenser if(!(RightSenser | LeftSenser) RandomFactorBuf = RandomFactor ; while (!(RightSenser | LeftSenser) if(RandomFactorBuf) BTurnLeft_1() ; delay (300) ; if(!RandomFactorBuf) BTurnRight_1() ; delay (300) ; if(!PWM) LeftStop ; RightStop ; /* / 跟随程序 /* void Follow(void) if(RightSenser RightStop; if(!RightSenser) if(RightSenser if(!(RightSenser | LeftSenser) FCar() ; /* /* main() Timer0Setup(500) ; Timer1Setup(50) ; Obstacle_Avoid() ; / Follow() ;