⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fet140_adc12_07.c

📁 msp430的C语言示例 来自TI官方
💻 C
字号:
//******************************************************************************
//  MSP-FET430P140 Demo - ADC12, 重复单通道转换
//
//  Description: 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.'
//
//
//               MSP430F149
//             ---------------
//            |               |
//     Vin -->|P6.0/A0        |
//            |               |
//
//
//  M. Mitchell
//  Texas Instruments Inc.
//  Feb 2005
//  Built with IAR Embedded Workbench Version: 3.21A
//******************************************************************************

#include  <msp430x14x.h>

#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;                   // 停止看门狗
  P6SEL |= 0x01;                            // 打开A0 A/D通道输入
  ADC12CTL0 = ADC12ON+SHT0_8+MSC;           // 开ADC12模块,+采集时间分频系数n=64 +采样信号由SHI仅首次触发
  ADC12CTL1 = SHP+CONSEQ_2;                 // 使用采样定时器输出采集/转换信号SAMPCON
                			    // 单通道多次转换模式
  ADC12IE = 0x01;                           // 允许A0中断 ADC12IFG.0
  ADC12CTL0 |= ENC;                         // 允许转换
  ADC12CTL0 |= ADC12SC;                     // 开始转换
  _BIS_SR(LPM0_bits + GIE);                 // 进入LPM0,开中断总允许
}


#pragma vector=ADC_VECTOR
__interrupt void ADC12ISR (void)
{
  static unsigned int index = 0;	    //中断服务程序中的静态变量

  results[index] = ADC12MEM0;               // 移动结果
  index = (index+1)%Num_of_Results;         // 增加结果的索引,取index变量的模(余数)
}

⌨️ 快捷键说明

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