资源简介
关于测距模块HC-SR04的内部电路图 ,51程序,需要的同学可以参考下 很精准的测距装置
代码片段和文件信息
/*============================================================
//HC-SRO4 超声波测距模块 DEMO 程序
// QQ: 517535000
//淘宝店铺:http://shop58246706.taobao.com
==============================================================
SMC1602A(16*2)模拟口线接线方式
连接线图:
---------------------------------------------------
|LCM-----51 | LCM-----51 | LCM------51 |
--------------------------------------------------|
|DB0-----P1.0 | DB4-----P1.4 | RW-------P3.4 |
|DB1-----P1.1 | DB5-----P1.5 | RS-------P3.3 |
|DB2-----P1.2 | DB6-----P1.6 | E--------P3.5 |
|DB3-----P1.3 | DB7-----P1.7 | VLCD接1K电阻到GND|
---------------------------------------------------
接线:模块TRIG接 P2.6 ECH0 接P2.7
本程序源码只供学习参考,不得应用于商业用途,如有需要请联系作者。
[注:AT89x51使用12M或11.0592M晶振实测使用11.0592M]
=============================================================*/
#include //器件配置文件
#include
#define RX P2_7
#define TX P2_6
#define LCM_RW P3_4 //定义LCD引脚
#define LCM_RS P3_3
#define LCM_E P3_5
#define LCM_Data P1
#define Key_Data P2_0 //定义Keyboard引脚
#define Key_CLK P3_2
#define Busy 0x80 //用于检测LCM状态字中的Busy标识
void LCMInit(void);
void DisplayOneChar(unsigned char X unsigned char Y unsigned char DData);
void DisplayListChar(unsigned char X unsigned char Y unsigned char code *DData);
void Delay5Ms(void);
void Delay400Ms(void);
void Decode(unsigned char ScanCode);
void WriteDataLCM(unsigned char WDLCM);
void WriteCommandLCM(unsigned char WCLCMBuysC);
unsigned char ReadDataLCM(void);
unsigned char ReadStatusLCM(void);
unsigned char code mcustudio[] ={“mcustudio.com.cn“};
unsigned char code email[] = {“fhwxaoo@163.com “};
unsigned char code Cls[] = {“ “};
unsigned char code ASCII[15] = {‘0‘‘1‘‘2‘‘3‘‘4‘‘5‘‘6‘‘7‘‘8‘‘9‘‘.‘‘-‘‘M‘};
static unsigned char DisNum = 0; //显示用指针
unsigned int time=0;
unsigned long S=0;
bit flag =0;
unsigned char disbuff[4] ={ 0000};
//写数据
void WriteDataLCM(unsigned char WDLCM)
{
ReadStatusLCM(); //检测忙
LCM_Data = WDLCM;
LCM_RS = 1;
LCM_RW = 0;
LCM_E = 0; //若晶振速度太高可以在这后加小的延时
LCM_E = 0; //延时
LCM_E = 1;
}
//写指令
void WriteCommandLCM(unsigned char WCLCMBuysC) //BuysC为0时忽略忙检测
{
if (BuysC) ReadStatusLCM(); //根据需要检测忙
LCM_Data = WCLCM;
LCM_RS = 0;
LCM_RW = 0;
LCM_E = 0;
LCM_E = 0;
LCM_E = 1;
}
//读数据
unsigned char ReadDataLCM(void)
{
LCM_RS = 1;
LCM_RW = 1;
LCM_E = 0;
LCM_E = 0;
LCM_E = 1;
return(LCM_Data);
}
//读状态
unsigned char ReadStatusLCM(void)
{
LCM_Data = 0xFF;
LCM_RS = 0;
LCM_RW = 1;
LCM_E = 0;
LCM_E = 0;
LCM_E = 1;
while (LCM_Data & Busy); //检测忙信号
return(LCM_Data);
}
void LCMInit(void) //LCM初始化
{
LCM_Data = 0;
WriteCommandLCM(0x380); //三次显示模式设置,不检测忙信号
Delay5Ms();
WriteCommandLCM(0x380);
Delay5Ms();
WriteCommandLCM(0x380);
Delay5Ms();
WriteCommandLCM(0
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4702 2010-06-20 22:33 超声波PIC单片机C程序\HC-SR04PIC.txt
目录 0 2010-06-20 22:33 超声波PIC单片机C程序
----------- --------- ---------- ----- ----
4702 2
- 上一篇:STM32F103+TFT彩屏程序
- 下一篇:马尔科夫特征提取
相关资源
- 瑞芯微RK原厂3399+LPDDR4 336球参考原理图
- dd-wrt.v24-15943_VINT_std-nokaid_usb
- Fiddler+v4.6.1.5汉化版
- ad9851 DDS 程序STM32 C51本人亲自调试
- 西门子DDC控制调试必备
- The Art of Debugging with GDB DDD and Eclipse.
- 基于fpga的dds可调频1-20MHZ,调幅,调相
- DDR3 sodimm DXP封装
- 基于STM32示波器 DDS信号发生器.zip
- SIEMENS 840D HMI 二次开发完整包
- QCExplorer QCExplorerAddIn QC浏览器 QC客户
- JESD79-3F DDR3 SDRAM Standard
- Additional Exercises for Convex Optimization
- 220ddc4f0dfcdbc35b693cd005ac3e16.rar
- ddos2016.exe
- 计算机图形学基础课程设计
- thc-ssl-dos-1.4-win-bin
- esriAddIn小工具
- comsol声学模块介绍
- CRUDDemo2.2.rar
- qt-recordDesktop
-
中文翻译 SphereFace Deep Hypersphere em
- 双目立体视觉的常用的一些Middlebury的
- Fiddler4安装包
- FPGA DDS 信号发生
- 基于FPGA的任意波形发生器的研究与设
- Beginning Lua with World of Warcraft Add-ons
-
嵌入式系统设计em
bedded System Design - fiddler 4最强大最好用的Web调试工具
- 利用t2fk工具的DDos攻击实验步骤.docx
评论
共有 条评论