超声波测距正确程序(共7页).doc





《超声波测距正确程序(共7页).doc》由会员分享,可在线阅读,更多相关《超声波测距正确程序(共7页).doc(7页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上/*- 内容:通过标准程序静态显示字符 引脚定义如下:1-VSS 2-VDD 3-V0 4-RS 5-R/W 6-E 7-14 DB0-DB7 15-BLA 16-BLK-*/#include /包含头文件,一般情况不需要改动,头文件包含特殊功能寄存器的定义#includesbit RS = P20; /定义端口 sbit RW = P21;sbit EN = P22;sbit echo=P11; /接收端sbit trig=P10; /发射端sbit Beap=P23; /蜂鸣器sbit Key_Data=P24; /按键发射#define RS_CLR RS=0
2、#define RS_SET RS=1#define RW_CLR RW=0 #define RW_SET RW=1 #define EN_CLR EN=0#define EN_SET EN=1#define DataPort P0unsigned char code ASCII15 = 0,1,2,3,4,5,6,7,8,9,.,-,M;unsigned char disbuff4 = 0,0,0,0,;unsigned long S=0;unsigned char Flag;unsigned int time;unsigned int t=500;/*- uS延时函数,含有输入参数 uns
3、igned char t,无返回值 unsigned char 是定义无符号字符变量,其值的范围是 0255 这里使用晶振12M,精确延时请使用汇编,大致延时 长度如下 T=tx2+5 uS -*/void DelayUs2x(unsigned char t) while(-t);/*- mS延时函数,含有输入参数 unsigned char t,无返回值 unsigned char 是定义无符号字符变量,其值的范围是 0255 这里使用晶振12M,精确延时请使用汇编-*/void DelayMs(unsigned char t) while(t-) /大致延时1mS DelayUs2x(24
4、5); DelayUs2x(245); /*- 判忙函数-*/ bit LCD_Check_Busy(void) DataPort= 0xFF; RS_CLR; RW_SET; EN_CLR; _nop_(); EN_SET; return (bit)(DataPort & 0x80); /*- 写入命令函数-*/ void LCD_Write_Com(unsigned char com) while(LCD_Check_Busy(); /忙则等待 RS_CLR; RW_CLR; EN_SET; DataPort= com; _nop_(); EN_CLR; /*- 写入数据函数-*/ voi
5、d LCD_Write_Data(unsigned char Data) while(LCD_Check_Busy(); /忙则等待 RS_SET; RW_CLR; EN_SET; DataPort= Data; _nop_(); EN_CLR; /*- 清屏函数-*/ void LCD_Clear(void) LCD_Write_Com(0x01); DelayMs(5); /*- 写入字符串函数-*/ void LCD_Write_String(unsigned char x,unsigned char y,unsigned char *s) if (y = 0) LCD_Write_Co
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 超声波 测距 正确 程序

限制150内