2012-06-21 70 views
0

我正在使用PIC-Web的熱敏電阻來讀取房間內的溫度以進行項目。我必須對代碼發表評論,以表明我不介意。我理解代碼的第一部分(我認爲),但第二部分並不那麼重要。這是代碼:itoa和uitoa的用法

void HTTPPrint_temp(void) 
{ 
// We define TempString as a string of bytes 
BYTE TempString[8]; 

// We define SP_String as a string of bytes 
BYTE SP_String[8]; 

// We define temperature and tmp as integers 
int temperature, tmp; 

// We define r and z as floating point number 
float r, z; 

#if defined(__18CXX) 
// We utilize channel 9 for the A/D conversion 
ADCON0bits.CHS0 = 1; 
ADCON0bits.CHS1 = 0; 
ADCON0bits.CHS2 = 0; 
ADCON0bits.CHS3 = 1; 

// We wait for the A/D conversion to end 
ADCON0bits.GO = 1; 
while(ADCON0bits.GO); 

// We convert the 10-bit value into an ASCII string 
tmp = (WORD)ADRES; 

// We read and calculate the value of the temperature 
r = ((1024.0*10000.0)/(float)tmp)-10000.0; 

// We calculate the value in degrees Celsius 
temperature = 4100.0/log(r/0.0111182) - 273.15; 

// We alocate the value of the temperature to TempString 
itoa(temperature, TempString); 

#else 

// Don't know? 
ADval = (WORD)ADC1BUF0; 

// Don't know 
uitoa(ADval, (BYTE*)AN0String); 

#endif 

// We open up a socket and send the data to the website 
TCPPutString(sktHTTP, TempString); 

} 

有人可以解釋爲什麼我們使用:

itoa 
else 
ADval=(WORD)ADC1BUF0 
uitoa 
+4

首先你需要了解這段代碼是在什麼語言。你標記了你的問題[c#] [C++] [c],它是哪一個? – BoltClock

+2

@BoltClock對我來說看起來像C。 –

+0

我的恥辱我真的不知道 –

回答

2

這是使用條件編譯指令兩種不同的架構定義。

你需要尋找到更多的部分是:

#if defined(__18CXX) 
    // code for PIC18 
#else 
    // code for other 
#endif 

我不熟悉的PIC系列,但你應該檢查PIC18控制器是否有其他太平洋島國不同的ADC設置。

__18CXX符號可能由您的編譯器自動定義。您可能能夠找到所需目標設備的設置,這將導致在編譯過程中使用正確的代碼。