| #include<reg52.h> unsigned char zkbl;//左占空比 unsigned char zkbr;//右占空比 unsigned char pwm_t;//周期 sbit motor1_1=P0^0; sbit motor1_2=P0^1; sbit motor2_1=P0^2; sbit motor2_2=P0^3; sbit xj1=P0^4; sbit xj2=P0^5; void forward(); void left(); void right(); void main() { while(1) { if (xj1==0&&xj2==0) forward();//直行 else if (xj1==0&&xj2==1) left();//左轉(zhuǎn) else(xj1==1&&xj2==0) right();//右轉(zhuǎn) } } void forward() { motor1_1=1; motor1_2=0; motor2_1=1; motor2_2=0; } void left() { motor1_1=0; motor1_2=0; motor2_1=1; motor2_2=0; } void right() { motor1_1=1; motor1_2=0; motor2_1=0; motor2_2=0; } Killer Queen.c(25): error C141: syntax error near 'right' 沒(méi)看懂咋回事,,,, 一個(gè)還沒(méi)完成的小車程序,先把電機(jī)和循跡給試著寫(xiě)了寫(xiě) |
lyxing 發(fā)表于 2020-1-25 10:39
else(xj1==1&&xj2==0) 改為 else if (xj1==1&&xj2==0) 試試
hhggg 發(fā)表于 2020-1-25 12:14
else有條件判斷要加 if

lyxing 發(fā)表于 2020-1-25 14:49
Killer 設(shè)置問(wèn)題吧。output有一個(gè)建立HEX文件選項(xiàng)。打上勾。
| 歡迎光臨 (http://www.raoushi.com/bbs/) | Powered by Discuz! X3.1 |