/**************************************************************************** 硬件连接 ****************************************************************************/ #include<> #include<> #defineSevro_moto_pwmP2_7 //接舵机信号端输入PWM信号调节速度 #defineECHOP2_4 //超声波接口定义 #RIGP2_5 //超声波接口定义 #defineLeft_moto_go{P1_0=1,P1_1=0,P1_2=1,P1_3=0;}//左边两个电机向前走 #defineLeft_moto_back{P1_0=0,P1_1=1,P1_2=0,P1_3=1;} //左边两个电机向后转 #defineLeft_moto_Stop{P1_0=0,P1_1=0,P1_2=0,P1_3=0;}//左边两个电机停转 #defineRight_moto_go{P1_4=1,P1_5=0,P1_6=1,P1_7=0;} //右边两个电机向前走 #defineRight_moto_back{P1_4=0,P1_5=1,P1_6=0,P1_7=1;} //右边两个电机向前走 #defineRight_moto_Stop{P1_4=0,P1_5=0,P1_6=0,P1_7=0;} //右边两个电机停转 unsignedcharconstdiscode[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xBF,0xff/*-*/}; unsignedcharconstpositon[3]={0xfe,0xfd,0xfb}; unsignedchardisbuff[4] ={0,0,0,0,};unsignedcharposit=0; unsignedcharpwm_val_left=0;//变量定义 unsignedcharpush_val_left=14;//舵机归中,产生约,=0; unsignedlongS1=0; unsignedlongS2=0; unsignedlongS3=0; unsignedlongS4=0; unsignedinttime=0; //时间变量 unsignedinttimer=0; //延时基准变量 unsignedchartimer1=0; //扫描时间变量/************************************************************************/ voiddelay(unsignedintk) //延时函数{unsignedintx,y; for(x=0;x<k;x++) for(y=0;y<2000;y++);}/************************************************************************/voidDisplay(void) //扫描数码管 { if(posit==0) {P
超声波小车舵机转动避障 来自淘豆网www.taodocs.com转载请标明出处.