日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁(yè) > 技術(shù)學(xué)院 > 熱搜器件
[導(dǎo)讀]采集完數(shù)據(jù),數(shù)據(jù)的處理方法很多,選中一種好的思路才是王道。

采集完數(shù)據(jù),數(shù)據(jù)的處理方法很多,選中一種好的思路,那才是王道!

1.

unsigned int ReadTemperature(void)

{

unsigned char a=0;

unsigned int b=0;

unsigned int t=0;

Init_DS18B20();

WriteOneChar(0xCC); // 跳過(guò)讀序號(hào)列號(hào)的操作

WriteOneChar(0x44); // 啟動(dòng)溫度轉(zhuǎn)換

DelayMs(10);

Init_DS18B20();

WriteOneChar(0xCC); //跳過(guò)讀序號(hào)列號(hào)的操作

WriteOneChar(0xBE); //讀取溫度寄存器等(共可讀9個(gè)寄存器) 前兩個(gè)就是溫度

a=ReadOneChar(); //低位

b=ReadOneChar(); //高位

b<<=8;

t=a+b;

return(t);

}

int temp;

float temperature;

ReadTempFlag=0;

temp=ReadTemperature();

temperature=(float)temp*0.0625;

2.

unsigned char temp;

unsigned char temp1;

void Temp_test(void)

{

uchar low,high;

Ds18b20Initial();

Ds18b20Write(0xcc);

Ds18b20Write(0x44);

// Ds18b20Delay(5);

Ds18b20Initial();

Ds18b20Write(0xcc);

Ds18b20Write(0xbe);

low = Ds18b20Read();//低位

high = Ds18b20Read();//高位

temp = high;

temp <<=8;

temp |= low;

temp = ((low >> 4)+((high & 0x07)*16));

temp1 = low&0x0f; //這就是小數(shù)位,不需要轉(zhuǎn)成float,然后又要轉(zhuǎn)回int型處理

}

int temp;

float temperature;

temperature=(float)

Temp_shi=temp/10;

Temp_ge=temp;

Temp_xiao=(temp1*625+500)/1000;//為了留一位小數(shù),并實(shí)現(xiàn)四舍五入

總結(jié):之前在51上做,當(dāng)程序比較多時(shí),用上float型,容易出錯(cuò);后來(lái)在cc2530上做溫度采集時(shí),為了顯示小數(shù)這一位,用了很多方法,顯示整數(shù)兩位沒(méi)有問(wèn)題,一加上小數(shù)位,就讀不出來(lái),后來(lái)在網(wǎng)上看到第2中方法的處理,它是一直用unsigned char,這種處理數(shù)據(jù)方法,對(duì)于某些場(chǎng)合,真的很好用。

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉