#include <msp430.h>
unsigned int ADC_Result[13]; // 12-bit ADC conversion result array
unsigned char i;
#define CALADC_15V_30C *((unsigned int *)0x1A1A) // Temperature Sensor Calibration-30 C
// See device datasheet for TLV table memory mapping
#define CALADC_15V_85C *((unsigned int *)0x1A1C) // Temperature Sensor Calibration-High Temperature (85 for Industrial, 105 for Extended)
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
// Configure ADC
// Configure ADC A1 pin
P5SEL0 |= BIT0;
P5SEL1 |= BIT0;
ADCCTL0 |= ADCSHT_8 | ADCON; // ADCON, S&H=16 ADC clks
ADCCTL1 |= ADCSHP | ADCCONSEQ_1 | ADCSSEL_1; // ADCCLK = MODOSC; sampling timer
ADCCTL2 &= ~ADCRES; // clear ADCRES in ADCCTL
ADCCTL2 |= ADCRES_2; // 12-bit conversion results
ADCIE |= ADCIE0; // Enable ADC conv complete interrupt
ADCMCTL0 = ADCINCH_12 | ADCSREF_1; // A1 ADC input select; Vref=2.5V
// Configure reference module
PMMCTL0_H = PMMPW_H; // Unlock the PMM registers
PMMCTL2 |= INTREFEN | REFVSEL_2 | TSENSOREN ; // Enable internal 2.5V reference
__delay_cycles(400); // Delay for reference settling
_EINT();
while(1)
{
while(ADCCTL2 & ADCBUSY); // Wait if ADC core is active
ADCCTL0 |= ADCENC | ADCSC; // Sampling and conversion start
__delay_cycles(5000);
}
}
// ADC interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ADC_VECTOR
__interrupt void ADC_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC_VECTOR))) ADC_ISR (void)
#else
#error Compiler not supported!
#endif
{
volatile float temp;
volatile float IntDegF;
volatile float IntDegC;
switch(__even_in_range(ADCIV,ADCIV_ADCIFG))
{
case ADCIV_NONE:
break;
case ADCIV_ADCOVIFG:
break;
case ADCIV_ADCTOVIFG:
break;
case ADCIV_ADCHIIFG:
break;
case ADCIV_ADCLOIFG:
break;
case ADCIV_ADCINIFG:
break;
case ADCIV_ADCIFG:
ADC_Result[i] = ADCMEM0;
if(i == 0)
{
i =12;
temp =ADC_Result[11];
// Temperature in Celsius
// The temperature (Temp, C)=
IntDegC = (temp-CALADC_15V_30C)*(85-30)/(CALADC_15V_85C-CALADC_15V_30C)+30;
// Temperature in Fahrenheit
// Tf = (9/5)*Tc | 32
IntDegF = 9*IntDegC/5+32;
//__bic_SR_register_on_exit(LPM3_bits); // Exit LPM3
}
else
{
i--;
}
break;
default:
break;
}
}