Browsing this Thread:
1 Anonymous Users
|
溫度sensor 程式原理
|
|
新會員
Joined
: 2008/9/23 8:50 最後登入時間
: 2008/12/17 17:47
Group:
註冊會員
Level : 2 HP : 0 / 46 MP : 5 / 2130 EXP : 86
|
usbCDC範例程式有溫度sensor 程式轉換ASCLL的程式
void UpdateCelsiusASCII(void) { WORD temp; byte i; temp._word = temperature._word >> 3; if(temp.HighB.b4 == 0) { temp.HighB._byte &= 0b00011111; tempString[0] = '+'; } else { temp.HighB._byte |= 0b11100000; tempString[0] = '-'; temp._word = temp._word ^ 0xFFFF; // Negate temp._word++; }//end if
temp._word = (temp._word*10U) >> 4; // Turn into celsius xx.x /* Populate string */ for(i=4;i>0;i--) { tempString[i] = (((char)(temp._word % 10)) & 0x0F) | 0x30; temp._word /= 10; }//end for /* Turn leading zeros into spaces */ if(tempString[1] == '0') { tempString[1] = ' '; if(tempString[2] == '0') tempString[2] = ' '; }//end if /* Adjust decimal digit */ tempString[5] = tempString[4]; tempString[4]='.'; tempString[6]=0x00 ; // Null-Terminated }//end UpdateCelsiusASCII ================================== 其中temp._word = (temp._word*10U) >> 4;這行是幹麻呢?
for(i=4;i>0;i--) { tempString[i] = (((char)(temp._word % 10)) & 0x0F) | 0x30; temp._word /= 10; }//end for
這for迴圈又做了什麼事
這兩個地方我看了很久不知道是怎麼轉換的有誰知道呢?我有看了TC77的data,0.0625度c為000FH
發表於: 2008/11/13 13:22
|
|
|
Re: 溫度sensor 程式原理
|
|
資深會員
Joined
: 2004/7/23 16:25 最後登入時間
: 昨天 15:19
Group:
註冊會員
Level : 32 HP : 0 / 775 MP : 461 / 44890 EXP : 0
|
tc77 一次丟 16bit ,只有前 13bit 有用。
每個 單位 = 0.0625 ℃
所以,假設你收到 05FF -------------->你到底看不看得懂這代表幾度?
191 *0.0625 = 11.9375
191/16 = 11
1910/16= 119
0.0625 = 1/16
所以你的兩個問題 一是 *10 / 16
二是 bcd 轉換
發表於: 2008/11/13 15:06
|
|
|
Re: 溫度sensor 程式原理
|
|
新會員
Joined
: 2008/9/23 8:50 最後登入時間
: 2008/12/17 17:47
Group:
註冊會員
Level : 2 HP : 0 / 46 MP : 5 / 2130 EXP : 86
|
謝謝~我懂了
發表於: 2008/11/13 16:38
|
|
You can view topic.
你 不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.