萌新半抄半改写了一个程序但是出现了同一个语法错误(大雾)- compiling wuluchaoshengbo.c...
- wuluchaoshengbo.c(205): error C141: syntax error near '=', expected ';'
- wuluchaoshengbo.c(209): error C141: syntax error near '=', expected ';'
- wuluchaoshengbo.c(216): error C141: syntax error near '=', expected ';'
- wuluchaoshengbo.c(228): error C141: syntax error near '=', expected ';
复制代码
放眼望去全是错误,头发都要掉完了,涂涂改改
希望有好心人指点下错误,帮助下小娃娃
- #include <STC12C5A60S2.h
- #include <intrins.h>
- #define RX1 P3^6 //小车左侧超声波HC-SR04接收端
- #define TX1 P1^7 //发送端
- #define RX2 P3^3 //左前方超声波
- #define TX2 P0^2
- #define RX3 P2^4 //正前方超声波
- #define TX3 P2^5
- #define RX4 P3^5 //右前方超声波
- #define TX4 P3^4
- #define RX5 P3^7 //右侧超声波
- #define TX5 P1^6
- #define Left_moto_pwm P1^5 //PWM信号端
- #define Right_moto_pwm P1^4 //PWM信号端
- //定义小车驱动模块输入IO口
- sbit IN1=P1^0;
- sbit IN2=P1^1;
- sbit IN3=P1^2;
- sbit IN4=P1^3;
- sbit EN1=P1^4;
- sbit EN2=P1^5;
- bit Right_moto_stop=1;
- bit Left_moto_stop =1;
- #define Left_moto_go {IN1=0,IN2=1,EN1=1;} //左电机向前走
- #define Left_moto_back {IN1=1,IN2=0,EN1=1;} //左边电机向后走
- #define Left_moto_Stop {EN1=0;} //左边电机停转
- #define Right_moto_go {IN3=1,IN4=0,EN2=1;} //右边电机向前走
- #define Right_moto_back {IN3=0,IN4=1,EN2=1;} //右边电机向后走
- #define Right_moto_Stop {EN2=0;} //右边电机停转
- unsigned char pwm_val_left =0;//变量定义
- unsigned char push_val_left =0;// 左电机占空比N/20
- unsigned char pwm_val_right =0;
- unsigned char push_val_right=0;// 右电机占空比N/20
- unsigned int time=0;
- unsigned int timer=0;
- unsigned long S1=0;
- unsigned long S2=0;
- unsigned long S3=0;
- unsigned long S4=0;
- unsigned long S5=0;
- void delay_1ms(unsigned char x) //1ms延时函数,100ms以内可用
- {
- unsigned char i;
- while(x--)
- for(i=124;i>0;i--);
- }
- /********************************************************/
- void Count1() //计算左侧超声波距离的函数
- {
- while(!RX1); //当RX1为零时等待
- TR0=1; //开启计数
- while(RX1); //当RX1为1计数并等待
- TR0=0; //关闭计数
- time=TH0*256+TL0;
- TH0=0;
- TL0=0;
- S1=(time*1.7)/100; //算出来是CM
- }
- void Count2() //计算函数
- {
- while(!RX2); //当RX2为零时等待
- TR0=1; //开启计数
- while(RX2); //当RX2为1计数并等待
- TR0=0; //关闭计数
- time=TH0*256+TL0;
- TH0=0;
- TL0=0;
- S2=(time*1.7)/100; //算出来是CM
- }
- void Count3() //计算函数
- {
- while(!RX3); //当RX3为零时等待
- TR0=1; //开启计数
- while(RX3); //当RX3为1计数并等待
- TR0=0; //关闭计数
- time=TH0*256+TL0;
- TH0=0;
- TL0=0;
- S3=(time*1.7)/100; //算出来是CM
- }
- void Count4() //计算函数
- {
- while(!RX4); //当RX4为零时等待
- TR0=1; //开启计数
- while(RX4); //当RX4为1计数并等待
- TR0=0; //关闭计数
- time=TH0*256+TL0;
- TH0=0;
- TL0=0;
- S4=(time*1.7)/100; //算出来是CM
- }
- void Count5() //计算函数
- {
- while(!RX5); //当RX5为零时等待
- TR0=1; //开启计数
- while(RX5); //当RX5为1计数并等待
- TR0=0; //关闭计数
- time=TH0*256+TL0;
- TH0=0;
- TL0=0;
- S5=(time*1.7)/100; //算出来是CM
- }
- /************************************************************************/
- //前进
- void run(void)
- {
- push_val_left=8; //左电机调速,速度调节变量 0-20。。。0最小,20最大,四驱大轮>6
- push_val_right=8; //右电机调速
- Left_moto_go ; //左电机往前走
- Right_moto_go ; //右电机往前走
- }
- /************************************************************************/
- //后退
- void backrun(void)
- {
- push_val_left=20;
- push_val_right=20;
- Left_moto_back ; //左电机往前走
- Right_moto_back ; //右电机往前走
- }
- /************************************************************************/
- //左转
- void leftrun(void)
- {
- push_val_left=20;
- push_val_right=20;
- Left_moto_back ; //左电机往后走
- Right_moto_go ; //右电机往前走
- }
- /************************************************************************/
- //右转
- void rightrun(void)
- {
- push_val_left=20;
- push_val_right=20;
- Left_moto_go ; //左电机往前走
- Right_moto_back ; //右电机往后走
- }
- /************************************************************************/
- //停止
- void stoprun(void)
- {
- Left_moto_Stop ; //左电机停
- Right_moto_Stop ; //右电机停
- }
- /************************************************************************/
- /* PWM调制电机转速 */
- /************************************************************************/
- /* 左电机调速 */
- /*调节push_val_left的值改变电机转速,占空比 */
- void pwm_out_left_moto(void)
- {
- if(Left_moto_stop)
- {
- if(pwm_val_left<=push_val_left)
- {
- Left_moto_pwm=1;
- }
- else
- {
- Left_moto_pwm=0;
- }
- if(pwm_val_left>=20)
- pwm_val_left=0;
- }
- else
- {
- Left_moto_pwm=0;
- }
- }
- /******************************************************************/
- /* 右电机调速 */
- void pwm_out_right_moto(void)
- {
- if(Right_moto_stop)
- {
- if(pwm_val_right<=push_val_right)
- {
- Right_moto_pwm=1;
- }
- else
- {
- Right_moto_pwm=0;
- }
- if(pwm_val_right>=20)
- pwm_val_right=0;
- }
- else
- {
- Right_moto_pwm=0;
- }
- }
- /********************************************************/
- void timer0() interrupt 1 //T0中断
- {
- }
- /***************************************************/
- ///*TIMER1中断服务子函数产生PWM信号*/
- void timer1()interrupt 3
- {
- TH1=(65536-1000)/256; //1ms定时
- TL1=(65536-1000)%256;
- timer++;
- pwm_val_left++;
- pwm_val_right++;
- pwm_out_left_moto();
- pwm_out_right_moto();
- }
- /*********************************************************
- **********************************************************/
- void main(void)
- {
- TMOD=0x11; //设T0为方式1,GATE=1;
- TH0=0;
- TL0=0;
- TH1=(65536-1000)/256; //1ms定时
- TL1=(65536-1000)%256;
- ET0=1; //允许T0中断
- ET1=1; //允许T1中断
- TR1=1; //开启定时器
- EA=1; //开启总中断
- while(1)
- {
- TX1=1; //开启超声波1探测
- delay_1ms(1);
- TX1=0;
- Count1(); //测距
- TX2=1;
- delay_1ms(1);
- TX2=0;
- Count2();
- TX3=1;
- delay_1ms(1);
- TX3=0;
- Count3();
- TX4=1;
- delay_1ms(1);
- TX4=0;
- Count4();
- TX5=1;
- delay_1ms(1);
- TX5=0;
- Count5();
- if(S3<20 && S1<20 && S5<20) //进入狭窄通道
- {
- backrun(); //倒车
- delay_1ms(100);
- }
- else if(S3<20 && S1<S5 ) //车子与障碍物90度垂直,左边距离小右转
- {
- rightrun();
- }
- else if(S3<20 && S5<S1 ) //车子与障碍物90度垂直,右边距离小左转
- {
- leftrun();
- }
- else if(S2<20)
- {
- rightrun(); //车与障碍物呈45度角时,车的左边比车的右边距离小,右转
- }
- else if(S4<20)
- {
- leftrun(); //车与障碍物呈45度角时,车的右边比车的左边距离小,左转
- }
- else
- {
- run();
- }
- }
- }
复制代码 错误的位置指向这里,一个部分错误用@标记
- void pwm_out_left_moto(void)
- {
- if(Left_moto_stop)
- {
- if(pwm_val_left<=push_val_left)
- {
- @ Left_moto_pwm=1;
- }
- else
- {
复制代码
感谢各位不吝赐教

|