test44x_adc12_06.c

来自「iar开发环境 msp430单片机的一些示例程序 有adc flash lcd 」· C语言 代码 · 共 55 行

C
55
字号
//******************************************************************************
//  MSP430-TEST44X Demo - ADC12, Repeated Single Channel Conversions
//
//  This example shows how to perform repeated conversions on a single channel
//  using "repeat-single-channel" mode.  AVcc is used for the reference and 
//  repeated conversions are performed on Channel A0. Each conversion result 
//  is moved to an 8-element array called results[].  Test by applying a 
//  voltage to channel A0, then running. To view the conversion results, open a
//  watch window and view 'results.' 
// 
//
//               MSP430F449
//             ---------------
//            |               |
//            |      A0 (P6.0)|<---- Vin
//            |               |
//
//
//  Yang Rui
//  Lierda, Inc
//  NOVEMBER 2003
//  Built with IAR Embedded Workbench Version: 1.26B
//******************************************************************************

#include          "msp430x44x.h"        // Standard Equations

#define   Num_of_Results   8

static unsigned int results[Num_of_Results];  // Needs to be global in this
                                              // example. Otherwise, the
                                              // compiler removes it because it 
                                              // is not used for anything.

void main(void)
{ 
  WDTCTL = WDTPW+WDTHOLD;               // Stop watchdog timer
  P6SEL |= 0x01;                        // Enable A/D channel A0
  ADC12CTL0 = ADC12ON+SHT0_8+MSC    ;   // Turn on ADC12, set sampling time
  ADC12CTL1 = SHP+CONSEQ_2;             // Use sampling timer, set mode
  ADC12IE = 0x01;                       // Enable ADC12IFG.0
  ADC12CTL0 |= ENC;                     // Enable conversions
  _EINT();                              // Enable interrupts  
  ADC12CTL0 |= ADC12SC;                 // Start conversion
  _BIS_SR(LPM0_bits);                   // Enter LPM0
}


interrupt[ADC_VECTOR] void ADC12ISR (void)
{
  static unsigned int index = 0;
   
  results[index] = ADC12MEM0;           // Move results
  index = (index+1)%Num_of_Results;     // Increment results index, modulo
}
 

⌨️ 快捷键说明

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