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

📄 fet440_adc12_11.c

📁 MSP430F43x, MSP430F44x.zip c语言 例程
💻 C
字号:
//******************************************************************************
//  MSP-FET430P440 Demo - ADC12, Sample A10 Temp and Convert to oC, TA1 Trigger
//
//  Description: Use the ADC12's integrated temperature sensor to measure
//  temperature. Sample time is set for 125 ADC12CLK cycles to allow 30us for
//  the integrated temperature sensor (see datasheet). ADC12 is operated in
//  repeat-single-channel mode with the sample and convert trigger sourced
//  from Timer_A CCR1. Timer_A is configured for continuous mode and is clocked
//  by SMCLK. TA1 is set for toggle mode triggering the ADC12 every 125ms.
//  The ADC12MEM0_IFG bit set at the end of each conversion triggers an ISR.
//  Normal mode is LPM0.
//  ACLK = LFXT1 = 32768, MCLK = SMCLK = DCO = 32xACLK = 1048576Hz,
//  ADC12CLK = ADC12OSC
//  //* An external watch crystal between XIN & XOUT is required for ACLK *//	
//
//  Uncalibrated temperature measured from device to devive will vary do to
//  slope and offset variance from device to device - please see datasheet.
//
//                MSP430F449
//             -----------------
//         /|\|              XIN|-
//          | |                 | 32KHZ
//          --|RST          XOUT|-
//            |                 |
//            |A10 (Temp)   P5.1|-->LED
//
//  M. Buccini
//  Texas Instruments Inc.
//  Feb 2005
//  Built with IAR Embedded Workbench Version: 3.21A
//*****************************************************************************
#include  <msp430x44x.h>

int long temp;
int long IntDegC;

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
  P5DIR = 0x02;                             // Set P5.2 as output
  ADC12CTL1 = SHS_1 + SHP + CONSEQ_2;       // TA1, samp timer, rpt
  ADC12MCTL0 = SREF_1 + INCH_10;            // VRef+, A10
  ADC12IE = 0x01;                           // Enable ADC12MEM0 interrupt
  ADC12CTL0 = SHT0_7 + REFON + ADC12ON + ENC; // sample for 192 ADC12CLK cycles
  TACCTL1 = OUTMOD_4;                       // Toggle
  TACTL = TASSEL_2 + MC_2;                  // SMCLK, cont-mode

  while(1)
  {
    _BIS_SR(LPM0_bits + GIE);
    //  oC = ((x/4096)*1500mV)-986mV)*1/3.55mV = x*423/4096 - 278
    IntDegC = (temp - 2692) * 423;
    IntDegC = IntDegC / 4096;
    _NOP();                                 // SET BREAKPOINT HERE
  }
 }

// ADC12 Interrupt Service Routine
#pragma vector=ADC_VECTOR
__interrupt void ADC12ISR (void)
{
  temp = ADC12MEM0;                         // IFG is cleared
  _BIC_SR_IRQ(CPUOFF);                      // Exit LPM0
  P5OUT ^= 0x02;                            // Toggle LED
}

⌨️ 快捷键说明

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