msp430xg46x_compa_04.c

来自「TI提供的MSP430开发例程,适合初学者练习各个功能模块的使用」· C语言 代码 · 共 41 行

C
41
字号
//******************************************************************************
//   MSP430xG46x Demo - Comparator A, Poll input CA0, result in P5.1
//
//   Description: The voltage at pin CA0 (Vcompare) is compared with reference
//   voltage of diode ref.  LED is toggled when Vcompare crosses the ref voltage.
//
//
//                 MSP430xG461x
//             -----------------
//         /|\|                 |
//          | |                 |
//          --|RST           CA0|<--Vcompare
//            |                 |
//            |                 |
//            |             P5.1|-->LED
//
//  K. Quiring/ M. Mitchell
//  Texas Instruments Inc.
//  October 2006
//  Built with IAR Embedded Workbench Version: 3.41A
//******************************************************************************
#include  <msp430xG46x.h>

void main(void)
{
  WDTCTL = WDTPW+WDTHOLD;                   // Stop WDT
  FLL_CTL0 |= XCAP14PF;                     // Configure load caps

  CACTL1 = CAON+CAREF_3+CARSEL;             //Enable comp, ref = Diode ref
  CACTL2 = P2CA0;                           // Pin to CA0

  P5DIR |= 0x002;                           // P5.1 = output direction
  P2SEL |= 0x040;                           // P2.6 = CAOUT

  while(1)
    if (CACTL2&0x01)
      P5OUT |= 0x002;                       // Set LED if result =1
    else
      P5OUT &= ~0x002;                      // Set LED if result =1
}

⌨️ 快捷键说明

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