#include<reg52.h>
#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>0;z--)
for(y=110;y>0;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;