循迹小车吧 关注:192贴子:191
  • 1回复贴,共1

怎么让小车循迹啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊

只看楼主收藏回复

这是我的程序
#include <reg52.h>
typedef unsigned int uint;
typedef unsigned char uchar;
sbit p2_1 = P2^1; //左循迹
sbit p2_2 = P2^2; //中循迹
sbit p2_3 = P2^3; //右循迹
sbit p1_0 = P1^0; //电机驱动
sbit p1_1 = P1^1;
sbit p1_2 = P1^2;
sbit p1_3 = P1^3;
sbit pwm1 = P2^4;
sbit pwm2 = P2^5;
unsigned char timer1;
void Time1Config()
{ TMOD= 0x10;
TH1 = 0xFE;
TL1 = 0x0C;
ET1 = 1;
EA = 1;
TR1 = 1;
}
void DelayX1ms(uint count)
{ uint j;
while(count--!=0)
{
for(j=0;j<72;j++);
}
}
void ting()
{
p1_0=0;
p1_1=0;
p1_2=0;
p1_3=0;
}
void ZhiXing( )
{
p1_0=0;
p1_1=0;
p1_2=0;
p1_3=0;
DelayX1ms(10);
p1_0=0;
p1_1=1;
p1_2=0;
p1_3=1;
DelayX1ms(20);
}
void ZuoZhuan( )
{
pwm1=0;
pwm2=0;
DelayX1ms(10);
p1_0=0;
p1_1=0;
p1_2=0;
p1_3=1;
DelayX1ms(20);
}
void YouZhuan( )
{
pwm1=0;
pwm2=0;
DelayX1ms(10);
p1_0=0;
p1_1=1;
p1_2=0;
p1_3=0;
DelayX1ms(20);
}
void main( )
{
Time1Config();
while(1)
{
if( p2_1==1&&p2_2==0&&p2_3==0)
{
YouZhuan();
}
else if(p2_1==0&&p2_2==0&&p2_3==1)
{
ZuoZhuan;
}
else if(p2_1==0&&p2_2==0&&p2_3==0)
{
ting();
}
else
{
ZhiXing( );
}
}
}
void Time1() interrupt 3 //
{ timer1++;
if(timer1>100) //PWMÖÜÆÚΪ100*0.5ms
{
timer1=0;
}
if(timer1 < 85) //¸Ä±ä30Õâ¸öÖµ¿ÉÒԸıäÖ±Á÷µç»úµÄËÙ¶È
{
pwm1=1;
pwm2=1;
} else
{
pwm1=0;
pwm2=0;
}
TH1 = 0xFE; //ÖØи³³õÖµ
TL1 = 0x0C;
}
大神们,帮我看看这程序哪里有错啊


IP属地:重庆1楼2017-04-09 16:56回复
    我也在做循迹小车可以交流一下吗? 我扣扣 3049693534


    IP属地:江苏2楼2017-04-29 09:25
    回复