كود:
#include "LCD.h"
#include <math.h>
void DisplayTemperature(void)
{
const char Voltage[] = "Temperature Sensor";
const float R3 = 10000, R2 = 10000, Vcc = 5.0; /* Circuit Constants */
unsigned int ADC_Value = 0;
float VoltageOutput = 0.0;
unsigned int TemperatureResistance = 0;
const float A = 28.54,
B = 158.5,
C = 474.5,
D = 319.85,
R25 = 980.0; /* Resistance at 25 degree C */
float ResistanceRatio = 0.0, /* RT/R25 */
Temperature = 0.0; /* in degree C */
ClearScreen_LCD();
WriteString_LCD(Voltage);
MoveCursorToPosition(SecondLine);
ADC_Value = SamplingAndConversionADC(); /* Sampling */
VoltageOutput = ((float)(ADC_Value))* 0.0048828; /* 0.0048828 = 5/1024 */
TemperatureResistance = (unsigned int)(((R2 * Vcc) - ((R2 + R3) * VoltageOutput)) / (VoltageOutput - Vcc));
ResistanceRatio = TemperatureResistance/R25;
Temperature = (A * powf(ResistanceRatio, 3.0) - (B * powf(ResistanceRatio, 2.0)) \
+ ((C * ResistanceRatio) - D));
WriteLongAsFloatUptoFiveFigures((signed long) Temperature);
WriteData_LCD(' ');
WriteData_LCD(223); /* Printing degree sign on LCD*/
WriteData_LCD('C');
}