0

私はPIC-Webのサーミスタを使用して、プロジェクトの部屋の温度を読み取ります。私はそれを理解していることを示すためにコードにコメントする必要があります。私はコードの最初の部分を理解していますが(私は思う)、2番目の部分はそれほど理解していません。これはコードです:

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

1 に答える 1

2

これは、条件付きコンパイル ディレクティブを使用して 2 つの異なるアーキテクチャに対して定義されます。

さらに調べる必要がある部分は次のとおりです。

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

私は PIC ファミリに詳しくありませんが、PIC18 コントローラの ADC 設定が他の PIC と異なるかどうかを確認する必要があります。

__18CXXシンボルはおそらくコンパイラによって自動的に定義されます。コンパイル中に正しいコードが使用されるように、目的のターゲット デバイスの設定を見つけることができる場合があります。

于 2012-06-21T11:34:52.947 に答える