<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 嵌入式系統 > 設計應用 > 基于DS18B20與TMS320LF2407A的溫度測量系統

基于DS18B20與TMS320LF2407A的溫度測量系統

作者: 時(shí)間:2012-07-07 來(lái)源:網(wǎng)絡(luò ) 收藏

#define PIN_LEAVE() {DATA_PORT=DATA_PORT(~DATA_OUT)|DATA_BIT;}
/* 傳感器復位程序 */
unchar reset(void)
{ unchar retval;
unint loopindex="0";
PIN_HIGH();
nop();nop();nop();nop(); /* 延時(shí)1us*/
PIN_LOW();
for(loopindex=0;loopindex213;loopindex++){;} /*置總線(xiàn)為低電平并保持至少480us */
PIN_HIGH();
for(loopindex=0;loopindex26;loopindex++){;} /*等電阻拉高總線(xiàn)并保持15-60us */
PIN_LEAVE(); /*接受應答信號*/
nop();
if((DATA_PORT DATA_BIT) == 0x0000)
{ retval = 0; }
else
{ retval = 1; }
PIN_HIGH();
for(loopindex=0;loopindex106;loopindex++){;} /*延時(shí)60-240us */
return(retval); /*返回應答信號 */
}
/* 從傳感器中讀一個(gè)字節 */
void read_byte(unchar *ReadByte)
{
int i;
unchar temp="0";
unint loopindex="0";
PIN_HIGH();
for(i=0;i8;i++)
{
temp="temp">>1;
PIN_LOW();
nop();nop();nop();nop(); /*延時(shí)2us */
nop();nop();nop();nop();
PIN_HIGH();
for(loopindex=0;loopindex6;loopindex++){;} /* 延時(shí)14us */
PIN_LEAVE();
nop();
if((DATA_PORT DATA_BIT) == 0x0000)
{ temp="temp" 0x7F; }
else
{ temp="temp" | 0x80; }
PIN_HIGH();
for(loopindex=0;loopindex26;loopindex++){;} /* 延時(shí)60us */
}
*ReadByte=temp;
return;
}
/* 將讀得的溫度轉化為十進(jìn)制 */
float transform(unchar *T)
{
unchar temp="0";
float temprature="0";
temp=temp|(*(T+1)8);
temp=temp|*T;
if((temp0x0F800)==0x0F800)
{ temprature="0-"((~temp)+1)*0.0625; }
else
{ temprature="temp"*0.0625; }
return(temprature);
}
/* 讀取溫度主函數,返回十進(jìn)制溫度數 */
float read_temp()
{
Unchar buff[2];
float temprature="0";
unint loopindex="0";
while (reset()==1){}; /* 復位等待從機應答 */
write_byte(0xCC); /* 忽略ROM匹配 */
write_byte(0x44); /* 發(fā)送溫度轉化命令 */
for(loopindex=0;loopindex65535;loopindex++){;} /* 延時(shí)300ms,等待數模轉換 */
for(loopindex=0;loopindex65535;loopindex++){;}
while(reset()==1){}; /* 再次復位,等待從機應答 */
write_byte(0xCC); /* 忽略ROM匹配 */
write_byte(0xBE); /* 發(fā)送讀溫度命令 */
read_byte(buff); /* 讀出溫度低8位 */
read_byte(buff+1); /* 讀出溫度高8位 */
temprature="transform"(buff);
PIN_HIGH(); /* 釋放總線(xiàn) */
return(temprature);
}

  4 結束語(yǔ)

  是一款非常優(yōu)秀的單總線(xiàn)數字式傳感器。硬件設計簡(jiǎn)單,運行可靠。通過(guò)分析C語(yǔ)言編譯后的匯編語(yǔ)言可以很明確的計算出軟件延時(shí)的時(shí)間,從而滿(mǎn)足單線(xiàn)總線(xiàn)通訊的時(shí)序要求,從而可以出色的完成DSP通訊的軟件設計。

  5 本文創(chuàng )新點(diǎn)有兩個(gè):

  1、通過(guò)C編譯器編譯出來(lái)的相應的C語(yǔ)言的延時(shí)程序,從而得到其對應的匯編語(yǔ)言,再通過(guò)定時(shí)器計時(shí),能夠知道單指令周期的時(shí)間,從而能夠精確的計算出軟件延時(shí)程序的延時(shí)時(shí)間。

  2、通常都是與單片機配合使用的,而本文則詳細的介紹了DS18B20與DSP的結合使用方法,其區別主要是在端口的操作上和延時(shí)的控制上。


上一頁(yè) 1 2 下一頁(yè)

關(guān)鍵詞: DS18B20 TMS320LF2407A 溫度測量

評論


相關(guān)推薦

技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>