简体   繁体   中英

itoa and uitoa usage

I'm using PIC-Web's thermistor to read the temperature in the room for a project. I have to comment the code to show that I undersand it. I understand the first part of the code (I think) but the second not so much. This is the code:

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);

}

Can somebody explain why we use:

itoa 
else 
ADval=(WORD)ADC1BUF0
uitoa

This is defined for two different architectures using conditional compilation directives.

The parts you need to look into more are:

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

I'm not familiar with the PIC family, but you should check whether PIC18 controllers have a different ADC setup from other PICs.

The __18CXX symbol is probably defined automatically by your compiler. You may be able to find a setting for the desired target device which will cause the correct code to be used during compilation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM