求:基于89c52单片机的超声波测距的程序。
本人设计的硬件如下:p3.0超声波发出、p3.2超声波接收、显示模块由p0口进行段选,p2口通过74L138进行位选,p1.7接蜂鸣器。接收模块为CX20106A设计接收...
本人设计的硬件如下:p3.0超声波发出、p3.2超声波接收、显示模块由p0口进行段选,p2口通过74L138进行位选,p1.7接蜂鸣器。接收模块为CX20106A设计接收电路。
展开
展开全部
void CLR_SCREEN(void);
void LCD_DISOFF(void);
void LCD_DISON(void);
void LCD_CUROFF(void);
void LCD_CURON(void);
void LCD_INT(void);
void LCD_PRINT(unsigned char row,unsigned char col,unsigned char count,unsigned int dats);
void LCD_PRINTF(unsigned char row,unsigned char col,unsigned char InBuffer[33]);
void LCD_PRINTCHAR(unsigned char row,unsigned char col,unsigned char Buffer);
void CPU_DELAYTIME(unsigned int count);
void LCD_WRI(unsigned char adr);
void LCD_WRD(unsigned char asc);
//--------------------------------------------------显示数值
void LCD_PRINT(unsigned char row,unsigned char col,unsigned char count,unsigned int dats){
unsigned int sxh4;
unsigned int sxh3;
unsigned int sxh2;
unsigned int sxh1;
LCD_DISON();
CPU_DELAYTIME(100);
switch (row)
{
case 1:row=0x80;break;
case 2:row=0xC0;break;
default: break;
}
LCD_WRI(row+col-1);
CPU_DELAYTIME(200);
sxh4=dats/10;
sxh3=sxh4/10;
sxh2=sxh3/10;
sxh1=sxh2/10;
if(count>=5){LCD_WRD(sxh1+48);}
if(count>=4){LCD_WRD(sxh2-sxh1*10+48);}
if(count>=3){LCD_WRD(sxh3-sxh2*10+48);}
if(count>=2){LCD_WRD(sxh4-sxh3*10+48);}
LCD_WRD(dats-sxh4*10+48);
}
//--------------------------------------------------LCD初始化
void LCD_INT(void){
LCD_WRI(0X38); //8位数据总线 两行显示模式 5X7点阵+光标显示模式
LCD_CUROFF(); //无光标跟随
LCD_WRI(0X80); //设置显示地址00H
}
//--------------------------------------------------关闭显示
void LCD_DISOFF(void){
LCD_WRI(0X08);
}
//--------------------------------------------------打开显示
void LCD_DISON(void){
LCD_WRI(0X0C);
}
//--------------------------------------------------光标消失
void LCD_CUROFF(void){
LCD_WRI(0X0C);
}
//--------------------------------------------------光标跟随
void LCD_CURON(void){
LCD_WRI(0X0F);
}
//--------------------------------------------------显示字符串
void LCD_PRINTF(unsigned char row,unsigned char col,unsigned char InBuffer[33])
{
unsigned char I_LOOP;
LCD_DISON();
CPU_DELAYTIME(500);
switch (row)
{
case 1:row=0x80;break;
case 2:row=0xC0;break;
default: break;
}
LCD_WRI(row+col-1);
for(I_LOOP=0;I_LOOP<=32;I_LOOP++){
if(InBuffer[I_LOOP]=='%'&&InBuffer[I_LOOP+1]=='d'){ break;}
if(col+I_LOOP==17&&row==0x80){LCD_WRI(0xC0);}
LCD_WRD(InBuffer[I_LOOP]);
}
}
//------------------------------------------------------------------
void LCD_PRINTCHAR(unsigned char row,unsigned char col,unsigned char Buffer){
LCD_DISON();
CPU_DELAYTIME(500);
switch (row)
{
case 1:row=0x80;break;
case 2:row=0xC0;break;
default: break;
}
LCD_WRI(row+col-1);
LCD_WRD(Buffer);
}
//-------------------------------------------------清屏指令
void CLR_SCREEN(void){
LCD_INT();
LCD_WRI(1);
CPU_DELAYTIME(200);
}
//-------------------------------------------------延时函数
void CPU_DELAYTIME(unsigned int count){
unsigned int iu_LOOP;
for(iu_LOOP=0;iu_LOOP<=count;iu_LOOP++){; }
}
//-----------------------------------------------显示屏写指令子程序
void LCD_WRI(unsigned char adr)
{ LCD_RW=0;
LCD_RS=0;
LCD_E=1;
LCD_DAT=adr;
LCD_E=0;
CPU_DELAYTIME(20);
}
//----------------------------------------------显示屏写数据子程序
void LCD_WRD(unsigned char asc){
LCD_RW=0;
LCD_RS=1;
LCD_E=1;
LCD_DAT=asc;
LCD_E=0;
CPU_DELAYTIME(80);
}
void LCD_DISOFF(void);
void LCD_DISON(void);
void LCD_CUROFF(void);
void LCD_CURON(void);
void LCD_INT(void);
void LCD_PRINT(unsigned char row,unsigned char col,unsigned char count,unsigned int dats);
void LCD_PRINTF(unsigned char row,unsigned char col,unsigned char InBuffer[33]);
void LCD_PRINTCHAR(unsigned char row,unsigned char col,unsigned char Buffer);
void CPU_DELAYTIME(unsigned int count);
void LCD_WRI(unsigned char adr);
void LCD_WRD(unsigned char asc);
//--------------------------------------------------显示数值
void LCD_PRINT(unsigned char row,unsigned char col,unsigned char count,unsigned int dats){
unsigned int sxh4;
unsigned int sxh3;
unsigned int sxh2;
unsigned int sxh1;
LCD_DISON();
CPU_DELAYTIME(100);
switch (row)
{
case 1:row=0x80;break;
case 2:row=0xC0;break;
default: break;
}
LCD_WRI(row+col-1);
CPU_DELAYTIME(200);
sxh4=dats/10;
sxh3=sxh4/10;
sxh2=sxh3/10;
sxh1=sxh2/10;
if(count>=5){LCD_WRD(sxh1+48);}
if(count>=4){LCD_WRD(sxh2-sxh1*10+48);}
if(count>=3){LCD_WRD(sxh3-sxh2*10+48);}
if(count>=2){LCD_WRD(sxh4-sxh3*10+48);}
LCD_WRD(dats-sxh4*10+48);
}
//--------------------------------------------------LCD初始化
void LCD_INT(void){
LCD_WRI(0X38); //8位数据总线 两行显示模式 5X7点阵+光标显示模式
LCD_CUROFF(); //无光标跟随
LCD_WRI(0X80); //设置显示地址00H
}
//--------------------------------------------------关闭显示
void LCD_DISOFF(void){
LCD_WRI(0X08);
}
//--------------------------------------------------打开显示
void LCD_DISON(void){
LCD_WRI(0X0C);
}
//--------------------------------------------------光标消失
void LCD_CUROFF(void){
LCD_WRI(0X0C);
}
//--------------------------------------------------光标跟随
void LCD_CURON(void){
LCD_WRI(0X0F);
}
//--------------------------------------------------显示字符串
void LCD_PRINTF(unsigned char row,unsigned char col,unsigned char InBuffer[33])
{
unsigned char I_LOOP;
LCD_DISON();
CPU_DELAYTIME(500);
switch (row)
{
case 1:row=0x80;break;
case 2:row=0xC0;break;
default: break;
}
LCD_WRI(row+col-1);
for(I_LOOP=0;I_LOOP<=32;I_LOOP++){
if(InBuffer[I_LOOP]=='%'&&InBuffer[I_LOOP+1]=='d'){ break;}
if(col+I_LOOP==17&&row==0x80){LCD_WRI(0xC0);}
LCD_WRD(InBuffer[I_LOOP]);
}
}
//------------------------------------------------------------------
void LCD_PRINTCHAR(unsigned char row,unsigned char col,unsigned char Buffer){
LCD_DISON();
CPU_DELAYTIME(500);
switch (row)
{
case 1:row=0x80;break;
case 2:row=0xC0;break;
default: break;
}
LCD_WRI(row+col-1);
LCD_WRD(Buffer);
}
//-------------------------------------------------清屏指令
void CLR_SCREEN(void){
LCD_INT();
LCD_WRI(1);
CPU_DELAYTIME(200);
}
//-------------------------------------------------延时函数
void CPU_DELAYTIME(unsigned int count){
unsigned int iu_LOOP;
for(iu_LOOP=0;iu_LOOP<=count;iu_LOOP++){; }
}
//-----------------------------------------------显示屏写指令子程序
void LCD_WRI(unsigned char adr)
{ LCD_RW=0;
LCD_RS=0;
LCD_E=1;
LCD_DAT=adr;
LCD_E=0;
CPU_DELAYTIME(20);
}
//----------------------------------------------显示屏写数据子程序
void LCD_WRD(unsigned char asc){
LCD_RW=0;
LCD_RS=1;
LCD_E=1;
LCD_DAT=asc;
LCD_E=0;
CPU_DELAYTIME(80);
}
追问
不好意思 我用的是LED数码管显示 不是LCD,有led显示的吗?
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
通测科技
2021-07-30 广告
2021-07-30 广告
选择正确的光时域反射仪 (OTDR)1.OTDR是一种光纤测试仪,用于测试光通信网络的特性。OTDR旨在探测、定位和测量光纤链路任何位置上的事件。OTDR只需接入链路的一端,其工作方式类似于一维雷达系统。通过提供被测光纤的图形化迹线特征,用...
点击进入详情页
本回答由通测科技提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询