在线情况
楼主
  • 头像
  • 级别
    • 积分3
    • 经验38
    • 文章2
    • 注册2011-03-18
    ADC12通道转换~严重困扰~请高人指点
    求教高人~小弟正在做MSP430f149的ADC12采样~我想通过串口控制单片机选择采样通道~即发送数字0则A0通道开始采样~发送数字1则A1通道开始采样~以此类推~希望能够控制A0到A7八个通道的采样。但是在程序运行的时候无论我选择哪个通道~都是A0通道在采样~其他通道不起任何作用~而且在串口发送数据的时候会在有效数据后产生很多乱码~求教高人指点~感激不尽~部分程序代码如下:
    //----------------------------interrupts----------------------------------------
    #pragma vector=UART0RX_VECTOR
    __interrupt void usart0_rx (void)
    {
      command=RXBUF0;
     
       
      switch (command)
      {
      case 0:
       
        ADC12CTL0 &= ~ADC12ON;  
        ADC12CTL0 &= ~ENC;
        P6SEL |=0x01;
        ADC12IE=0x01;
        ADC12MCTL0=INCH_0;
        ADC12MCTL0 = SREF_1;
        ADC12CTL1 = CSTARTADD_0+SHP+CONSEQ_2;
        ADC12CTL0 = ADC12ON+SHT0_15+MSC+REFON+REF2_5V;
        ADC12CTL0 |= ENC;
        ADC12CTL0 |= ADC12SC;
        break;
      case 1:
       
        ADC12CTL0 &= ~ADC12ON;
        ADC12CTL0 &= ~ENC;

        P6SEL |=0x02;
        ADC12IE=0x02;
        ADC12MCTL1=INCH_1;
        ADC12MCTL1 = SREF_1;
        ADC12CTL1 = CSTARTADD_1+SHP+CONSEQ_2;
        ADC12CTL0 = ADC12ON+SHT0_15+MSC+REFON+REF2_5V;
        ADC12CTL0 |= ENC;
        ADC12CTL0 |= ADC12SC;
        break;
      case 2:
       
        ADC12CTL0 &= ~ADC12ON;
        ADC12CTL0 &= ~ENC;
        P6SEL |=0x04;
        ADC12IE=0x04;
        ADC12MCTL2=INCH_2;
        ADC12MCTL2 = SREF_1;
        ADC12CTL1 = CSTARTADD_2+SHP+CONSEQ_2;
        ADC12CTL0 = ADC12ON+SHT0_15+MSC+REFON+REF2_5V;
        ADC12CTL0 |= ENC;
        ADC12CTL0 |= ADC12SC;    
        break;
      case 3:
       
        ADC12CTL0 &= ~ADC12ON;
        ADC12CTL0 &= ~ENC;
        P6SEL |=0x08;
        ADC12IE=0x08;
        ADC12MCTL3=INCH_3;
        ADC12MCTL3 = SREF_1;
        ADC12CTL1 = CSTARTADD_3+SHP+CONSEQ_2;
        ADC12CTL0 = ADC12ON+SHT0_3+MSC+REFON+REF2_5V;
        ADC12CTL0 |= ENC;
        ADC12CTL0 |= ADC12SC;
        break;
      case 4:
       
        ADC12CTL0 &= ~ADC12ON;
        ADC12CTL0 &= ~ENC;
        P6SEL |=0x10;
        ADC12IE=0x10;
        ADC12MCTL4=INCH_4;
        ADC12MCTL4 = SREF_1;
        ADC12CTL1 = CSTARTADD_4+SHP+CONSEQ_2;
        ADC12CTL0 = ADC12ON+SHT0_3+MSC+REFON+REF2_5V;
        ADC12CTL0 |= ENC;
        ADC12CTL0 |= ADC12SC;
        break;
      case 5:
       
        ADC12CTL0 &= ~ADC12ON;
        ADC12CTL0 &= ~ENC;
        P6SEL |=0x20;
        ADC12IE=0x20;
        ADC12MCTL5=INCH_5;
        ADC12MCTL5 = SREF_1;
        ADC12CTL1 = CSTARTADD_5+SHP+CONSEQ_2;
        ADC12CTL0 = ADC12ON+SHT0_3+MSC+REFON+REF2_5V;
        ADC12CTL0 |= ENC;
        ADC12CTL0 |= ADC12SC;
        break;
      case 6:
       
        ADC12CTL0 &= ~ADC12ON;
        ADC12CTL0 &= ~ENC;
        P6SEL |=0x40;
        ADC12IE=0x40;
        ADC12MCTL6=INCH_6;
        ADC12MCTL6 = SREF_1;
        ADC12CTL1 = CSTARTADD_6+SHP+CONSEQ_2;
        ADC12CTL0 = ADC12ON+SHT0_3+MSC+REFON+REF2_5V;
        ADC12CTL0 |= ENC;
        ADC12CTL0 |= ADC12SC;
        break;
      case 7:
       
        ADC12CTL0 &= ~ADC12ON;
        ADC12CTL0 &= ~ENC;
        P6SEL |=0x80;
        ADC12IE=0x80;
        ADC12MCTL7=INCH_7;
        ADC12MCTL7 = SREF_1;
        ADC12CTL1 = CSTARTADD_7+SHP+CONSEQ_2;
        ADC12CTL0 = ADC12ON+SHT0_3+MSC+REFON+REF2_5V;
        ADC12CTL0 |= ENC;
        ADC12CTL0 |= ADC12SC;
        break;
    //  case 8: init_ADC_full();
    //  break;
      case 9:
        putstring2("Stop");
        break;
      default:
        putstring2("Error");
        break;
      }
     
    }
    //****************
    #pragma vector=ADC_VECTOR
    __interrupt void ADC12ISR(void)
    {
     switch (command)
     {
      case 0:
        hexdata=ADC12MEM0;
        trans(hexdata);     //(这个trans程序是转换采样数据为实际模拟值并通过串口发送的子程序)
        break;
      case 1:
        hexdata=ADC12MEM1;
        trans(hexdata);
        break;
      case 2:
        hexdata=ADC12MEM2;
        trans(hexdata);
        break;
      case 3:
        hexdata=ADC12MEM3;
        trans(hexdata);
        break;
      case 4:
        hexdata=ADC12MEM4;
        trans(hexdata);
        break;
      case 5:
        hexdata=ADC12MEM5;
        trans(hexdata);
        break;
      case 6:
        hexdata=ADC12MEM6;
        trans(hexdata);
        break;
      case 7:
        hexdata=ADC12MEM6;
        trans(hexdata);
        break;
    //  case 8: init_ADC_full();
    //    break;
     
     
     }
    }
    微控网感谢您的参与
    在线情况
    2
    • 头像
    • 级别
      • 积分3
      • 经验38
      • 文章2
      • 注册2011-03-18
      各位高手~跪求帮助啊~
      微控网感谢您的参与
      在线情况
      3
      • 头像
      • 级别
        • 积分15
        • 经验2712
        • 文章199
        • 注册2006-07-28
        ADC中断中调用的输出传输程序占用的时间太长,因此串口出现乱码。在中断中置标志位,主程序中作数据传输就好了!
        微控网感谢您的参与
        Powered by LeadBBS 9.2 .
        Page created in 0.3750 seconds with 5 queries.