|
以下是部分关键代码:
int getTmpValue()
{
unsigned int tmpvalue;
int value;
float t;
unsigned char low, high;
sendReadCmd();
low = readByte();
high = readByte();
tmpvalue = high;
tmpvalue <<= 8;
tmpvalue |= low;
value = tmpvalue;
\
t = value * 0.0625;
\
value = t * 100 + (value > 0 ? 0.5 : -0.5); //′óóú0¼ó0.5, D¡óú0¼õ0.5
return value;
}
void display(int v)
{
unsigned char count;
unsigned char datas[] = {0, 0, 0, 0, 0};
unsigned int tmp = abs(v);
datas[0] = tmp / 10000;
datas[1] = tmp % 10000 / 1000;
datas[2] = tmp % 1000 / 100;
datas[3] = tmp % 100 / 10;
datas[4] = tmp % 10;
writeComm(0xc0+3);
if(v < 0)
{
writeString("- ", 2);
}
else
{
writeString("+ ", 2);
}
if(datas[0] != 0)
{
writeData('0'+datas[0]);
}
for(count = 1; count != 5; count++)
{
writeData('0'+datas[count]);
if(count == 2)
{
writeData('.');
}
}
}
/**//*****************************DS18B20*******************************/
void main()
{
uchar table[] = " xianzaiwendu: ";
sendChangeCmd();
init();
writeComm(0x80);
writeString(table, 16);
while(1)
{
delayMs(1000); //ζè×a»»ê±¼äDèòa750msòÔéÏ
writeComm(0xc0);
display(getTmpValue());
sendChangeCmd();
}
}
...................
具体请下载附件^v^..............
|
|