test44x_adc12_09.c

来自「MSP430F449的AD转换的相关VC程序」· C语言 代码 · 共 46 行

C
46
字号


#include          "msp430x44x.h" // Standard Equations

static unsigned int ADCresult; 
static unsigned long int DegC, DegF;

void main(void)
{ 
  unsigned int i;
  WDTCTL = WDTPW+WDTHOLD;               // Stop watchdog timer
  ADC12CTL0 = ADC12ON+REFON+REF2_5V+SHT0_6; // Setup ADC12, ref., sampling time
  ADC12CTL1 = SHP;                      // Use sampling timer
  ADC12MCTL0 = INCH_10+SREF_1;          // Select channel A10, Vref+
  ADC12IE = 0x01;                       // Enable ADC12IFG.0

  for (i=0; i<0x3600; i++)              // Delay for reference start-up
  {
  }

  ADC12CTL0 |= ENC;                     // Enable conversions
  _EINT();                              // Enable interrupts

  while(1)
  {
    ADC12CTL0 |= ADC12SC;               // Start conversion
    _BIS_SR(LPM0_bits);                 // Enter LPM0

//  DegC = (Vsensor - 986mV)/3.55mV
//  Vsensor = (Vref)(ADCresult)/4095)
//  DegC -> ((ADCresult - 1615)*704)/4095
    DegC = ((((long)ADCresult-1615)*704)/4095);
    DegF = ((DegC * 9/5)+32);           // Calculate DegF
    _NOP();                             // SET BREAKPOINT HERE
  }
}

interrupt[ADC_VECTOR] void ADC12ISR (void)
{
  ADCresult = ADC12MEM0;                // Move results, IFG is cleared
  _BIC_SR_IRQ(LPM0_bits);               // Clear LPM0
}



⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?