• 大小: 640KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-10
  • 语言: 其他
  • 标签: HY-SRF05  

资源简介

HY-SRF05超声波模块 全套资料包含:电路图、使用手册、源代码等 还包括LCD显示部分代码

资源截图

代码片段和文件信息

/*
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接 P3.7  ECH0 接P3.6

本程序源码只供学习参考,不得应用于商业用途,如有需要请联系作者。

[注:stc89c52使用12M或11.0592M晶振实测使用11.0592M]
=============================================================*/
#include  //器件配置文件
#include 
#define  RX  P3_6
#define  TX  P3_7

#define LCM_RW  P2_3 //定义LCD引脚
#define LCM_RS  P2_4
#define LCM_E   P2_2
#define LCM_Data  P1

#define Key_Data P3_3 //定义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[] ={“==Range Finder==“};
unsigned char code email[] =    {“heyaodz@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(0x381); //显示模式设置开始要求每次检测忙信号
WriteCommandLCM(0x081); //关闭显示
WriteCommandLCM(0x011); //显示清屏
WriteCommandLCM(0x061); // 显示光标移动设置
WriteCommandLCM(0x0F1); // 显示开及光标设置
}

//按指定位置显示一个字符
void DisplayOneChar(u

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       4703  2011-06-15 19:07  超声波PIC单片机C程序\HY-SRF05PIC.txt

     目录          0  2011-06-15 21:23  超声波PIC单片机C程序

----------- ---------  ---------- -----  ----

                 4703                    2


评论

共有 条评论