帮我看一下这个程序有没有错?智能小车红外避障的,放在小车上运行的不对啊,也不知道是什么原因 20
#include<reg52.h>#defineuintunsignedint#defineucharunsignedcharsbitin1=P0^4;//右轮前进sbi...
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit in1=P0^4;//右轮前进
sbit in2=P0^5;//右轮后退
sbit in3=P0^6;//左轮后退
sbit in4=P0^7;//左轮前进
sbit lhw=P0^0;
sbit rhw=P0^1;
void delay(unsigned int xms)
{
unsigned int i,j;
for(i=xms;i>0;i--)
for(j=112;j>0;j--);
}
uchar in1_pwm;
uchar in2_pwm;
uchar in3_pwm;
uchar in4_pwm;
uchar time=0;
void go(void)//前进
{
in1_pwm=4;
in2_pwm=0;
in3_pwm=0;
in4_pwm=4;
}
void back(void)
{
in1_pwm=0;
in2_pwm=4;
in3_pwm=4;
in4_pwm=0;
}
void right(void)
{
in1_pwm=0;
in2_pwm=0;
in3_pwm=0;
in4_pwm=4;
}
void left(void)
{
in1_pwm=4;
in2_pwm=0;
in3_pwm=0;
in4_pwm=0;
}
void T1int(void)//定时器初始化
{
TMOD|=0x10;
TH1=0xfc;
TL1=0x18;
ET1=1;
TR1=1;
}
void T1_isr(void)interrupt 3
{
TR1=0;//关闭定时器1
TH1=0xfc;
TL1=0x18;
time++;
if(time>=10)
time=0;
if(time<=in1_pwm)
in1=1;
else in1=0;
if(time<=in2_pwm)
in2=1;
else in2=0;
if(time<=in3_pwm)
in3=1;
else in3=0;
if(time<=in4_pwm)
in4=1;
else in4=0;
TR1=1;//启动定时器
}
void main()
{
if(lhw==1&&rhw==1)
go();
if(rhw==0)
back();
delay(500);
left();
delay(500);
if(lhw==0)
back();
delay(500);
right();
delay(500);
} 展开
#define uint unsigned int
#define uchar unsigned char
sbit in1=P0^4;//右轮前进
sbit in2=P0^5;//右轮后退
sbit in3=P0^6;//左轮后退
sbit in4=P0^7;//左轮前进
sbit lhw=P0^0;
sbit rhw=P0^1;
void delay(unsigned int xms)
{
unsigned int i,j;
for(i=xms;i>0;i--)
for(j=112;j>0;j--);
}
uchar in1_pwm;
uchar in2_pwm;
uchar in3_pwm;
uchar in4_pwm;
uchar time=0;
void go(void)//前进
{
in1_pwm=4;
in2_pwm=0;
in3_pwm=0;
in4_pwm=4;
}
void back(void)
{
in1_pwm=0;
in2_pwm=4;
in3_pwm=4;
in4_pwm=0;
}
void right(void)
{
in1_pwm=0;
in2_pwm=0;
in3_pwm=0;
in4_pwm=4;
}
void left(void)
{
in1_pwm=4;
in2_pwm=0;
in3_pwm=0;
in4_pwm=0;
}
void T1int(void)//定时器初始化
{
TMOD|=0x10;
TH1=0xfc;
TL1=0x18;
ET1=1;
TR1=1;
}
void T1_isr(void)interrupt 3
{
TR1=0;//关闭定时器1
TH1=0xfc;
TL1=0x18;
time++;
if(time>=10)
time=0;
if(time<=in1_pwm)
in1=1;
else in1=0;
if(time<=in2_pwm)
in2=1;
else in2=0;
if(time<=in3_pwm)
in3=1;
else in3=0;
if(time<=in4_pwm)
in4=1;
else in4=0;
TR1=1;//启动定时器
}
void main()
{
if(lhw==1&&rhw==1)
go();
if(rhw==0)
back();
delay(500);
left();
delay(500);
if(lhw==0)
back();
delay(500);
right();
delay(500);
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询