某项目的部分函数,根据情况改写吧
int readTempDS18B20(bit T)
{
unsigned char tempL,tempH;
unsigned int x;
P3_3 = 1;
P3_4 = 1;
DS_Rest();
OWWriteByte(0xcc); //跳过ROM
OWWriteByte(0x44); //启动温度转换
SetDatOut(); IO转换 忽略
wait(SYSTIM); 1秒
SetDatIn(); IO转换 忽略
DS_Rest();
OWWriteByte(0xcc); //跳过ROM
OWWriteByte(0xbe); //读数据
tempL=OWReadbyte();
tempH=OWReadbyte();
P3_3 = 0;
P3_4 = 0;
x=((unsigned int)tempH<<8)|tempL;
if(T) return((int)x*10/16);
return((int)x);
}
|