/**************************************************************************** Hardware connection **********************************************************************/ #include #include #define Sevro_moto_pwm P2_7 //Connect to the servo signal terminal to input PWM signal to adjust the speed#define ECHO P2_4 //Ultrasonic interface definition#define TRIG P2_5 //Ultrasonic interface definition#define Left_moto_go {P1_0=1,P1_1=0,P1_2=1,P1_3=0;} //The two motors on the left go forward#define Left_moto_back {P1_0=0,P1_1=1,P1_2=0,P1_3=1;} //The two motors on the left turn backward#define Left_moto_Stop {P1_0=0,P1_1=0,P1_2=0,P1_3=0;} //The two motors on the left stop#define Right_moto_go {P1_4=1,P1_5=0,P1_6=1,P1_7=0;} //The two motors on the right go forward#define Right_moto_back {P1_4=0,P1_5=1,P1_6=0,P1_7=1;} //The two motors on the right go forward#define Right_moto_Stop {P1_4=0,P1_5=0,P1_6=0,P1_7=0;} //The two motors on the right stopunsigned char const discode[] ={ 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xBF,0xff/*-*/}; unsigned char const positon[3]={ 0xfe,0xfd,0xfb}; unsigned char disbuff[4] ={ 0,0,0,0,}; unsigned char posit=0; unsigned char pwm_val_left = 0;//variable definition unsigned char push_val_left =14;//Servo returns to center, generating about 1.5MS signal unsigned long S=0; unsigned long S1=0; unsigned long S2=0; unsigned long S3=0; unsigned long S4=0; unsigned int time=0; //time variable unsigned int timer=0; //delay reference variable unsigned char timer1=0; //scan time variable/********************************************************************/ void delay(unsigned int k) //delay function { unsigned int x,y; for(x=0;x