请大家帮忙看看,那块有问题!!??
void rest_18b20()
{
DQ=1;
delay1(1);
DQ=0;
delay1(60);
DQ=1;
delay1(4);
// DQ=1;
delay1(6);
if(DQ==0)
// P1=0x00;
delay1(10);
else
// P1=0XFF;
delay1(10);
// DQ=1;
}
void wrte18b20_0()
{
DQ=1;
delay1(1);
DQ=0;
delay1(5);
}
void wrte18b20_1()
{
DQ=1;
delay1(1);
DQ=0;
delay1(3);
DQ=1;
delay1(4);
}
void write_18b20(unchar com)
{
unchar i;
for(i=8;i>0;i--)
{
if(com&0x01)
wrte18b20_1();
else
wrte18b20_0();
com=com>>1;
}
}
unchar read_18b20()
{
unchar x, date=0;
for(x=0;x<8;x++)
{
DQ=0;
date>>=1;
//DQ=1;
DQ=1;
if(DQ)
date|=0x80;
else
date|=0x00;
delay1(5);
}
return date;
}
void init_18b20()
{
// unchar
rest_18b20();
write_18b20(0xcc);
write_18b20(0x44);
delay(500);
rest_18b20();
write_18b20(0xcc);
write_18b20(0xbe);
delay(200);
tempL=read_18b20();
tempH=read_18b20();
tempH=(tempH<<4)|(tempL>>4);
tempL=tempL&0x0f;
if(tempH&0x80)
{
tempH=~tempH;
tempL=~tempL+0x01;
flag=1;
}
else
flag=0;
//htd();
gaowei=tempH/100+0x30;
diwei=tempH%100/10+0x30;
xswei=tempH%10+0x30;
}