代码一:Timer_A触发转换
1 #include <msp430x14x.h> 2 void main() 3 { 4 WDTCTL = WDTPW + WDTHOLD; 5 P6SEL |= BIT0; 6 TACTL |= TASSEL_2 + MC_2; 7 TACCTL1 = OUTMOD_3; 8 TACCR1 = 0X0FFF; 9 ADC12CTL0 = ADC12ON + SHT0_2; 10 ADC12CTL1 = SHS_1 + SHP; 11 while(1) 12 { 13 ADC12CTL0 |= ENC; 14 ADC12CTL0 |= ADC12SC; 15 while((ADC12IFG & ADC12BUSY) == 0); 16 ADC12CTL0 &= ~ENC; 17 } 18 }
代码二:ADC12序列通道多次转换
1 #include <msp430x14x.h> 2 #define uint unsigned int 3 #define uchar unsigned char 4 5 uint results0; 6 uint results1; 7 uint results2; 8 uint results3; 9 10 void int_clk() 11 { 12 BCSCTL1 &= ~XT2OFF; 13 BCSCTL2 |= SELS + SELM1; 14 do 15 { 16 IFG1 &= ~OFIFG; 17 for(int i=0;i<100;i++) 18 _NOP(); 19 }while((IFG1 & OFIFG)==1); 20 IFG1 &= ~OFIFG; 21 } 22 23 void int_adc() 24 { 25 P6SEL |= 0X0F; 26 ADC12CTL0 = ADC12ON + MSC + SHT0_2 + REFON + REF2_5V; 27 ADC12CTL1 = SHP + CONSEQ_3; 28 ADC12MCTL0 = INCH_0; 29 ADC12MCTL1 = INCH_1; 30 ADC12MCTL2 = INCH_2; 31 ADC12MCTL3 = INCH_3; 32 ADC12IE = 0X08; 33 ADC12CTL0 |= ENC; 34 } 35 #pragma vector=ADC_VECTOR 36 __interrupt void ADC12_ISR() 37 { 38 results0 = ADC12MEM0; 39 results1 = ADC12MEM1; 40 results2 = ADC12MEM2; 41 results3 = ADC12MEM3; 42 } 43 void main() 44 { 45 WDTCTL = WDTPW + WDTHOLD; 46 int_clk(); 47 int_adc(); 48 _EINT(); 49 ADC12CTL0 |= ADC12SC; 50 }
时间: 2024-10-29 19:09:57