|
DS18B20的初始化,讀字節(jié),寫字節(jié)已省略
unsigned int ReadTemperature(void) //讀取溫度
{
uchar a=0,b=0;
unsigned int t=0;
Init_DS18B20();
WriteOneChar(0xcc); //跳過讀序號列表的操作
WriteOneChar(0x44); //啟動溫度轉(zhuǎn)換
time_delay(); //延時10ms
Init_DS18B20();
WriteOneChar(0xcc);
WriteOneChar(0xbf); //讀取溫度
a=ReadOneChar(); // 低位
b=ReadOneChar(); // 高位
b<<=8;
t=a+b;
t=t*0.0625*10+0.5;
return(t);
}
問題:我想讓DS18B20讀到的溫度當(dāng)超過80時進行報警,那我該如何設(shè)置這個判斷條件?
為什么我這樣不對:
void Alarm(void)
{
unsigned int temp,;
temp=ReadTemperature();
if(temp>80)
{
Alarm_LED=0;
Alarm=0;
}
}為什么我自proteus上我把溫度調(diào)在80以下還是執(zhí)行了報警
|
|