msp430的一些常用的C語(yǔ)言控制程序---ADC12(3)
//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);//設(shè)置狀態(tài)為輸入態(tài)
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;
}
評(píng)論