AD单通道采样成功了
但是两个通道却不可以
利用查询模式 不用中断模式
书上如是说:
[1]在CONSEQ=0(单通道单次转换)的情况下,当ADC12BUSY=1时, ENC=0则会结束转换进程,并且得到错误结果。 [2]在CONSEQ≠0(非单通道单次转换)的情况下,当 ADC12BUSY=1时, ENC=0则转换正常结束,得到正确结果
[code]
void ADC_init(void) { P1SEL |= (BIT0|BIT1); ADC10CTL0 = SREF_1 + REFON + ADC10ON; // ADC10AE0 |= (BIT0|BIT1); // P1.0 ADC option select ADC10CTL1 = ADC10SSEL_2+CONSEQ_1; //MCLK Sequence-of-channels }
void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT P1DIR |= (BIT6); P2DIR |= 0xff; P1OUT&= ~BIT6; P2OUT&=0X00; ADC_init(); result1=0; result2=0; ADC10CTL1 &=~INCH_1; ADC10CTL1 |= INCH_0; ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start while (ADC10CTL1 & ADC10BUSY); // ADC10BUSY?
ADC10CTL0 &=(~ENC); result1=ADC10MEM ; ADC10CTL1 &=~INCH_0; //ADC10MEM=0; ADC10CTL1 |= INCH_1; ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start while (ADC10CTL1 & ADC10BUSY); // ADC10BUSY? ADC10CTL0 &=(~ENC); result2=ADC10MEM ; if(result1>0) {P2OUT |= BIT1; } if(result2>0) { P1OUT |= BIT6; }
while(1) { } }
[code]
我是想利用A0 A1通道采样两个电压 一个高一个低 正好两个灯一亮一灭 可是事与愿违 两个灯都不亮
|