?? 18b20b.h
字號:
#include<intrins.h>
sbit DS18b20_DQ1 = P2^1;
sbit DS18b20_DQ2 = P2^2;
sbit DS18b20_DQ3 = P2^3;
unsigned char step=0,sub_step_r=16,sub_step_w=16;
unsigned int dat1,dat2,dat3,tempr1,tempr2,tempr3;
bit presence=0;//for 18b20 if 0 error
bit flag=1;
void initial_DS_18b20()
{
ET1=1;
EA=1;
TMOD=TMOD|0x10;
TR1=1;
}
void DS_18b20() interrupt 3 using 1///from here to case about 25 cycles
//less time to execute case large code
{
unsigned int temp;
bit temp_b;
TR1=0;
if(step==3)
{
if(flag)
{
temp=52292;//0xcc 44
if(sub_step_w)
{
DS18b20_DQ1=1;DS18b20_DQ2=1;DS18b20_DQ3=1;
DS18b20_DQ1=0;DS18b20_DQ2=0;DS18b20_DQ3=0;
//P2=P2&0xf1;equal with the last sentence
temp_b=temp&0x01;
DS18b20_DQ1=temp_b;DS18b20_DQ2=temp_b;DS18b20_DQ3=temp_b;
temp>>=1;
sub_step_w--;
TH1=0xff;TL0=0xeb;//delay 20
TR1=1;
return();
}
flag=0;
sub_step_w=16;
step=0;
return();
}
else
{
temp=52414;//0xcc be
if(sub_step_w)
{
DS18b20_DQ1=1;DS18b20_DQ2=1;DS18b20_DQ3=1;
DS18b20_DQ1=0;DS18b20_DQ2=0;DS18b20_DQ3=0;
//P2=P2&0xf1;equal with the last sentence
temp_b=temp&0x01;
DS18b20_DQ1=temp_b;DS18b20_DQ2=temp_b;DS18b20_DQ3=temp_b;
temp>>=1;
sub_step_w--;
TH1=0xff;TL0=0xeb;//delay 20
TR1=1;
return();
}
step++;
return();
}
}
if(step==4)
{
if(sub_step_r)
{
DS18b20_DQ1=1;DS18b20_DQ2=1;DS18b20_DQ3=1;
DS18b20_DQ1=0;DS18b20_DQ2=0;DS18b20_DQ3=0;
DS18b20_DQ1=1;DS18b20_DQ2=1;DS18b20_DQ3=1;
if(DS18b20_DQ1)dat1|=0x80;
if(DS18b20_DQ2)dat2|=0x80;
if(DS18b20_DQ3)dat3|=0x80;
dat1>>=1;dat2>>=1;dat3>>=1;
sub_step_r--;
TH1=0xff;TL1=0xdc;
TR1=1;
return();
}
flag=1;step=0;sub_step_r=16;
TH1=0;TL1=0;
TR1=1;
tempr1=dat1;tempr2=dat2;tempr3=dat3;
return();
}
switch(step)
{
////////////initial
case 0:
TH1=0xfe;TL1=0x1f;//delay 480
DS18b20_DQ1=1;DS18b20_DQ2=1;DS18b20_DQ3=1;
DS18b20_DQ1=0;DS18b20_DQ2=0;DS18b20_DQ3=0;
TR1=1;
step++;return();
case 1:
TH1=0xff;TL1=0xdc;//delay 70-35
DS18b20_DQ1=1;
DS18b20_DQ2=1;
DS18b20_DQ3=1;
TR1=1;
step++;return();
case 2:
TH1=0xfe;TL1=0x5b;TR1=1;//delay 410
presence=~(DS18b20_DQ1|DS18b20_DQ2|DS18b20_DQ3);
step++;return();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -