微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > 关于循迹小车自己所编程序的一些困惑

关于循迹小车自己所编程序的一些困惑

时间:10-02 整理:3721RD 点击:
在keil 中运行老是报错,根据底下的提示找到错误地,但还是有些无法改正,求大神指导
#include<reg52.h>
sbit PWM1=P1^0;
sbit PWM2=P1^4;
sbit IN1=P1^1;
sbit IN2=P1^2;
sbit IN3=P1^5;
sbit IN4=P1^6;
sbit RP1=P2^0;
sbit RP2=P2^1;
sbit RP3=P2^2;
sbit RP4=P2^3;
sbit RP5=P2^4;
sbit RP6=P2^5;
sbit RP7=P2^6;
sbit RP8=P2^7;
int count1,count2;
void delay(int z)
{
int x,y;
for(x=z;x>0;x--);
for(y=124;y>0;y--);
}
void foward1()
{
IN1=1;
IN2=0;
}
void forward2()
{
IN3=1;
IN4=0;
}
void back1()
{
IN1=0;
IN2=1;
}
void back2()
{
IN3=0;
IN4=1;
}
void speed(int cnt1,int sd1,int cnt2,int sd2)
{
if(cnt1<sd1)
{
PWM1=1
;  }
else
{
PWM1=0;
}
if(cnt2<sd2)
  {
PWM2=1
;
}
else
{
PWM2=0;
  }
}
void turn(int cnt1,int sd1,int cnt2,int sd2)
{
forward1();
forward2();
speed(cnt1,sd1,cnt2,sd2)
}
void back(int cnt1,int sd1,int cnt2,int sd2)
{
back1();
back2();
speed(cnt1,sd1,cnt2,sd2);
}
void main()
{
int num=0;
TMOD=0x01;
EA=1;
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
ET0=1;
TR0=1;
turn(count1,250,count2,250);
delay(350);
}
while(1)
{
if(RP1==1&&RP2==1&&RP3==1&&RP4==1&&RP5==1&&RP6==1&&RP7==1&&RP8==1)
back(count1,50,count2,50);
if(RP1==1&&RP2==1&&RP3==1&&RP4==0&&RP5==0&&RP6==1&&RP7==1&&RP8==1)
turn(count1,200,count2,200);
if(RP1==1&&RP2==1&&RP3==0&&RP4==0&&RP5==0&&RP6==1&&RP7==1&&RP8==1)
turn(count1,100,count2,150);
if(RP1==1&&RP2==0&&RP3==0&&RP4==0&&RP5==0&&RP6==1&&RP7==1&&RP8==1)
turn(count1,60,count2,150);
if(RP1==0&&RP2==0&&RP3==0&&RP4==0&&RP5==0&&RP6==1&&RP7==1&&RP8==1)
turn(count1,20,count2,150);
if(RP1==1&&RP2==1&&RP3==1&&RP4==0&&RP5==0&&RP6==0&&RP7==1&&RP8==1)
turn(count1,150,count2,100);
if(RP1==1&&RP2==1&&RP3==1&&RP4==0&&RP5==0&&RP6==0&&RP7==0&&RP8==1)
turn(count1,150,count2,60);
if(RP1==1&&RP2==1&&RP3==1&&RP4==0&&RP5==0&&RP6==0&&RP7==0&&RP8==0)
turn(count1,150,count2,20);
if(RP1==0&&RP2==0&&RP3==0&&RP4==0&&RP5==0&&RP6==0&&RP7==0&&RP8==0)
{
if(num==0)
{
back1();
forward2();
delay(100);
}
if(num>0&&num<3)
{
turn(count1,150,count,150);
}
if(num>=3)
{
PWM1=0;
PWM2=0;
}
num++;
}
}
void time0()interrupt 1
{
TH0=(65536-1000)/256;
TL0=(65536-1000)/256;
count1++;
count2++;
if(count1>=500)
count1=0;
if(count2>=500)
count2=0;
}

#include<reg52.h>
sbit PWM1=P1^0;
sbit PWM2=P1^4;
sbit IN1=P1^1;
sbit IN2=P1^2;
sbit IN3=P1^5;
sbit IN4=P1^6;
sbit RP1=P2^0;
sbit RP2=P2^1;
sbit RP3=P2^2;
sbit RP4=P2^3;
sbit RP5=P2^4;
sbit RP6=P2^5;
sbit RP7=P2^6;
sbit RP8=P2^7;
int count1,count2;
void delay(int z)
{
int x,y;
for(x=z;x>0;x--);
for(y=124;y>0;y--);
}
void forward1()
{
IN1=1;
IN2=0;
}
void forward2()
{
IN3=1;
IN4=0;
}
void back1()
{
IN1=0;
IN2=1;
}
void back2()
{
IN3=0;
IN4=1;
}
void speed(int cnt1,int sd1,int cnt2,int sd2)
{
if(cnt1<sd1)
{
PWM1=1
;  }
else
{
PWM1=0;
}
if(cnt2<sd2)
  {
PWM2=1
;
}
else
{
PWM2=0;
  }
}
void turn(int cnt1,int sd1,int cnt2,int sd2)
{
forward1();
forward2();
speed(cnt1,sd1,cnt2,sd2);
}
void back(int cnt1,int sd1,int cnt2,int sd2)
{
back1();
back2();
speed(cnt1,sd1,cnt2,sd2);
}
void main()
{
int num=0;
TMOD=0x01;
EA=1;
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
ET0=1;
TR0=1;
turn(count1,250,count2,250);
delay(350);
while(1)
{
if(RP1==1&&RP2==1&&RP3==1&&RP4==1&&RP5==1&&RP6==1&&RP7==1&&RP8==1)
back(count1,50,count2,50);
if(RP1==1&&RP2==1&&RP3==1&&RP4==0&&RP5==0&&RP6==1&&RP7==1&&RP8==1)
turn(count1,200,count2,200);
if(RP1==1&&RP2==1&&RP3==0&&RP4==0&&RP5==0&&RP6==1&&RP7==1&&RP8==1)
turn(count1,100,count2,150);
if(RP1==1&&RP2==0&&RP3==0&&RP4==0&&RP5==0&&RP6==1&&RP7==1&&RP8==1)
turn(count1,60,count2,150);
if(RP1==0&&RP2==0&&RP3==0&&RP4==0&&RP5==0&&RP6==1&&RP7==1&&RP8==1)
turn(count1,20,count2,150);
if(RP1==1&&RP2==1&&RP3==1&&RP4==0&&RP5==0&&RP6==0&&RP7==1&&RP8==1)
turn(count1,150,count2,100);
if(RP1==1&&RP2==1&&RP3==1&&RP4==0&&RP5==0&&RP6==0&&RP7==0&&RP8==1)
turn(count1,150,count2,60);
if(RP1==1&&RP2==1&&RP3==1&&RP4==0&&RP5==0&&RP6==0&&RP7==0&&RP8==0)
turn(count1,150,count2,20);
if(RP1==0&&RP2==0&&RP3==0&&RP4==0&&RP5==0&&RP6==0&&RP7==0&&RP8==0)
{
if(num==0)
{
back1();
forward2();
delay(100);
}
if((num>0)&&(num<3))
{
  turn(count1,150,count2,150);
}
if(num>=3)
{
PWM1=0;
PWM2=0;
}
num++;
}
}
}
void time0()interrupt 1
{
TH0=(65536-1000)/256;
TL0=(65536-1000)/256;
count1++;
count2++;
if(count1>=500)
count1=0;
if(count2>=500)
count2=0;
}

好了!

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top