This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
看你的程序在AD通道设置上
ADC12MCTL0 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL1 = INCH_1+EOS; // ref+=AVcc, channel = A1, end seq.
ADC12IE = 0x02; // Enable ADC12IFG.1
ADC的中断向量 #pragma vector=ADC12_VECTOR
试试这样可以进入中断吗?
_BIS_SR(LOM0+GIE);跟_ENIT();区别是肯定有的,ENIT仅仅是开启中断. _BIS_SR(LOM0+GIE);的意思是LPM0 与中断功能.而且你是不是打错了。
LPM0 的意思是 Enter Low Power Mode 0 ;
在编辑界面你用 go to define ... 找一下看看BIS_SR(LPM0+GIE);的定义在哪,是不是相应的没有进行定义,比如在G2系列的程序中就能找到BIS_SR(LPM0+GIE);的定义但是找不到ENIT的定义同时编译器也不会报错但是程序运行到ENIT时就跑飞了,所以你可以先看看有没有定义,再就是可以用仿真器追踪一下执行完该条语句后单片机的寄存器GIE位是否打开了~
size hu,
我看你的程序是采用的Repeated Sequence of Conversions的模式,下面程序是TI关于这种用法的例程,你直接用这个程序跑试试。我看了觉得你的程序没有问题。
int main(void)
{
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
P6SEL = 0x0F; // Enable A/D channel inputs
ADC12CTL0 = ADC12ON+MSC+SHT0_8; // Turn on ADC12, extend sampling time
// to avoid overflow of results
ADC12CTL1 = SHP+CONSEQ_3; // Use sampling timer, repeated sequence
ADC12MCTL0 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL1 = INCH_1; // ref+=AVcc, channel = A1
ADC12MCTL2 = INCH_2; // ref+=AVcc, channel = A2
ADC12MCTL3 = INCH_3+EOS; // ref+=AVcc, channel = A3, end seq.
ADC12IE = 0x08; // Enable ADC12IFG.3
ADC12CTL0 |= ENC; // Enable conversions
ADC12CTL0 |= ADC12SC; // Start conversion
_BIS_SR(LPM0_bits + GIE); // Enter LPM0, Enable interrupts
}
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
{
static unsigned int index = 0;
A0results[index] = ADC12MEM0; // Move A0 results, IFG is cleared
A1results[index] = ADC12MEM1; // Move A1 results, IFG is cleared
A2results[index] = ADC12MEM2; // Move A2 results, IFG is cleared
A3results[index] = ADC12MEM3; // Move A3 results, IFG is cleared
index = (index+1)%Num_of_Results; // Increment results index, modulo; Set Breakpoint here
}
size hu,
_ENIT();只是打开全局中断,_BIS_SR(LPM0+GIE);是打开全局中断并进入LPM0低功耗模式。只用_ENIT();的话,功耗会较高。我在IAR中测试了,没有问题。
另外,抱歉,刚刚程序拷贝少了一部分,全部如下。
#include <msp430.h>
#define Num_of_Results 8
static unsigned int A0results[Num_of_Results]; // These need to be global in
static unsigned int A1results[Num_of_Results]; // this example. Otherwise, the
static unsigned int A2results[Num_of_Results]; // compiler removes them because
static unsigned int A3results[Num_of_Results]; // they are not used
int main(void)
{
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
P6SEL = 0x0F; // Enable A/D channel inputs
ADC12CTL0 = ADC12ON+MSC+SHT0_8; // Turn on ADC12, extend sampling time
// to avoid overflow of results
ADC12CTL1 = SHP+CONSEQ_3; // Use sampling timer, repeated sequence
ADC12MCTL0 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL1 = INCH_1; // ref+=AVcc, channel = A1
ADC12MCTL2 = INCH_2; // ref+=AVcc, channel = A2
ADC12MCTL3 = INCH_3+EOS; // ref+=AVcc, channel = A3, end seq.
ADC12IE = 0x08; // Enable ADC12IFG.3
ADC12CTL0 |= ENC; // Enable conversions
ADC12CTL0 |= ADC12SC; // Start conversion
_BIS_SR(LPM0_bits + GIE); // Enter LPM0, Enable interrupts
}
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
{
static unsigned int index = 0;
A0results[index] = ADC12MEM0; // Move A0 results, IFG is cleared
A1results[index] = ADC12MEM1; // Move A1 results, IFG is cleared
A2results[index] = ADC12MEM2; // Move A2 results, IFG is cleared
A3results[index] = ADC12MEM3; // Move A3 results, IFG is cleared
index = (index+1)%Num_of_Results; // Increment results index, modulo; Set Breakpoint here
}
你好:
这个问题与LPM0没有关系,现在你是一次中断都进不了,还是只能进一次?
再一个,可以参考Lina的代码试试。
总之,不要误以为是LPM0的问题。
谢谢。