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

📄 msp430dayii_adc12_01.c

📁 430DAY精美手表DEMO程序和原理图
💻 C
字号:
//******************************************************************************
//  MSP-430-Day II Demo - ADC12 Sample A8 (VERef+) Set P1.0 if A0 > 0.5*AVcc 
//
//  Description; A single sample is made on A8 with reference to AVcc.  
//  Software sets ADC12SC to start sample and conversion - ADC12SC 
//  automatically cleared at EOC. ADC12 internal oscillator times sample (16x) 
//  and conversion. In Mainloop MSP430 waits in LPM0 to save power until ADC12
//  conversion complete, ADC12_ISR will force exit from LPM0 in Mainloop on
//  reti. If A8 > 0.5*AVcc, P1.0 set, else reset. 
//  
//                MSP430FG439
//             -----------------
//         /|\|              XIN|-  
//          | |                 |
//          --|RST          XOUT|-
//            |                 |
//  0-AVcc >--|A8 (VERef+)  P1.0|--> LED
//
//  M. Buccini
//  Texas Instruments, Inc
//  February 2004
//  Updated for IAR Embedded Workbench Version: 2.21B
//******************************************************************************

#include  <msp430xG43x.h>

void main(void)
{ 
  WDTCTL = WDTPW + WDTHOLD;             // Stop WDT
  FLL_CTL0 |= XCAP18PF;                 // Set load capacitance
  ADC12CTL0 = SHT0_2 + ADC12ON;         // Set sampling time, turn on ADC12
  ADC12CTL1 = SHP;                      // Use sampling timer
  ADC12IE = 0x01;                       // Enable interrupt
  ADC12MCTL0 = INCH_8;                  // Channel A8 (VERef+)
  ADC12CTL0 |= ENC;                     // Conversion enabled
  P1DIR |= 0x01;                        // P1.0 output
  
  for (;;)                              
  {
    ADC12CTL0 |= ADC12SC;               // Sampling open
    _BIS_SR(CPUOFF + GIE);              // LPM0, ADC12_ISR will force exit
  }
}

// ADC12 interrupt service routine
#pragma vector=ADC_VECTOR
__interrupt void ADC12_ISR (void)
{
    if (ADC12MEM0 < 0x7FF) 
      P1OUT &= ~0x01;                   // Clear P1.0 LED off
    else
      P1OUT |= 0x01;                    // Set P1.0 LED on
    _BIC_SR_IRQ(CPUOFF);                // Clear CPUOFF bit from 0(SR)
}

⌨️ 快捷键说明

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