msp430xg46x_adc12_02.c

来自「MSP430FG461x.zip c语言 例程打包」· C语言 代码 · 共 53 行

C
53
字号
//******************************************************************************
//   MSP430xG461x Demo - ADC12, Using the Internal Reference
//
//   This example shows how to use the internal reference of the ADC12.
//   It uses the internal 2.5V reference and performs a single conversion
//   on channel A0. The conversion results are stored in ADC12MEM0. Test by
//   applying a voltage to channel A0, then setting and running to a breakpoint
//   at "__no_operation()".
//   To view the conversion results, open a register window in Debugger and
//   view the contents of ADC12MEM0.
//   ACLK = 32kHz, MCLK = SMCLK = default DCO 1048576Hz, ADC12CLK = ADC12OSC
//
//
//                MSP430xG461x
//              ---------------
//             |            XIN|-
//             |               | 32kHz
//      Vin -->|P6.0/A0    XOUT|-
//             |               |
//
//
//   A. Dannenberg/ M. Mitchell
//   Texas Instruments Inc.
//   October 2006
//   Built with IAR Embedded Workbench Version: 3.41A
//******************************************************************************
#include "msp430xG46x.h"

volatile unsigned int i;

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog
  P6SEL |= 0x01;                            // Enable A/D channel A0
  ADC12CTL0 = REFON + REF2_5V + ADC12ON + SHT0_2;
                                            // turn on 2.5V ref, set samp time
  ADC12CTL1 = SHP;                          // Use sampling timer
  ADC12MCTL0 = SREF_1;                      // Vr+=Vref+

  for (i = 0x3600; i; i--);                 // Delay for needed ref start-up.
                                            // See datasheet for details.
  ADC12CTL0 |= ENC;                         // Enable conversions


  while (1)
  {
    ADC12CTL0 |= ADC12SC;                   // Start conversions
    while (!(ADC12IFG & 0x0001));           // Conversion done?
    ADC12MEM0;                              // Access result
    __no_operation();                       // SET BREAKPOINT HERE
  }
}

⌨️ 快捷键说明

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