|
#include<intrins.h>
#ifndef _DS18B20_H_
#define _DS18B20_H_
sbit DS=P2^4;
/*Ñóê±2ù×÷*/
void DS18B20_Delay(unsigned int x)
{
unsigned int a,b;
for(a=x;a>0;a--)
for(b=10;b>0;b--);
}
/*¸′λ2ù×÷*/
void DS18B20_Reset(void) //send reset and initialization command
{
unsigned int i;
DS=0;
i=103;
while(i>0)i--;
DS=1;
i=4;
while(i>0)i--;
}
/*¶áè¡ò»Î»êy¾Y*/
bit DS18B20_BitRead()
{
unsigned int i;
bit dat;
DS=0; _nop_();
DS=1; _nop_(); _nop_();
dat=DS;
i=8;while(i>0)i--;
return (dat);
}
/*¶áè¡ò»¸ö×Ö½ú*/
unsigned char DS18B20_ByteRead()
{
unsigned char i,j,dat;
dat=0;
for(i=1;i<=8;i++)
{
j=DS18B20_BitRead();
dat=(j<<7)|(dat>>1);
}
return(dat);
}
|
|