超声波LCD显示测距程序.docx
- 文档编号:10063366
- 上传时间:2023-02-08
- 格式:DOCX
- 页数:16
- 大小:17.28KB
超声波LCD显示测距程序.docx
《超声波LCD显示测距程序.docx》由会员分享,可在线阅读,更多相关《超声波LCD显示测距程序.docx(16页珍藏版)》请在冰豆网上搜索。
超声波LCD显示测距程序
文件管理序列号:
[K8UY-K9IO69-O6M243-OL889-F88688]
超声波LCD显示测距程序
/******************************************************************************/
/*Name:
LCD12864(St7920/St7921)+超声波测距模块+STC89C52*/
/*DYP-ME007超声波测距模块DEMO程序*/
/*晶振:
11.0592M*/
*/
/*接线:
模块TRIG接P1.2ECH0接P1.1*/
/*RS(CS)接P3.3;*/
/*RW(SID)接P3.4;*/
/*E(SCLK)接P3.5;*/
/*PSB接GND串行模式*/
/******************************************************************************/
#include
#include
//引脚定义
sbitRX=P1^1;
sbitTX=P1^2;
sbitCS=P3^3;//片选高电平有效单片LCD使用时可固定高电平
sbitSID=P3^4;//数据
sbitSCLK=P3^5;//时钟
//FunctionDefinition 函数声明
voidDelay(intnum);
voidInit_DS18B20(void);
unsignedcharReadOneChar(void);
voidWriteOneChar(unsignedchardat);
unsignedintReadTemperature(void);
voidclock_out(unsignedchardd);
unsignedcharclock_in(void);
unsignedcharread_clock(unsignedcharord);
voidwrite_clock(unsignedcharord,unsignedchardd);
voidDisp(void);
voidid_case1_key(void);
voidid_case2_key(void);
voidSet_time(unsignedcharsel,bitsel_1);
voidTimer0_Init(void);
voidInit_1302(void);
voidSet_Bell(unsignedcharsel,bitsel_1);
voidBell(void);
//12864
voidWrite_char(bitstart,unsignedcharddata);
voidSend_byte(unsignedcharbbyte);
voidDelaynms(unsignedintdi);
voidLcd_init(void);
voidDisp_img(unsignedchar*img);
voidLCD_Write_string(unsignedcharX,unsignedcharY,unsignedchar*s);
voidLCD_set_xy(unsignedcharx,unsignedchary);
unsignedcharcode:
.-"};
unsignedcharcodewaves[]={"超声波测距系统"};
unsignedcharcodeznwk[]={"智能微控工作室"};
unsignedcharcodeCM[]={"M"};
unsignedinttime=0;
longS=0;
bitflag=0;
unsignedchardisbuff[4]={0,0,0,0,};
unsignedcharcodelogo[]={
/*--调入了一幅图像:
logo.bmp--*/
/*--宽度x高度=128x64欢迎使用本产品LOGO--*/
/*--调入了一幅图像:
C:
\DocumentsandSettings\lwd\桌面\新建文件夹\X.bmp--*/
/*--宽度x高度=128x64--*/
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,
};
/******************************************************************************/
voidLcd_init(void)//初始化LCD
{
Delaynms(10);//启动等待,等LCM讲入工作状态
CS=1;
Write_char(0,0x30);//8位介面,基本指令集
Write_char(0,0x0c);//显示打开,光标关,反白关
Write_char(0,0x01);//清屏,将DDRAM的地址计数器归零
}
/******************************************************************************/
voidWrite_char(bitstart,unsignedcharddata)//写指令或数据
{
unsignedcharstart_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);//延时是必须的
}
/******************************************************************************/
voidSend_byte(unsignedcharbbyte)//发送一个字节
{
unsignedchari;
for(i=0;i<8;i++)
{
SID=bbyte&0x80;//取出最高位
SCLK=1;
SCLK=0;
bbyte<<=1;//左移
}
}
/******************************************************************************/
voidDelaynms(unsignedintdi)//延时
{
unsignedintda,db;
for(da=0;da for(db=0;db<10;db++); } /******************************************************************************/ voidDisp_img(unsignedchar*img)//图形方式12864显示字模221横向取膜 { unsignedchari,j; unsignedintk=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++]); } } } /******************************************************************************/ voidClr_Scr(void)//清屏函数 { Write_char(0,0x01); } /******************************************************************************/ voidLCD_set_xy(unsignedcharx,unsignedchary) {//设置LCD显示的起始位置,X为行,Y为列 unsignedcharaddress; switch(x) { case0: address=0x80+y;break; case1: address=0x80+y;break; case2: address=0x90+y;break; case3: address=0x88+y;break; case4: address=0x98+y;break; default: address=0x80+y;break; } Write_char(0,address); } /******************************************************************************/ voidLCD_Write_string(unsignedcharX,unsignedcharY,unsignedchar*s) {//中英文字符串显示函数 LCD_set_xy(X,Y); while(*s) { Write_char(1,*s); s++; Delaynms (1); } } /******************************************************************************/ voidLCD_Write_number(unsignedchars)//数字显示函数 { Write_char(1,num[s]); Delaynms (1); } /******************************************************************************/ voidLcd_Mark2(void) { Clr_Scr();//清屏 LCD_Write_string(1,0,znwk);// LCD_Write_string(2,0,waves);// LCD_Write_string(3,7,CM);// } /**********************************************
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 超声波 LCD 显示 测距 程序
![提示](https://static.bdocx.com/images/bang_tan.gif)