MSP430 Launchpad - Internal Temperature Sensor
Code:
#include <msp430g2553.h>
int temp = 0;
int main(void){
WDTCTL = WDTPW | WDTHOLD; //stop the watchdog timer//Select 1.5 V, 64 clock cycles, enable ADC interrupt, Turn on the reference generator
ADC10CTL0 = SREF_1 + REFON + ADC10ON + ADC10SHT_3 + ADC10IE;
//Select input channel 10 and divide the clock frequency by 4
ADC10CTL1 = INCH_10 + ADC10DIV_3;
//Enable and Start conversion
ADC10CTL0 |= ENC + ADC10SC;
//Enter low power mode
__bis_SR_register(LPM0_bits + GIE);
//fetch the temperature value from ADC10MEM register
temp = ADC10MEM;
//convert it into degree celsius
temp = ((temp * 27069L - 18169625L)>>16);
return 0;
}
//ISR
#pragma vector = ADC10_VECTOR
__interrupt void adc_interrupt(void)
{
__bic_SR_register_on_exit(CPUOFF);
}
//ISR
#pragma vector = ADC10_VECTOR
__interrupt void adc_interrupt(void)
{
__bic_SR_register_on_exit(CPUOFF);
}
No comments:
Post a Comment