红外避障模块c语言程序,51单片机 超声波红外避障 程序

满意答案

02ae427d08e371d7e90d5b995e828d6d.png

69sjjeojo

2020.07.01

02ae427d08e371d7e90d5b995e828d6d.png

采纳率:58%    等级:9

已帮助:365人

这是一个超声波避障小车的源程序,可以参考下,用的89C52单片机,舵机控制转角避障。

#include

#include

#define Sevro_moto_pwm P2_7 //接舵机信号端输入PWM信号调节速度

#define ECHO P2_4 //超声波接口定义

#define TRIG P2_5 //超声波接口定义

#define Left_moto_go {P1_0=1,P1_1=0,P1_2=1,P1_3=0;} //左边两个电机向前走

#define Left_moto_back {P1_0=0,P1_1=1,P1_2=0,P1_3=1;} //左边两个电机向后转

#define Left_moto_Stop {P1_0=0,P1_1=0,P1_2=0,P1_3=0;} //左边两个电机停转

#define Right_moto_go {P1_4=1,P1_5=0,P1_6=1,P1_7=0;} //右边两个电机向前走

#define Right_moto_back {P1_4=0,P1_5=1,P1_6=0,P1_7=1;} //右边两个电机向前走

#define Right_moto_Stop {P1_4=0,P1_5=0,P1_6=0,P1_7=0;} //右边两个电机停转

unsigned char const discode[] ={ 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xBF,0xff/*-*/};

unsigned char const positon[3]={ 0xfe,0xfd,0xfb};

unsigned char disbuff[4] ={ 0,0,0,0,};

unsigned char posit=0;

unsigned char pwm_val_left = 0;//变量定义

unsigned char push_val_left =14;//舵机归中,产生约,1.5MS 信号

unsigned long S=0;

unsigned long S1=0;

unsigned long S2=0;

unsigned long S3=0;

unsigned long S4=0;

unsigned int time=0; //时间变量

unsigned int timer=0; //延时基准变量

unsigned char timer1=0; //扫描时间变量

/************************************************************************/

void delay(unsigned int k) //延时函数

{

unsigned int x,y;

for(x=0;x

for(y=0;y<2000;y++);

}

/************************************************************************/

void Display(void) //扫描数码管

{

if(posit==0)

{P0=(discode[disbuff[posit]])&0x7f;}//产生点

else

{P0=discode[disbuff[posit]];} if(posit==0)

{ P2_1=0;P2_2=1;P2_3=1;}

if(posit==1)

{P2_1=1;P2_2=0;P2_3=1;}

if(posit==2)

{P2_1=1;P2_2=1;P2_3=0;}

if(++posit>=3)

posit=0;

}

/************************************************************************/

void StartModule() //启动测距信号

{

TRIG=1;

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值