#include "msp430g2231.h"
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE; // 转换时钟选择 ADC10ON(打开ADC10), interrupt enabled(使能中断)
ADC10CTL1 = INCH_1; // input A1(选择输入通道A1,对应P1.1口)
ADC10AE0 |= 0x02; // PA.1 ADC option select (使能P1.1模拟输入)
P1DIR |= 0x01; // Set P1.0 to output direction (P1.0为输出模式)
for (;;)
{
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start (ADC10开始采样转换)
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit (开总中断,低功耗模式)
/*******翻转P1.0口状态******/
if (ADC10MEM < 0x1FF)
P1OUT &= ~0x01; // Clear P1.0 LED off
else
P1OUT |= 0x01; // 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)
}
呵呵,又是抄的官方例程,结合手册分析起来不是很难,由于我手头没有什么模拟输出设备,所以该程序下载到板子上的效果是LED0一直亮着,找一条杜邦线,一头连在板子的地端(GND),另一头接在P1.1口,LED0灭