下面是ADC12的序列通道单次转化的比如:
//ADC12序列通道单次
#include<msp430x14x.h>
unsigned ADC_Result1,ADC_Result2;
void ADC12_Init();
void main(){
WDTCTL = WDTPW + WDTHOLD;
ADC12_Init();
ADC12CTL0 |= ADC12SC;
_BIS_SR(GIE);
while(1);
}
//
void ADC12_Init(){
P6DIR &= (~BIT6 + ~BIT7);//设置状况为输入态
P6SEL |= BIT6 + BIT7;//挑选端口的第二功用
ADC12CTL0 = ADC12ON + SHT0_6 + REFON + MSC; //
ADC12CTL0 &= ~REF2_5V; //
ADC12CTL1 = SHP + CONSEQ_1 + SHS_0;//
ADC12MCTL6 = SREF_1 + INCH_6;
ADC12MCTL7 = SREF_1 + INCH_7 + EOS;
ADC12IE = BIT7;
ADC12CTL0 |= ENC;
}
#pragma vector=ADC_VECTOR
__interrupt void ADC12ISR(){
ADC_Result1 = ADC12MEM6;
ADC_Result2 = ADC12MEM7;//此处可观察到值
ADC12CTL0 |= ADC12SC;
}