我想调G2板子上的ADC10,写了这个程序,从P1.1输入,当输出超过一定值P1.0灯灭、
#include "msp430g2231.h"
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC10CTL0 = SREF_0+ADC10SHT_2 + ADC10ON + ADC10IE+REFON; // ADC10ON, interrupt enabled
ADC10CTL1=INCH_1+CONSEQ_0;
ADC10AE0 |= BIT1 ; // P2.0 ADC option select
P1DIR |= BIT0; // Set P1.0 to output direction
while(1)
{
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
if (ADC10MEM < 0x1FF)
P1OUT |= BIT0; // Clear P1.0 LED off
else
P1OUT &= ~BIT0; // Set P1.0 LED on
}
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
} |