Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- temperature read_internal_temperature(void)
- {
- temperature temp_sensor;
- ADC10CTL1 |= INCH_10 | ADC10DIV_7 | ADC10SSEL_3;
- ADC10CTL0 |= REFON | ADC10ON | SREF_1 | ADC10SHT_3;// | REF2_5V;
- delay(480);
- ADC10CTL0 |= ENC | ADC10SC;
- delay(48);
- while (ADC10CTL1 & ADC10BUSY) {};
- ADC10CTL0 &= ~ENC;
- ADC10CTL0 &= ~(REFON | ADC10ON);
- // (raw * 0.0024414 - 0.986) / 0.00355
- unsigned long temp_tmp;
- int temp_sensor_int;
- div_t temp_sensor_main_digits;
- //temp_tmp = (ADC10MEM - 404) * 11;
- temp_tmp = (ADC10MEM - 673) * 423;
- //temp_sensor_int = temp_tmp / 16;
- temp_sensor_int = temp_tmp / 1024;
- temp_sensor.negative = 0;
- if (temp_sensor_int < 0) {
- temp_sensor.negative = 1;
- }
- temp_sensor_main_digits = div(temp_sensor_int, 10);
- //temp_tmp = temp_tmp * 10 / 16;
- temp_tmp = temp_tmp * 10 / 1024;
- temp_sensor.digit_3 = div(temp_tmp, 10).rem;
- temp_sensor.digit_1 = temp_sensor_main_digits.quot;
- temp_sensor.digit_2 = temp_sensor_main_digits.rem;
- return temp_sensor;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement