求助:为什么AD中断进不去呢?

2019-03-24 15:22发布

RT                    求高手帮忙void main(void){  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT  P6SEL |= 0x10;                            // P6.4 ADC option select  ADC12CTL0 = ADC12SHT02 + ADC1      ;         // Sampling time, ADC12 on  ADC12CTL1 = ADC12SHP;                     // Use sampling timer  ADC12IE = 0x10;                           // Enable interrupt  ADC12CTL0 |= ADC12ENC;  P2DIR |= 0x08;                            // P2.3 output    while (1)  {     ADC12CTL0 |= ADC12SC;                   // Start sampling/conversion
    __bis_SR_register(LPM0_bits + GIE);     // LPM0, ADC12_ISR will force exit    __no_operation();                       // For debugger  }}
#pragma vector = ADC12_VECTOR__interrupt void ADC12_ISR(void){  switch(__even_in_range(ADC12IV,34))  {  case  0: break;                           // Vector  0:  No interrupt  case  2: break;                           // Vector  2:  ADC overflow  case  4: break;                           // Vector  4:  ADC timing overflow  case  6: break;                           // Vector  6:  ADC12IFG0     case  8: break;                           // Vector  8:  ADC12IFG1  case 10: break;                           // Vector 10:  ADC12IFG2  case 12: break;                           // Vector 12:  ADC12IFG3  case 14:                         // Vector 14:  ADC12IFG4            if (ADC12MEM4 >= 0x7ff)                 // ADC12MEM = A4 > 0.5AVcc?      P2OUT |= BIT3;                        // P2.3 = 1    else      P2OUT &= ~BIT3;                       // P2.3 = 0
    __bic_SR_register_on_exit(LPM0_bits);   // Exit active CPU  case 16: break;                           // Vector 16:  ADC12IFG5  case 18: break;                           // Vector 18:  ADC12IFG6  case 20: break;                           // Vector 20:  ADC12IFG7  case 22: break;                           // Vector 22:  ADC12IFG8  case 24: break;                           // Vector 24:  ADC12IFG9  case 26: break;                           // Vector 26:  ADC12IFG10  case 28: break;                           // Vector 28:  ADC12IFG11  case 30: break;                           // Vector 30:  ADC12IFG12  case 32: break;                           // Vector 32:  ADC12IFG13  case 34: break;                           // Vector 34:  ADC12IFG14  default: break;  }}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
6条回答
wstt
2019-03-24 22:39
< :TI_MSP430_内容页_SA7 --> 参考下这个例程
#include  <msp430x24x.h>

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  ADC12CTL0 = SHT0_2 + ADC12ON;             // Set sampling time, turn on ADC12
  ADC12CTL1 = SHP;                          // Use sampling timer
  ADC12IE = 0x01;                           // Enable interrupt
  ADC12CTL0 |= ENC;                         // Conversion enabled
  P6DIR &= 0x01;                            // P6.0, i/p
  P6SEL |= 0x01;                            // P6.0-ADC option select
  P1DIR |= 0x01;                            // P1.0 output-LED

  for (;;)
  {
    ADC12CTL0 |= ADC12SC;                   // Start convn, software controlled
    _BIS_SR(CPUOFF + GIE);                  // LPM0, ADC12_ISR will force exit
  }
}

// ADC12 interrupt service routine
#pragma vector=ADC12_VECTOR
__interrupt void ADC12_ISR (void)
{
    if (ADC12MEM0 < 0x7FF)
      P1OUT &= ~0x01;                       // Clear P1.0 LED off
    else
      P1OUT |= 0x01;                        // Set P1.0 LED on
    _BIC_SR_IRQ(CPUOFF);                    // Clear CPUOFF bit from 0(SR)
}

一周热门 更多>

相关问题

    相关文章