标题:
单片机循迹小车程序编译错误,有大佬帮忙教教怎么改吗
[打印本页]
作者:
更都赤那
时间:
2020-5-2 16:01
标题:
单片机循迹小车程序编译错误,有大佬帮忙教教怎么改吗
51hei图片_20200502155701.png
(34.6 KB, 下载次数: 33)
下载附件
2020-5-2 15:57 上传
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar temp1,temp2,signal1,signal2;
void delay_1ms(uint d)
{
uint i;
while(d--)
for(i=0;i<75;i++);
}
void main0()
{
EA=1;
ET1=1;
TR1=1;
TMOD=0x01;
TH1=-(1000/256);
TL1=-(1000%256);
temp1=P0;
signal1=temp1&0xff;
if(signal1==0xff)
{
void motor_run() // ??????
{
P1=0x53;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
/* ENA=1;
OUT1=0;
OUT2=1;
delay_1ms(800);
OUT2=0;
delay_1ms(200);
ENB=1;
OUT4=0;
OUT3=1;
delay_1ms(800);
OUT3=0;
delay_1ms(200);
*/
}
void motor_left() //???
{
P1=0x50;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
void motor_right() //???
{
P1=0x03;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
void motor_big_right() //?????
{
P1=0x33;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
void motor_big_left() //?????
{
P1=0x55;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
void motor_stop() //?????
{
P1=0x00;
}
void motor_back() //???????
{
P1=0x35;
}
void main1()
{
EA=1;
ET1=1;
TR1=1;
TMOD=0x01;
TH1=-(1000/256);
TL1=-(1000%256);
while(1)
{
temp2=P2;
signal2=temp2&0xff; //????????????
switch(signal2)
{
case 0xff: //?????
motor_run();
break;
case 0xfb: //????
motor_left();
break;
case 0xfd: //???
case 0xf9:
motor_big_left();
break;
case 0xfe: //???????
case 0xfc:
motor_big_left();
delay_1ms(10);
break;
case 0xef: //????
motor_right();
break;
case 0xdf: //???
case 0xcf:
motor_big_right();
break;
case 0xbf: //???????
case 0x9f:
motor_big_right();
delay_1ms(10);
break;
case 0xc9: //?м??????????????????
case 0x88: //???д???????????????
motor_back();
delay_1ms(200);
motor_stop();
default:
break;
}
}
}
}
else
{
void motor_run1 () // ?????????
{
P1=0x35;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
/* ENA=1;
OUT1=1;
OUT2=0;
delay_1ms(800);
OUT2=1;
delay_1ms(200);
ENB=1;
OUT4=1;
OUT3=0;
delay_1ms(800);
OUT3=1;
delay_1ms(200);
*/
}
void motor_left1() //???
{
P1=0x30;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
void motor_right1() //???
{
P1=0x05;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
void motor_big_right1() //?????
{
P1=0x55;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
void motor_big_left1() //?????
{
P1=0x33;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
void motor_stop1() //?????
{
P1=0x00;
}
void motor_back1() //???????
{
P1=0x53;
}
void main2()
{
EA=1;
ET1=1;
TR1=1;
TMOD=0x01;
TH1=-(1000/256);
TL1=-(1000%256);
while(1)
{
temp2=P2;
signal2=temp2&0xff; //????????????
switch(signal2)
{
case 0xff: //?????
motor_run1();
break;
case 0xfb: //????
motor_left1();
break;
case 0xfd: //???
case 0xf9:
motor_big_left1();
break;
case 0xfe: //???????
case 0xfc:
motor_big_left1();
delay_1ms(10);
break;
case 0xef: //????
motor_right1();
break;
case 0xdf: //???
case 0xcf:
motor_big_right1();
break;
case 0xbf: //???????
case 0x9f:
motor_big_right1();
delay_1ms(10);
break;
case 0xc9: //?м??????????????????
case 0x88: //???д???????????????
motor_back1();
delay_1ms(200);
motor_stop1();
default:
break;
}
}
}
}
}
这几行显示语法错误,但是后面程序中有相同形式的语句,是正确的,这几个错误要怎么改,上面是完整的程序
作者:
xxpp2011
时间:
2020-5-2 19:55
主程序入口是main(),我不知道你的main0()/main1()/main2()哪个是入口
作者:
hantu
时间:
2020-5-3 13:49
你这代码乱来的,函数里套函数了,估计是搞错了
作者:
angmall
时间:
2020-5-3 16:52
函数里套函数了
自始至终错误百出!!!楼主看的是什么书?
你所能理解的方式都是最笨最糟糕的方法。
先学理论,打基础,否则,问题多多,事倍功半。
作者:
幻剑心
时间:
2020-5-3 17:51
先把void motor_run()拉到main0()外面去.
作者:
angmall
时间:
2020-5-3 22:46
给你改了,对比一下就知道哪里错了。
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar temp1,temp2,signal1,signal2;
void delay_1ms(uint d)
{
uint i;
while(d--)
for(i=0;i<75;i++);
}
void motor_run() // ??????
{
P1=0x53;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
/* ENA=1;
OUT1=0;
OUT2=1;
delay_1ms(800);
OUT2=0;
delay_1ms(200);
ENB=1;
OUT4=0;
OUT3=1;
delay_1ms(800);
OUT3=0;
delay_1ms(200);
*/
}
void motor_left() //???
{
P1=0x50;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
void motor_right() //???
{
P1=0x03;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
void motor_big_right() //?????
{
P1=0x33;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
void motor_big_left() //?????
{
P1=0x55;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
void motor_stop() //?????
{
P1=0x00;
}
void motor_back() //???????
{
P1=0x35;
}
void motor_run1 () // ?????????
{
P1=0x35;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
/* ENA=1;
OUT1=1;
OUT2=0;
delay_1ms(800);
OUT2=1;
delay_1ms(200);
ENB=1;
OUT4=1;
OUT3=0;
delay_1ms(800);
OUT3=1;
delay_1ms(200);
*/
}
void motor_left1() //???
{
P1=0x30;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
void motor_right1() //???
{
P1=0x05;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
void motor_big_right1() //?????
{
P1=0x55;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
void motor_big_left1() //?????
{
P1=0x33;
delay_1ms(150);
P1=0x00;
delay_1ms(20);
}
void motor_stop1() //?????
{
P1=0x00;
}
void motor_back1() //???????
{
P1=0x53;
}
void main()
{
EA=1;
ET1=1;
TR1=1;
TMOD=0x01;
TH1=-(1000/256);
TL1=-(1000%256);
//EA=1;
//ET1=1;
//TR1=1;
//TMOD=0x01;
//TH1=-(1000/256);
//TL1=-(1000%256);
//EA=1;
//ET1=1;
//TR1=1;
//TMOD=0x01;
//TH1=-(1000/256);
//TL1=-(1000%256);
while(1)
{
temp1=P0;
signal1=temp1&0xff;
if(signal1==0xff)
{
//while(1)
{
temp2=P2;
signal2=temp2&0xff; //????????????
switch(signal2)
{
case 0xff: //?????
motor_run1();
break;
case 0xfb: //????
motor_left1();
break;
case 0xfd: //???
case 0xf9:
motor_big_left1();
break;
case 0xfe: //???????
case 0xfc:
motor_big_left1();
delay_1ms(10);
break;
case 0xef: //????
motor_right1();
break;
case 0xdf: //???
case 0xcf:
motor_big_right1();
break;
case 0xbf: //???????
case 0x9f:
motor_big_right1();
delay_1ms(10);
break;
case 0xc9: //?м??????????????????
case 0x88: //???д???????????????
motor_back1();
delay_1ms(200);
motor_stop1();
default:
break;
}
}
}
else
{
//while(1)
{
temp2=P2;
signal2=temp2&0xff; //????????????
switch(signal2)
{
case 0xff: //?????
motor_run();
break;
case 0xfb: //????
motor_left();
break;
case 0xfd: //???
case 0xf9:
motor_big_left();
break;
case 0xfe: //???????
case 0xfc:
motor_big_left();
delay_1ms(10);
break;
case 0xef: //????
motor_right();
break;
case 0xdf: //???
case 0xcf:
motor_big_right();
break;
case 0xbf: //???????
case 0x9f:
motor_big_right();
delay_1ms(10);
break;
case 0xc9: //?м??????????????????
case 0x88: //???д???????????????
motor_back();
delay_1ms(200);
motor_stop();
default:
break;
}
}
}
}
}
//void main1()
//{
//}
//void main0()
//{
//}
复制代码
作者:
hantu
时间:
2020-5-3 23:45
估计是抄错代码了
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1