最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 正文

超声波避障小车c语言程序

来源:动视网 责编:小OO 时间:2025-10-05 03:56:46
文档

超声波避障小车c语言程序

#include#defineucharunsignedchar#defineuintunsignedint#includeunsignedcharly_dis[4];//定义显示缓冲区sbitlcd_rs_port=P2^6;/*定义LCD控制端口*/sbitlcd_rw_port=P2^5;sbitlcd_en_port=P2^7;sbitRX=P3^6;//回响信号sbitTX=P3^7;//触发信号sbith=P2^4;sbitz_1=P2^0;//警报继电器发出sbitz_2=P2^
推荐度:
导读#include#defineucharunsignedchar#defineuintunsignedint#includeunsignedcharly_dis[4];//定义显示缓冲区sbitlcd_rs_port=P2^6;/*定义LCD控制端口*/sbitlcd_rw_port=P2^5;sbitlcd_en_port=P2^7;sbitRX=P3^6;//回响信号sbitTX=P3^7;//触发信号sbith=P2^4;sbitz_1=P2^0;//警报继电器发出sbitz_2=P2^
#include

#define uchar unsigned char

#define uint unsigned int

#include

unsigned char ly_dis[4];//定义显示缓冲区

sbit lcd_rs_port = P2^6; /*定义LCD控制端口*/

sbit lcd_rw_port = P2^5;

sbit lcd_en_port = P2^7;

sbit RX=P3^6; //回响信号

sbit TX=P3^7; //触发信号

sbit h=P2^4;

sbit z_1=P2^0; //警报继电器发出

sbit z_2=P2^1; //警报蜂鸣器发出

sbit y_1=P2^2; //警报继电器发出

sbit y_2=P2^3; //警报蜂鸣器发出

#define lcd_data_port P0

#define Busy 0x80 //用于检测LCM状态字中的Busy标识

uchar jishu;

uchar lb=0;

uchar lb_1=0;

uchar zhuanxiang;

uchar code mun_to_char[] = {"01234567ABCDEF.'cm+-

uchar j;

while(ms--){

for(j=0;j<250;j++)

{;}

}

}

void lcd_system_reset() /*LCD1602 初始化*/

{

lcd_delay(20);

lcd_command_write(0x38);

lcd_delay(100);

lcd_command_write(0x38);

lcd_delay(50);

lcd_command_write(0x38);

lcd_delay(10);

lcd_command_write(0x08);

lcd_command_write(0x01);

lcd_command_write(0x06);

lcd_command_write(0x0c);

lcd_data_port = 0xff; /*释放数据端口*/

}

void Conut(void)

{

time=TH0*256+TL0;

TH0=0;

TL0=0;

S=(time*1.7)/10; //算出来是MM

if(S<=200) //超出测量范围 //可以跟改此处数值达到设定的距离将200更改

{

lb++;

if(lb>=5){

lb_1=0;

y_1=0;y_2=1; z_1=0;z_2=0;

}

}

else

{

lb_1++;

if(lb_1>=5){

lb=0;

y_1=0;y_2=1; z_1=0;z_2=0;

}

}

if(flag==1) flag=0;

disbuff[0]=S%10;

disbuff[1]=S/10%10;

disbuff[2]=S/100%10;

disbuff[3]=S/1000;

}

void StartModule() //启动模块

{

TX=1; //启动一次模块

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

_nop_();

TX=0;

}

void Timer_Count(void)

{

TR0=1; //开启计数

while(RX);//当RX为1计数并等待

TR0=0;//关闭计数

Conut();//计算

}

void main() /*主函数*/

{

unsigned int i=0;

unsigned int valA;

void inti();

lcd_system_reset(); /*LCD1602 初始化*/

for(j=0;j<16;j++)//显示Welcome to the g

{

lcd_char_write(j,0,mun_to_char1[j]);

}

for(j=0;j<16;j++)//显示raduation design

{

lcd_char_write(j,1,mun_to_char1[j+16]);

}

lcd_delay(2000); //延时函数

for(j=0;j<16;j++)//清屏

{

lcd_char_write(j,0,mun_to_char8[j]);

}

for(j=0;j<16;j++)//清屏

{

lcd_char_write(j,1,mun_to_char8[j+16]);

}

for(j=0;j<16;j++)//显示The car

{

lcd_char_write(j,0,mun_to_char2[j]);

}

for(j=0;j<16;j++)//显示reversing radar

{

lcd_char_write(j,1,mun_to_char2[j+16]);

}

lcd_delay(2000); //延时函数

for(j=0;j<16;j++)//清屏

{

lcd_char_write(j,0,mun_to_char8[j]);

}

for(j=0;j<16;j++)//清屏

{

lcd_char_write(j,1,mun_to_char8[j+16]);

}

for(j=0;j<16;j++)//显示Designer:

{

lcd_char_write(j,0,mun_to_char4[j]);

}

for(j=0;j<16;j++)//显示li

{

lcd_char_write(j,1,mun_to_char4[j+16]);

}

lcd_delay(2000); //延时函数

for(j=0;j<16;j++)//清屏

{

lcd_char_write(j,0,mun_to_char8[j]);

}

for(j=0;j<16;j++)//清屏

{

lcd_char_write(j,1,mun_to_char8[j+16]);

}

while(1)

{

RX=1;

StartModule();

for(valA=7510;valA>0;valA--) //多次测量提升可靠性

{

if(RX==1)

{

Timer_Count();//时间计数

}

}

void display();//调用显示

}

}

void timer0() interrupt 1 /*定时器0中断函数*/

{

flag=1; //中断溢出标志

RX=0;

}

void timer1() interrupt 3 /*定时器1中断函数*/

{

jishu++;

TH1=(65536-1000)/256;

TL1=(65536-1000)%256;

if(jishu>=20){

jishu=0;

}

if((zhuanxiang==1)&&(jishu>=10)){

y_1=0;y_2=0; z_1=0;z_2=0;

}

if((zhuanxiang==1)&&(jishu<10)){

y_1=0;y_2=0; z_1=1;z_2=0;

}

if((zhuanxiang==0)&&(jishu>=10)){

y_1=0;y_2=0; z_1=0;z_2=0;

}

if((zhuanxiang==0)&&(jishu<10)){

y_1=1;y_2=0; z_1=1;z_2=0;

}

}

文档

超声波避障小车c语言程序

#include#defineucharunsignedchar#defineuintunsignedint#includeunsignedcharly_dis[4];//定义显示缓冲区sbitlcd_rs_port=P2^6;/*定义LCD控制端口*/sbitlcd_rw_port=P2^5;sbitlcd_en_port=P2^7;sbitRX=P3^6;//回响信号sbitTX=P3^7;//触发信号sbith=P2^4;sbitz_1=P2^0;//警报继电器发出sbitz_2=P2^
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top