/******************************************
18b20程序
******************************************/
//===============复位 ===========
void ow_reset(void)
{
uchar presence;
DQ = 0; //pull DQ line low
delay_18B20(44); //至少480微秒, leave it low for 501us
DQ = 1; // allow line to return high?
delay_18B20(3); // wait for presence18b20 36us
presence = DQ; // get presence signal // 0= DS18B20 ready, 1= busy
//if(!presence)P1_0=0;
delay_18B20(12); // wait for end of timeslot
}
//=========从总线上读取一个字节========
uint read_byte(void)
{
uchar i;
for (i=8;i>0;i--)
{
value>>=1;
DQ = 0; // pull DQ low to start timeslot
_nop_();_nop_();_nop_();_nop_();
DQ = 1; // then return high
if(DQ)
{
value|=0x80;
}
delay_18B20(4); // wait for rest of timeslot
}
return(value);
}
//===========向18B20写一个字节=================
void write_byte(char val)
{
uchar i,j;
for (i=8; i>0; i--) // writes byte, one bit at a time
{
DQ = 0; // pull DQ low to start timeslot
j++; /*延时4us*/
DQ = val&0x01;
delay_18B20(8); // hold value for remainder of timeslot
DQ = 1;
j++;
val>>=1;
}