超声波测距离加温度显示Word文档格式.docx
- 文档编号:20372046
- 上传时间:2023-01-22
- 格式:DOCX
- 页数:24
- 大小:23.04KB
超声波测距离加温度显示Word文档格式.docx
《超声波测距离加温度显示Word文档格式.docx》由会员分享,可在线阅读,更多相关《超声波测距离加温度显示Word文档格式.docx(24页珍藏版)》请在冰豆网上搜索。
#defineDataPortP0//MCUP0<
------>
LCM
#defineucharunsignedchar
#defineuintunsignedint
//***********FunctionDefinition*********************//
//****************函数声明***************************//
voidLCD_Write_number(uchars);
voidWrite_char(bitstart,ucharddata);
//写入某坐标
voidSend_byte(ucharbbyte);
voidLcd_init(void);
//lcd初始化
voidDisp_img(uchar*img);
//显示图片
voidLCD_Write_string(ucharX,ucharY,uchar*s);
//写入某字符串
voidLCD_set_xy(ucharx,uchary);
voidLcd_Mark3(void);
//画面3
voidLcd_Mark2(void);
//画面2
bittemp_flag;
//判断DS18B20正常工作位
DS18B20_init();
//DS18B20初始化
voiddelay(uintnum);
//DS18B20延时函数
voidDelaynms(uintdi);
//短延时
voiddelayms(uintx);
//1ms延时函数
readonebyte(void);
//读一个字节函数
voidwriteonebyte(uchardat);
//写一个字节函数
voidgettemperture(void);
//获取温度值
voidtemperture_display();
//温度显示函数
voidtempconv();
//温度转换
voidbeep();
//蜂鸣器响一声函数
voidtimer_init();
//中断初始化函数(计数器0,计数器1,定时器2)
voidzhuansu_display();
//转速显示函数
voidspeed_conv();
//速度转换函数
voidspeed_display();
//速度显示函数
voidchaoshengbo_conv(void);
//超声波转换
//***************变量定义*****************//
uchardatatemp_dat[2]={0};
//temp[0],temp[1]用来存放温度的低、高8位
uchardataDQdisp_buf[5]={0};
//温度显示缓冲区
ucharzhuansu_buff[6]={0};
//转速显示缓存
ucharspeed_buff[6]={0};
//速度显示缓存
uchartemp_comp;
//存放温度整数部分
ucharDS18B20_OK,speed2;
//DS18B20_OK=0复位正常
uchart2=0,T,L,H,WENDU;
//t2代表timer2中断次数,T代表温度整数部分
//H:
温度高8位,L:
温度低8位
uinttime=0;
//超声波往返时间
longS=0,num1=0,speed;
//s表示超声波距离,num1表示发动机转速
//speed表示车轮转速=》速度
bitflag=0;
//超声波中断溢出标志位
uchardisbuff[4]={0};
//超声波数据显示缓存
ucharcodenum[]={"
0123456789:
.-℃"
};
ucharcodeline1_data[]={"
速度:
km/h"
ucharcodeline2_data[]={"
转速:
r/min"
ucharcodeline3_data[]={"
前方车距:
m"
ucharcodeline4_data[]={"
车内温度:
"
ucharcodeline5_data[]={"
#**欢迎使用**#"
ucharcodeline6_data[]={"
您的安全"
ucharcodeline7_data[]={"
是全家人"
ucharcodeline8_data[]={"
最大的幸福·
·
ucharcodepicture[]=
{
0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x06,0x30,0x01,0xE0,0x00,0x00,0x2A,0x00,0x00,0xD8,0x00,0x00,0x00,0x00,0x00,
0x00,0x0F,0x7B,0x63,0xE0,0x00,0x00,0x22,0x00,0x01,0x24,0x00,0x00,0x00,0x00,0x00,
0x00,0x0F,0xFB,0x63,0x07,0x34,0x00,0x14,0x00,0x01,0x04,0x00,0x00,0x00,0x00,0x00,
0x00,0x0D,0xDB,0x63,0x01,0xBC,0x00,0x08,0x00,0x00,0x88,0x00,0x00,0x00,0x00,0x00,
0x00,0x0C,0x1B,0x63,0x07,0xB0,0x00,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x00,0x00,
0x00,0x0C,0x1B,0x63,0xED,0xB0,0xDB,0x00,0x01,0x00,0x20,0x00,0x00,0x00,0x00,0x00,
0x00,0x0C,0x19,0xE1,0xE7,0xB0,0xDB,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x05,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x0A,0x80,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x0A,0x00,0x00,0xFF,0xF8,0xE0,0x05,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x06,0xC0,0x15,0x00,0x1F,0xFF,0xFF,0xC0,0x02,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x09,0x20,0x11,0x00,0xFB,0xFF,0xE1,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x08,0x20,0x0A,0x03,0x9F,0x00,0x9E,0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x04,0x40,0x04,0x0E,0x70,0x00,0x81,0xC7,0x80,0x01,0x40,0x00,0x00,0x00,0x00,
0x00,0x02,0x80,0x00,0x1D,0x80,0x00,0xE0,0x61,0xE0,0x02,0xA0,0x00,0x00,0x00,0x00,
0x00,0x01,0x00,0x00,0x77,0x9F,0xFC,0xF0,0x18,0xF8,0x02,0x20,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0xDF,0x00,0x00,0xF3,0x0C,0x3C,0x01,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x03,0x9E,0x00,0x00,0xF8,0x06,0x1E,0x00,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0x0E,0x30,0x01,0xFC,0x7F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x7E,0xFF,0xFF,0xFF,0xFF,0xFF,0x83,0xC0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x0F,0xFD,0xFF,0xFF,0xFF,0xFF,0xFC,0x01,0xF0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x3F,0x81,0xFF,0x00,0x00,0x00,0x00,0x1F,0xF0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xFE,0xF0,0x00,0x00,0x01,0x00,0x00,0xC0,0x1C,0x00,0x00,0x00,0x00,0x00,
0x00,0x03,0xC0,0x07,0x80,0x00,0x03,0xE0,0x07,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,
0x00,0x03,0x80,0x03,0x40,0x00,0x03,0xE0,0x0C,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,
0x00,0x07,0x00,0x00,0xC0,0x00,0x00,0x20,0x18,0x00,0x07,0x00,0x00,0x00,0x00,0x00,
0x00,0x09,0x01,0x80,0x60,0x00,0x00,0x20,0x73,0x9F,0x03,0x80,0x00,0x00,0x00,0x00,
0x00,0x1E,0x0F,0xF2,0x20,0x00,0x00,0x20,0x67,0xFF,0xC1,0xC0,0x00,0x00,0x00,0x00,
0x00,0x1E,0x1F,0xF9,0x30,0x00,0x00,0x20,0xEF,0xFF,0xE0,0xE0,0x00,0x00,0x00,0x00,
0x00,0x38,0x3F,0xFC,0x90,0x00,0x00,0x20,0xCB,0xFF,0xF9,0xF0,0x00,0x00,0x00,0x00,
0x00,0x7F,0x7F,0xFE,0x10,0x00,0x00,0x20,0xDB,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,
0x00,0x6E,0xF9,0xBF,0x10,0x00,0x00,0x20,0xF7,0xED,0xFF,0xF0,0x00,0x00,0x00,0x00,
0x00,0x7C,0xFC,0x3F,0x10,0x00,0x00,0x20,0x67,0xE1,0xFD,0xE0,0x00,0x00,0x00,0x00,
0x00,0x38,0xFC,0x3F,0x18,0x00,0x00,0x20,0x87,0xE0,0xFD,0xC0,0x00,0x00,0x00,0x00,
0x00,0x38,0xF1,0x8F,0x18,0x00,0x1F,0xE7,0x87,0x9C,0x7D,0xC0,0x00,0x00,0x00,0x00,
0x00,0x1C,0xFE,0x1F,0x81,0xFF,0xFF,0xC0,0x0F,0xE0,0xFF,0x80,0x00,0x00,0x00,0x00,
0x00,0x0C,0xFC,0x3F,0x80,0x00,0x00,0x00,0x0F,0xE1,0xF8,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xF9,0xBF,0xFF,0xFF,0xFF,0xFF,0xFF,0xEC,0xFE,0x00,0x00,0x00,0x00,0x00,
0x00,0x03,0xF9,0xBF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,
0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,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
//************************************************//
//**********DS18B20********//
//************蜂鸣器响一声函数*******//
voidbeep()
BEEP=0;
//开蜂鸣器
delayms(500);
//延时半秒
BEEP=1;
//关蜂鸣器
}
//************温度转换***************//
voidtempconv()
ucharsign=0;
//定义符号标志位
uchartemp;
//定义温度数据暂存
if(H>
127)//大于127,即高4位全为1,即温度为负值
{
L=(~L)+1;
//取反加1,将补码变成原码
if((~L)>
=0xff)//
H=(~L)+1;
//取反加一
elseH=~H;
//否则只取反
sign=1;
//置符号标志位为1
}
temp=L&
0x0f;
//取小数位
DQdisp_buf[0]=temp*0.625;
//所获得的是四位数,所测温度加大了10倍
DQdisp_buf[0]=DQdisp_buf[0]%1000%100%10;
//将小数部分转换成ASCII码
temp_comp=((L&
0xf0)>
>
4|(H&
0x0f)<
<
4);
//取温度整数部分
DQdisp_buf[3]=temp_comp/100;
//温度百位
temp=temp_comp%100;
//温度的十位和个位一起
DQdisp_buf[2]=temp/10;
//温度十位
DQdisp_buf[1]=temp%10;
//温度个位
if(DQdisp_buf[3]==0)//如果温度的百位为0
DQdisp_buf[3]=17;
//则不显示,
if(DQdisp_buf[2]==0)//在这种前提下,如果十位也为0的话,
DQdisp_buf[2]=17;
//不显示十位
if(sign)DQdisp_buf[3]=13;
//如果符号标志位为1,则显示负号
//************温度显示函数**************//
voidtemperture_display()
LCD_set_xy(4,4);
//从第四行第5列开始显示
LCD_Write_number(11);
LCD_Write_number(DQdisp_buf[3]);
//显示百位
LCD_Write_number(DQdisp_buf[2]);
//显示十位
LCD_Write_number(DQdisp_buf[1]);
//显示个位
LCD_Write_number(12);
//小数点
LCD_Write_number(DQdisp_buf[0]);
//十分位
LCD_set_xy(4,7);
Write_char(1,num[14]);
Write_char(1,num[15]);
//************获取温度值*****************//
voidgettemperture(void)
uchari;
DS18B20_init();
//DS18B20初始化
if(DS18B20_OK==0)//如果正常
writeonebyte(0xcc);
//跳过读序列号的操作
writeonebyte(0x44);
//启动温度转换
for(i;
i<
100;
i++)//调用显示函数延时,等待A/D转换完成,分辨率为12位的需要延时750ms以上
temperture_display();
DS18B20_init();
//DS18B20初始化
writeonebyte(0xbe);
//读取温度寄存器
temp_dat[0]=readonebyte();
//温度低8位放入temp_dat[0]
temp_dat[1]=readonebyte();
//温度高8位放入temp_dat[1]
L=temp_
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 超声波 测距 温度 显示
![提示](https://static.bdocx.com/images/bang_tan.gif)