18b20h温度传感器相关的程序文档格式.docx

上传人:b****6 文档编号:16504806 上传时间:2022-11-24 格式:DOCX 页数:12 大小:16.75KB
下载 相关 举报
18b20h温度传感器相关的程序文档格式.docx_第1页
第1页 / 共12页
18b20h温度传感器相关的程序文档格式.docx_第2页
第2页 / 共12页
18b20h温度传感器相关的程序文档格式.docx_第3页
第3页 / 共12页
18b20h温度传感器相关的程序文档格式.docx_第4页
第4页 / 共12页
18b20h温度传感器相关的程序文档格式.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

18b20h温度传感器相关的程序文档格式.docx

《18b20h温度传感器相关的程序文档格式.docx》由会员分享,可在线阅读,更多相关《18b20h温度传感器相关的程序文档格式.docx(12页珍藏版)》请在冰豆网上搜索。

18b20h温度传感器相关的程序文档格式.docx

i<

128;

i++)

{

for(j=49;

j<

63;

j++)

disp_bit(i,j,2);

}

mdelay(1500);

voidshow_zb()

show_p(zb);

gotoxy(1,7);

wr_d_lcd(0xa1);

wr_d_lcd(0xe6);

voidabout()

show_p(apple);

mdelay(2000);

while(ff==9)

key();

}

voidalarm(ucharnn)

if((nn!

=0)&

alarmx1)

fA=1;

beep=~beep;

gotoxy(1,2);

if(beep)

{

print("

"

);

}

else

△"

gotoxy(3,2);

switch(nn)

{

case1:

print("

高温告警"

break;

case2:

失温告警"

case3:

传感器告警"

}

}

elseif(fA)

beep=1;

print("

gotoxy(3,2);

fA=0;

voidtemp_to_zb(void)

uchary,temp,i;

temp=(temp_h<

<

5)|(temp_l>

>

3);

if(temp<

0x29)

temp=0x29;

elseif(temp>

0x55)

temp=0x55;

else

y=101-temp;

if(y<

max)

alarmx=1;

elseif(y>

min)

alarmx=2;

elseif(alarmx!

=3)

alarmx=0;

for(i=16;

60;

disp_bit(xx,i,0);

disp_bit(xx,y,1);

xx++;

if(xx==124)

xx=13;

for(i=max;

min;

i+=alarmx1)

disp_bit(xx,i,1);

voidzb_to_sz(ucharzz)

uchartt0;

if(tt0=(101-zz)&

0x01)

tt[4]=5+'

0'

;

else

tt[4]='

tt[3]='

.'

tt0=(101-zz)>

1;

tt[2]=tt0%10+'

tt[1]=tt0/10%10+'

tt[0]=tt0/100;

if(tt[0]==0)

tt[0]='

'

tt[5]='

\0'

voidkey()

if(key2==0)

mdelay(10);

if(key2==0)

while(key2==0);

switch(ff)

case0:

gotoxy(2,1);

print("

Alarm:

gotoxy(2,5);

if(alarmx1==1)print("

On"

elseprint("

Off"

ff++;

case1:

Setmax"

zb_to_sz(max);

print(tt);

ff++;

case2:

Setmin"

zb_to_sz(min);

case3:

About"

case4:

ff=0;

case9:

ff=0;

show_zb();

xx=13;

}

if(key3==0)

if(key3==0)

while(key3==0);

break;

gotoxy(2,5);

if(alarmx1==1){alarmx1=2;

else{alarmx1=1;

On"

}break;

if(max>

16){max--;

gotoxy(2,5);

if(min>

16){min--;

ff=9;

about();

if(key4==0)

if(key4==0)

while(key4==0);

if(max<

60){max++;

if(min<

60){min++;

voiddisp_temp()

if(count==10)

{

count=0;

ReadTemp();

temp_to_str();

gotoxy(1,3);

print(TempBuffer);

temp_to_zb();

alarm(alarmx);

voidcheck_ds18b20()

if(presence==1)

alarmx=3;

alarmx=0;

}

main()

init();

show_logo();

show_zb();

EA=1;

while

(1)

check_ds18b20();

key();

disp_temp();

voidtimer0()interrupt1

count++;

if(count>

10)

ds18b20.h温度传感器相关的程序

//****************************************

//ds18b20子程序模块

 

#defineuintunsignedint

#defineucharunsignedchar

sbitDQ=P2^7;

//温度传送数据IO口

uchartemp_value,temp1_value,temp_h,temp_l,presence;

//temp_value温度值正数部分temp1_value温度值小数部分

ucharTempBuffer[8];

/***********ds18b20延迟子函数(晶振12MHz)*******/

voiddelay_18B20(unsignedinti)

while(i--);

/**********ds18b20初始化函数**********************/

Init_DS18B20(void)

DQ=1;

//DQ复位

delay_18B20(8);

//稍做延时

DQ=0;

//单片机将DQ拉低

delay_18B20(40);

//精确延时大于480us

DQ=1;

//拉高总线

delay_18B20(7);

presence=DQ;

//稍做延时后如果x=0则初始化成功x=1则初始化失败

delay_18B20(10);

return(presence);

//返回信号,0=presence,1=nopresence

/***********ds18b20读一个字节**************/

ucharReadOneChar(void)

uchari=0;

uchardat=0;

for(i=8;

i>

0;

i--)

DQ=0;

//给脉冲信号

dat>

=1;

DQ=1;

if(DQ)

dat|=0x80;

delay_18B20(4);

return(dat);

/*************ds18b20写一个字节****************/

voidWriteOneChar(uchardat)

uchari=0;

for(i=8;

i>

i--)

DQ=dat&

0x01;

delay_18B20(5);

dat>

/**************读取ds18b20当前温度************/

voidReadTemp(void)

uchart;

Init_DS18B20();

WriteOneChar(0xCC);

//跳过读序号列号的操作

WriteOneChar(0x44);

//启动温度转换

delay_18B20(100);

//thismessageisweryimportant

//跳过读序号列号的操作

WriteOneChar(0xBE);

//读取温度寄存器等(共可读9个寄存器)前两个就是温度

delay_18B20(50);

temp_l=ReadOneChar();

//读取温度值低位

temp_h=ReadOneChar();

//读取温度值高位

t=temp_h&

0xf8;

if(t)

TempBuffer[0]='

TempBuffer[1]='

-'

temp_value=temp_h<

4;

temp_value+=(temp_l&

0xf0)>

temp_value=~temp_value+1;

temp1_value=~temp_l&

0x0f;

temp1_value=temp_l&

TempBuffer[1]=temp_value/100+'

//百位

if(TempBuffer[1]=='

1'

TempBuffer[1]='

/**************温度数据转换成液晶字符显示************/

voidtemp_to_str()

{

TempBuffer[2]=temp_value%100/10+'

//十位

TempBuffer[3]=temp_value%10+'

//个位

TempBuffer[4]='

TempBuffer[5]=temp1_value*625/1000%10+'

TempBuffer[6]=temp1_value*625/100%10+'

TempBuffer[7]=temp1_value*625/10%10+'

//TempBuffer[8]=temp1_value*625%10+'

TempBuffer[8]='

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高中教育 > 语文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1