基于51单片机的超声波测距模块设计

发布者:qpb1234最新更新时间:2023-08-10 来源: elecfans关键字:51单片机  超声波测距模块  12864液晶 手机看文章 扫描二维码
随时随地手机看文章

超声波测距的模块,51单片机接上12864液晶,HC-SR04超声波模块,就可以了,具体程序没怎么看,超声波模块的硬件也不晓得。


超声波测距51单片机12864液晶显示源程序:

#include

#include

//引脚定义

sbitRX=P1 ^ 1;

sbitTX=P1 ^ 2;

sbitCS=P3 ^ 3;//片选 高电平有效 单片LCD使用时可固定高电平

sbitSID=P3 ^ 4;//数据

sbitSCLK=P3 ^ 5;//时钟

//Function Definition 函数声明

void Delay(int num);

void Init_DS18B20(void);

unsigned char ReadOneChar(void);

void WriteOneChar(unsigned char dat);

unsigned int ReadTemperature(void);

void clock_out(unsigned char dd);

unsigned char clock_in(void);

unsigned char read_clock(unsigned char ord);

void write_clock(unsigned char ord, unsigned char dd);

void Disp(void);

void id_case1_key(void);

void id_case2_key(void);

void Set_time(unsigned char sel,bit sel_1);

void Timer0_Init(void);

void Init_1302(void);

void Set_Bell(unsigned char sel, bit sel_1);

void Bell(void);

//12864

void Write_char(bit start, unsigned char ddata);

void Send_byte(unsigned char bbyte);

void Delaynms(unsigned int di);

void Lcd_init(void);

void Disp_img(unsigned char *img);

void LCD_Write_string(unsigned char X,unsigned char Y,unsigned char *s);

void LCD_set_xy( unsigned char x, unsigned char y );

unsigned char code num[]={“0123456789 :。-”};

unsigned char code waves[]={“超声波测距系统”};

unsigned char code znwk[] ={“智能微控工作室”};

unsigned char code CM[] ={“M”};

unsigned inttime=0;

long S=0;

bitflag =0;

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

unsigned char code logo[]={

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0xE0,0x00,0x00,0x0C,0x00,0x00,0x40,0x70,0x00,0x00,0x00,0x80,0x00,

0x00,0x00,0x00,0xE0,0x00,0x00,0x1E,0x00,0x00,0x60,0x70,0x00,0x00,0x0F,0xE0,0x00,

0x00,0x00,0x01,0xC0,0x00,0x60,0x3C,0x00,0x00,0xE0,0x60,0x00,0x1F,0xFF,0xE0,0x00,

0x00,0x00,0x03,0x80,0x00,0x70,0x70,0x40,0x00,0xE0,0x7E,0x00,0x1F,0xE0,0xC0,0x00,

0x00,0x00,0x03,0x00,0x00,0x73,0xC3,0xF0,0x01,0xC3,0xFC,0x00,0x38,0xE1,0xC0,0x00,

0x00,0x03,0xC6,0x3C,0x00,0x33,0x9F,0xF0,0x03,0x8F,0xC0,0x00,0x30,0xC1,0xC0,0x00,

0x00,0x3F,0xEF,0xFE,0x00,0x03,0x1C,0xE0,0x07,0x01,0xCC,0x00,0x31,0xF1,0x80,0x00,

0x00,0x79,0xDF,0xBC,0x00,0x06,0x18,0xC0,0x0E,0x01,0xFE,0x00,0x77,0xF9,0x80,0x00,

0x00,0x01,0xB0,0x30,0x01,0xC6,0x19,0xC0,0x1E,0x7F,0xDE,0x00,0x6F,0x83,0x80,0x00,

0x00,0x23,0xAC,0x60,0x0F,0xE6,0xF1,0x80,0x3E,0x7B,0x38,0x00,0x61,0x83,0x00,0x00,

0x00,0x37,0x0E,0x00,0x0F,0xC7,0xB7,0x80,0xEC,0x63,0x30,0x00,0xE3,0x03,0x00,0x00,

0x00,0x3E,0x0E,0x00,0x01,0x8F,0x37,0x01,0xCC,0x6F,0xF0,0x00,0xC7,0xF7,0x00,0x00,

0x00,0x1E,0x0C,0x00,0x03,0x1E,0x66,0x03,0x0C,0x7F,0x00,0x01,0xFF,0xE6,0x00,0x00,

0x00,0x1E,0x1C,0x00,0x03,0x1C,0x60,0x02,0x19,0xAC,0x00,0x01,0x96,0x06,0x00,0x00,

0x00,0x3E,0x3E,0x00,0x03,0x18,0x60,0x00,0x19,0xFC,0x00,0x03,0x86,0x0E,0x00,0x00,

0x00,0x7E,0x36,0x00,0x03,0x00,0xC0,0x00,0x38,0x78,0x00,0x03,0x06,0x0C,0x00,0x00,

0x00,0xE6,0x67,0x00,0x03,0x00,0xC0,0x00,0x30,0x78,0x00,0x06,0x0C,0x0C,0x00,0x00,

0x01,0xC6,0xC3,0x80,0x7F,0xF0,0xC0,0x00,0x30,0xFE,0x00,0x0E,0x0C,0x1C,0x00,0x00,

0x03,0x81,0x83,0xC0,0x78,0xFF,0x80,0x00,0x61,0xCF,0x80,0x1C,0x08,0x18,0x00,0x00,

0x06,0x07,0x03,0xE0,0x00,0x1F,0xFF,0xE0,0x67,0x07,0xE0,0x38,0x18,0xF8,0x00,0x00,

0x08,0x0E,0x01,0xF8,0x00,0x07,0xFF,0x80,0xCE,0x03,0xF8,0x60,0x00,0x70,0x00,0x00,

0x00,0x18,0x01,0xF8,0x00,0x01,0xFC,0x00,0xC0,0x01,0xFC,0xC0,0x00,0x70,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x06,0x00,0x00,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x07,0x00,0x00,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x06,0x00,0x00,0x00,0x0C,0xE0,0x00,0x01,0xE0,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x0E,0x00,0x00,0x00,0x3F,0xE0,0x00,0xFF,0xF0,0x00,0x38,0x00,0xE0,0x00,

0x00,0x00,0x0C,0x00,0x00,0x0F,0xFF,0x80,0x00,0xF8,0xF0,0x00,0x38,0x00,0xE0,0x00,

0x00,0x00,0x0C,0xF0,0x00,0x0F,0xC7,0x00,0x00,0x60,0xE0,0x00,0x38,0x00,0xE0,0x00,

0x00,0x00,0x1F,0xF0,0x00,0x01,0x8E,0x00,0x00,0x60,0xC0,0x00,0x70,0x01,0xC0,0x00,

0x00,0x07,0xFF,0x80,0x00,0x01,0x8C,0x00,0x00,0xE1,0x80,0x00,0x70,0x01,0xC0,0x00,

0x00,0x07,0xF8,0x00,0x00,0x01,0x98,0x00,0x00,0xDF,0xC0,0x00,0x70,0x01,0xC0,0x00,

0x00,0x00,0x78,0x00,0x00,0x01,0xBF,0xE0,0x00,0xFF,0x00,0x00,0x60,0x01,0x80,0x00,

0x00,0x00,0xFC,0x00,0x00,0x7F,0xFF,0xE0,0x00,0xC0,0x00,0x00,0xE0,0x03,0x80,0x00,

0x00,0x01,0xFE,0x00,0x00,0x7F,0xF8,0x00,0x00,0x00,0x00,0x00,0xC0,0x03,0x00,0x00,

0x00,0x03,0xB7,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x3C,0x00,0xC0,0x03,0x00,0x00,

0x00,0x07,0x67,0x00,0x00,0x60,0x00,0x00,0x03,0x9F,0xFE,0x00,0x80,0x02,0x00,0x00,

0x00,0x0E,0x63,0x80,0x00,0xE0,0x00,0x01,0xFF,0xCF,0x1E,0x01,0x80,0x06,0x00,0x00,

0x00,0x1C,0xE1,0xE0,0x00,0xC0,0x00,0x00,0xE3,0x9C,0x38,0x01,0x80,0x06,0x00,0x00,

0x00,0x38,0xC1,0xF8,0x01,0xC0,0x00,0x00,0xC3,0x18,0x30,0x00,0x00,0x00,0x00,0x00,

0x00,0xE0,0xFC,0xFE,0x03,0x80,0x00,0x01,0xC7,0x18,0x60,0x00,0x00,0x00,0x00,0x00,

0x01,0xDF,0xF8,0xFE,0x03,0x00,0x00,0x01,0x8E,0x1B,0xE0,0x07,0x00,0x1C,0x00,0x00,

0x07,0x07,0x80,0x00,0x07,0x00,0x00,0x01,0xFF,0x3F,0xE0,0x07,0x00,0x1C,0x00,0x00,

0x0C,0x03,0x80,0x00,0x0E,0x00,0x00,0x01,0xF0,0x38,0x00,0x0F,0x00,0x3C,0x00,0x00,

0x00,0x03,0x00,0x00,0x1C,0x00,0x00,0x01,0x00,0x20,0x00,0x06,0x00,0x18,0x00,0x00,

0x00,0x03,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x03,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x02,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

};

void Lcd_init(void)//初始化LCD

{

Delaynms(10); //启动等待,等LCM讲入工作状态

CS=1;

Write_char(0,0x30);//8 位介面,基本指令集

Write_char(0,0x0c);//显示打开,光标关,反白关

Write_char(0,0x01);//清屏,将DDRAM的地址计数器归零

}

void Write_char(bit start, unsigned char ddata) //写指令或数据

{

unsigned char start_data,Hdata,Ldata;

if(start==0)

start_data=0xf8;//写指令

else

start_data=0xfa;//写数据

Hdata=ddata&0xf0;//取高四位

Ldata=(ddata《《4)&0xf0;//取低四位

Send_byte(start_data);//发送起始信号

Delaynms(5); //延时是必须的

Send_byte(Hdata);//发送高四位

Delaynms(1);//延时是必须的

Send_byte(Ldata);//发送低四位

Delaynms(1);//延时是必须的

}

void Send_byte(unsigned char bbyte) //发送一个字节

{

unsigned char i;

for(i=0;i《8;i++)

{

SID=bbyte&0x80; //取出最高位

SCLK=1;

SCLK=0;

bbyte《《=1; //左移

}

}

void Delaynms(unsigned int di) //延时

{

unsigned int da,db;

for(da=0;da

for(db=0;db《10;db++);

}

void Disp_img(unsigned char*img)//图形方式12864显示字模221 横向取膜

{

unsigned char i,j;

unsigned int k = 0;

Write_char(0,0x36); //图形方式

for(i=0;i《32;i++)

{

Write_char(0,0x80+i);

Write_char(0,0x80);

for(j=0;j《16;j++)

{

Write_char(1,img[k++]);

}

}

for(i=0;i《32;i++)

{

Write_char(0,0x80+i);

Write_char(0,0x88);

for(j=0;j《16;j++)

{

Write_char(1,img[k++]);

}

}

}

void Clr_Scr(void)//清屏函数

{

Write_char(0,0x01);

}


关键字:51单片机  超声波测距模块  12864液晶 引用地址:基于51单片机的超声波测距模块设计

上一篇:51单片机的外部中断实验设计
下一篇:如何制作一款单片机记时器

推荐阅读最新更新时间:2024-11-13 15:14

自制51单片机常用头文件(中断)
#ifndef __CONFIG_H__ #define __CONFIG_H__ /********************************/ /* 以下为系统配置 */ /********************************/ #include regx51.h #include string.h #include intrins.h /***************************************************** 函 数 名:void Clearmen(void) 功 能:系统初始化 说 明:对系统引脚变量及中断进行初始化 入口参数:无 返 回
[单片机]
51单片机(STC89C52RC)小综合实验
  这个实验包含以下几个内容: 51单片机最小系统 单片机外接继电器 整流桥的使用 lm393电压比较器的使用   首先先上实验结果图: 前面两个继电器,中间是最小系统,最下脚是整流器和lm393电压比较器. 好,下面来说这个板子制作过程当中的经验:   一是整流桥输出的电压输入到电压比较器当中,这里牵扯到电压比较器的零点漂移概念,即输入为零的时候,输出不为零,主要原因是温度对电子元件的影响,电子元件一般都不是纯种的.二是稳压直流电压的输出,这里用电稳压电源的一套系统,要求不高的话一般是线性稳压:交流电压- 整流器- RC电路滤波- LR滤波(可选)- 稳压(三端稳压器)- 稳压管.三是51单片机下载,在接通串口线
[单片机]
<font color='red'>51单片机</font>(STC89C52RC)小综合实验
51单片机定时器的应用
interrupt中断的关键字,n是中断号提供中断程序的入口地址。 0-INT0 1-T0 2-INT1 3-T1 4-串行中断 5-T2 直接访问寄存器和端口 定义 sfr P0 0x80 sfr P1 0x81 sfr ADCON; 0xDE sbit EA 0x9F 操作 ADCON = 0x08 ; P1 = 0xFF ; io_status = P0 ; EA = 1 ; 在使用了interrupt 1 关键字之后,会自动生成中断向量 在 IS
[单片机]
51单片机字符串口通信为什么乱码?终于找到原因了
被这个问题卡了3天,代码很简单就是乱码出问题,烦恼! 后来查资料找到原因,晶振12MHz和11.0592Hz的问题。 如果你用的是12Mhz的单片机,定时器初值TH1一般要设置到E6(2400bps)、F3(4800bps)。 对应的在上位机配置UART串口时,选取2400 4800bps。如果试了不行,那就换更低的1200bps。 修改前 修改后 做了半天才发现我的晶振是11.0592Mhz,为啥对应的开发板视频讲的是12Mhz。 以4800bps为例,TH1=TL1=0xF4,SMOD=1,波特率翻倍=2*2400bps。这样就不会乱码了 ------------------------------
[单片机]
<font color='red'>51单片机</font>字符串口通信为什么乱码?终于找到原因了
51单片机学习:IO扩展(串转并)实验-74HC595
实验名称:IO扩展(串转并)实验-74HC595 接线说明: 实验现象:下载程序后,8*8LED点阵以一行循环滚动显示 注意事项:LED点阵旁的J24黄色跳线帽短接到GND一端 ***************************************************************************************/ #include reg51.h typedef unsigned int u16; //对系统默认数据类型进行重定义 typedef unsigned char u8; //定义74HC595控制管脚 sbit SRCLK=P3^6; //移位寄存器时钟输入 sbit RCLK
[单片机]
51单片机系列之串口
---------------------------------------------------- 名称:51单片机自带串口 平台:Keil 4, Ly-51S学习板 引脚定义如下:RXD TXD MAX232与51连接:TXD-T1IN RXD-R1OUT -----------------------------------------------------*/ #include reg52.h /*串口初始化*/ void UART_init() { SCON = 0x50; // SCON: 模式 1, 8-bit UART, 使能接收 TMOD |= 0x20;
[单片机]
89C51单片机——按钮控制LED
1.实现流程图 2.proteus仿真图 3.keli代码 #include reg51.h sbit led1=P0^0; sbit key1=P0^1; sbit led2=P1^0; sbit key2=P1^1; void delay(int ms) { int i,j; for(i = 0; i ms; ++i) for(j = 0; j 110; ++j); } int main() { led1=1; led2=0; while(1) { //按钮控制 if(key2 == 0) { //按钮延时去抖动
[单片机]
89C<font color='red'>51单片机</font>——按钮控制LED
51单片机+DHT11温控程序-可设置温度值
基于51单片机的温湿度测量控制程序,使用DHT11数字传感器,用1602液晶屏显示,按键定义如下: sbit key_1=P0^1; //确定按键 sbit key_2=P0^2; //按键加 sbit key_3=P0^3; // 按键减 本程序中用到的头文件 12c5a.h下载: http://www.51hei.com/f/12c5a.rar #include 12c5a.H #include intrins.h unsigned char code num ={ 0123456789 };//显示字符存储 unsigned char code start_char ={ Loading.... }; unsigned c
[单片机]
小广播
设计资源 培训 开发板 精华推荐

最新单片机文章
何立民专栏 单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广工作。

换一换 更多 相关热搜器件

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved