不建议刚开始入门就从18B20开始,它的时序有点啰嗦。IO口线的定义要与硬件的接法一致,Keil编译软件要和谐过。LS说得对,read_18b20函数里面有错误。更正为:
unsigned char read_18b20()
{
unsigned char du_i;
unsigned char outdata_1820=0x00;
unsigned char tmp_du=0x00;
for(du_i=1;du_i<=8;du_i++)
{
DQ=1;
DQ=0;
_nop_();
_nop_(); DQ=1;
_nop_();
tmp_du=P1&0x80;
tmp_du=tmp_du<<0;
outdata_1820=outdata_1820|tmp_du;
delay1(8);
if(du_i==8)break;
outdata_1820=outdata_1820>>1;
}
return(outdata_1820);
}