#include <REGX52.H>
bit startds18()
{
unsigned char i;
bit a;
P3_7=1;
P3_7=0;
i = 227; //500
while (--i);
P3_7=1;
i = 34; //80
while (--i);
a=P3_7;
i = 135; //300
while (--i);
return a;
}
void sendds18(unsigned char a)
{
unsigned char b,i,j;
for(j=0;j<8;j++)
{
b=a&(0x01<<j);
P3_7=0;
i = 4; //15
while (--i);
P3_7=b;
i = 34; //80
while (--i);
P3_7=1;
}
}
unsigned char receiveds18()
{
unsigned char i,j,a=0x00;
for(j=0;j<8;j++)
{
P3_7=0;
i = 4; //15
while (--i);
P3_7=1;
if(P3_7) a=a|(0x01<<j);
i = 25;
while (--i);
P3_7=1;
}
return a;
}
void ds18start()
{
startds18();
sendds18(0xcc);
sendds18(0x44);
}
float ds18red()
{
unsigned char a,b;
float deta;
int t;
startds18();
sendds18(0xcc);
sendds18(0xbe);
a=receiveds18();
b=receiveds18();
t=(b<<8)&a;
deta=t/16.0;
return deta;
} |