求救,。。循跡小車程序有錯誤,
大家好,今天謝了一塊智能車的循跡程序,不知道哪里有錯,不能編成hex文件,總是有錯,今天找了一天也沒有發(fā)現(xiàn),大蝦們給指點一下唄,,,
/*****************************************************************
??硬件連接
??P16 接驅動模塊ENA 使能端,輸入PWM信號調節(jié)速度
? ???P17 接驅動模塊ENB 使能端,輸入PWM信號調節(jié)速度
??P14 接蜂鳴器
??P15 接避障管
? ???P34 P35 接IN1??IN2? ?
??P36 P37 接IN3??IN4
??當 P34=1,P35=0; 時左電機正轉??
? ???當 P34=0,P35=1; 時左電機反轉? ?? ?? ?? ?? ?
? ???當 P36=1,P3_7=0; 時右電機正轉
? ???當 P36=0,P37=1; 時右電機反轉
? ???P10接OUT1
? ???P11接OUT2
? ???P12接OUT3
??P13接OUT4
??四路尋跡傳感器有信號(白線)為0??沒有信號(黑線)為1
? ?? ?? ?? ?? ?? ?? ?? ?
??
****************************************************************************/
#include
#define uint unsigned int
#define uchar unsigned char
#define Left_pwm? ???P1^6? ? //接驅動模塊ENA 使能端,輸入PWM信號調節(jié)速度
#define Right_pwm? ? P1^7? ? //接驅動模塊ENB
? ? #define Left1_led? ?? ???P1^0? ? //四路尋跡模塊接口第一路
#define Left2_led? ?? ???P1^1? ? //四路尋跡模塊接口第二路
? ? #define Right1_led? ?? ? P1^2? ? //四路尋跡模塊接口第三路
#define Right2_led? ?? ? P1^3? ? //四路尋跡模塊接口第四路
#define BELL? ?? ?? ?? ? P1^4
#define BIZHANG? ?? ?? ? P1^5
#define Left_go? ?? ?{P3^4=0,P3^5=1;} //P3_4 P3_5 接IN1??IN2? ? 當 P3_4=0,P3_5=1; 時左電機前進
#define Left_back? ? {P3^4=1,P3^5=0;} //P3_4 P3_5 接IN1??IN2? ? 當 P3_4=1,P3_5=0; 時左電機后退? ?
#define Left_stop? ???{P3^4=1,P3^5=1;} //P3_4 P3_5 接IN1??IN2? ? 當 P3_4=1,P3_5=1; 時左電機停轉? ?? ?? ?? ?? ?
#define Right_go? ???{P3^6=0,P3^7=1;} //P3_6 P3_7 接IN1??IN2??當 P3_6=0,P3_7=1; 時右電機前轉
#define Right_back? ?{P3^6=1,P3^7=0;} //P3_6 P3_7 接IN1??IN2??當 P3_6=1,P3_7=0; 時右電機后退
? ? #define Right_stop? ? {P3^6=1,P3^7=1;} //P3_6 P3_7 接IN1??IN2??當 P3_6=1,P3_7=0; 時右電機停轉
? ? uchar pwm_val_left??=0;//變量定義
uchar push_val_left =0;// 左電機占空比N/10
uchar pwm_val_right =0;
uchar push_val_right=0;// 右電機占空比N/10
sbit Right_stop=1;
sbit Left_stop =1;
uint??time=0;
/************************************************************************/
??void delay(uint k)? ? //延時函數(shù)10
{? ?
? ???uint x,y;
??for(x=0;x? ? for(y=0;y<1648;y++);
}
/************************************************************************/
??void delay1ms(uint del)? ? //延時函數(shù)1ms
{? ?
? ???uint i,j;
??for(i=0;i? ? for(j=0;j<148;j++);
}
/************************************************************************/
? ???void??run(void) //前進函數(shù)
{
? ???push_val_left??=5;??//PWM 調節(jié)參數(shù)1-10? ?1為最慢,10是最快??改這個值可以改變其速度
??push_val_right =5;??//PWM 調節(jié)參數(shù)1-10? ?1為最慢,10是最快??改這個值可以改變其速度
??Left_go =1;? ?//左電機前進
??Right_go =1;??//右電機前進
}
/************************************************************************/
? ???void??left(void) //左轉函數(shù)
{
? ???push_val_left??=4;??//PWM 調節(jié)參數(shù)1-10? ?1為最慢,10是最快??改這個值可以改變其速度
??push_val_right =4;??//PWM 調節(jié)參數(shù)1-10? ?1為最慢,10是最快??改這個值可以改變其速度
??Right_go=1;??//右電機繼續(xù)
??Left_stop=1;? ?//左電機停走
}
/************************************************************************/
? ???void??right(void) //右轉函數(shù)
{
? ???push_val_left??=4;??//PWM 調節(jié)參數(shù)1-10? ?1為最慢,10是最快??改這個值可以改變其速度
??push_val_right =4;??//PWM 調節(jié)參數(shù)1-10? ?1為最慢,10是最快??改這個值可以改變其速度
??Right_stop=1;??//右電機停走
??Left_go=1;??//左電機繼續(xù)
}
/*************************************************************************/
void??BELL0(void)? ?//蜂鳴器報警0函數(shù)
{
while(1)
{
BELL=0;
delay(10);
BELL=1;
delay(10);
}
}
/*************************************************************************/
void??BELL1(void)? ?//蜂鳴器特殊報警函數(shù)
{
while(1)
{
BELL=0;
delay(1);
BELL=1;
delay(1);
}
}
/************************************************************************/
/*? ?? ?? ?? ?? ?? ???PWM調制電機轉速? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???*/
/************************************************************************/
/*? ?? ?? ?? ?? ?? ???左電機調速? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? */
/*調節(jié)push_val_left的值改變電機轉速,占空比? ?? ?? ?? ?*/
??void pwm_out_left(void)
{??
? ?if(Left_stop==1)
? ?{
? ? if(pwm_val_left<=push_val_left)
? ?? ???Left_pwm=1;
else
? ?? ???Left_pwm=0;
if(pwm_val_left>=10)
pwm_val_left=0;
? ?}
? ?else??Left_pwm=0;
}
/******************************************************************/
/*? ?? ?? ?? ?? ?? ???右電機調速? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? */??
? ?void pwm_out_right(void)
{
??if(Right_stop==1)
? ?{
? ? if(pwm_val_right<=push_val_right)
? ?? ???Right_pwm=1;
else
? ?? ???Right_pwm=0;
if(pwm_val_right>=10)
pwm_val_right=0;
? ?}
? ?else? ? Right_pwm=0;
}
/***************************************************/
///*TIMER0中斷服務子函數(shù)產(chǎn)生PWM信號*/
??void timer0()interrupt 1? ?using 2
{
? ???TH0=0XF8;? ?//1Ms定時
??TL0=0X30;
??time++;
??pwm_val_left++;
??pwm_val_right++;
??pwm_out_left();
??pwm_out_right();
}
/***************************************************/
void main(void)
{
TMOD=0X01;
TH0= 0XF8;? ? //1ms定時
??TL0= 0X30;
TR0= 1;
ET0= 1;
EA = 1;
while(BIZHANG&0x10)? ?? ?
{
? ???//四路尋跡傳感器有信號(白線)為0??沒有信號(黑線)為1
? ???switch(P1&0x0f)
{
??case 0x00:? ?? ?// 全部沒有壓線,直轉
? ?run();
? ?break;
??case 0x01:? ?? ?// 右壓線,報警,左轉
? ?BELL0();
? ? Left2_led=0;
? ?left();
? ?break;
??case 0x02:? ?? ?// 右壓線,報警,左轉
? ?BELL0();
? ? Left1_led=0;
? ?? ?left();
? ?delay(30);? ???//轉向延時
? ?break;
??case 0x04:? ?? ?// 左壓線,報警? ? ,右轉
? ?BELL0();
? ? Right1_led=0;??
? ?? ?? ?right();
? ?delay(30);? ???//轉向延時
? ?break;
??case 0x08:? ?? ?// 左壓線,報警,右轉
? ?BELL0();
? ? Right2_led=0;? ???
? ?right();? ???
? ?break;
??default
? ?BELL1();? ?? ?? ?? ?? ?? ?? ?//蜂鳴器報警1信號
? ?}
??}
}
上面是寫的程序,下面是錯誤。。
compiling 終極小車.c...
終極小車.C(49): error C141: syntax error near '{', expected ''
終極小車.C(49): error C141: syntax error near '=', expected ';'
終極小車.C(50): error C141: syntax error near '=', expected ';'
終極小車.C(72): error C141: syntax error near '='
終極小車.C(72): error C141: syntax error near '='
終極小車.C(72): error C141: syntax error near '='
終極小車.C(73): error C141: syntax error near '='
終極小車.C(73): error C141: syntax error near '='
終極小車.C(73): error C141: syntax error near '='
終極小車.C(81): error C141: syntax error near '='
終極小車.C(81): error C141: syntax error near '='
終極小車.C(81): error C141: syntax error near '='
終極小車.C(82): error C141: syntax error near '='
終極小車.C(82): error C141: syntax error near '='
終極小車.C(82): error C141: syntax error near '='
終極小車.C(89): error C141: syntax error near '='
終極小車.C(89): error C141: syntax error near '='
終極小車.C(89): error C141: syntax error near '='
終極小車.C(90): error C141: syntax error near '='
終極小車.C(90): error C141: syntax error near '='
終極小車.C(90): error C141: syntax error near '='
終極小車.C(98): error C141: syntax error near '='
終極小車.C(100): error C141: syntax error near '='
終極小車.C(110): error C141: syntax error near '='
終極小車.C(112): error C141: syntax error near '='
終極小車.C(123): error C141: syntax error near '{'
終極小車.C(126): error C141: syntax error near '='
終極小車.C(127): error C141: syntax error near 'else'
終極小車.C(128): error C141: syntax error near '='
終極小車.C(132): error C141: syntax error near '='
終極小車.C(138): error C141: syntax error near '{'
終極小車.C(141): error C141: syntax error near '='
終極小車.C(142): error C141: syntax error near 'else'
終極小車.C(143): error C141: syntax error near '='
終極小車.C(147): error C141: syntax error near '='
終極小車.C(185): error C141: syntax error near '='
終極小車.C(190): error C141: syntax error near '='
終極小車.C(196): error C141: syntax error near '='
終極小車.C(202): error C141: syntax error near '='
終極小車.C(206): error C141: syntax error near 'BELL1', expected ':'
Target not created
請大蝦們幫忙啊。。。。。。。
提問者:Shype
地點:-
瀏覽次數(shù):9826
提問時間:10-17 00:15
我有更好的答案