IC解密超声波测距模块程序1602显示
IC解密HC-SRO4 超声波测距模块 DEMO 程序
==============================================================
IC解密SMC1602A(16*2)模拟口线接线方式
连接线图:
---------------------------------------------------
|LCM_RS--P3_3 | LCM_RW--P3_4 | LCM_E--P3_5 |
--------------------------------------------------|
|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 <AT89x51.H> //器件配置文件
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
#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 Busy 0x80 //用于检测LCM状态字中的Busy标识
unsigned char code mcustudio[] ={" The distance "};
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; //显示用指针
uint time=0;
unsigned long S=0;
bit flag =0;
uchar disbuff[4]={ 0,0,0,0,};
/*********************5ms延时************/
void delay5Ms(void)
{
uint TempCyc = 5552;
while(TempCyc--);
}
/***********400ms延时******************/
void delay400Ms(void)
{
uchar TempCycA = 5;
uint TempCycB;
while(TempCycA--)
{
TempCycB=7269;
while(TempCycB--);
};
}
/*********************延迟****************/
void delayms(uint ms)
{
unsigned char i=100,j;
for(;ms;ms--)
{
while(--i)
{
j=10;
while(--j);
}
}
}
/**************读状态**********************************/
uchar 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);
}

芯片解密