萌新半抄半改寫了一個程序但是出現了同一個語法錯誤(大霧)- 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
- {
復制代碼
感謝各位不吝賜教

|