超声波测距仪编程_超声波测距C语言程序

#include&ltreg52.h&gt

#define uchar unsigned char

#define uint unsigned int

uchar distance[]="THE DISTANCE IS:";

uchar cm[]="CM";

uchar dis[3];//距离数组,本超声波模块为HC—SR04,测量距离为2CM--400CM ,故只定义三位

sbit tirg=P1^0; //发射端

sbit echo=P1^1; //接收端

sbit lcdrs = P2^4;

sbit lcdrw = P2^5;

sbit lcden = P2^6;

uchar num;

int s;//不可为浮点型,因为,浮点型数不可以进行取模运算“%”

void delay(uint z)

{

uint x,y;

for(x=z;z&gt0;z--)

for(y=110;y&gt0;y--);

}

void TIM0init(void)

{

TMOD= 0x01;//定时器0工作方式1

TH0=0x00;

TL0=0x00;

EA=1;

ET0=1;

TR0=1;

}

void write_com(uchar com)

{

lcdrs=0;

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值