刚开始调ADC12模块就遇到一个很奇怪的问题,ADC12SC 在单通道单次转换模式下不能置位,但是在单通道多次转换模式下却可以置位。现在我换了两块不一样的最小系统板,都遇到这个问题。。
程序1.(TI的官方演示程序,单通道单次转换)-----》单步时ADC12CTL0 |= ADC12SC不能置位。
#include <msp430x14x.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
P6SEL |= 0x01; // P6.0 ADC option select
P1DIR |= 0x01; // P1.0 output
for (;;)
{
ADC12CTL0 |= ADC12SC; // Sampling open
_BIS_SR(CPUOFF + GIE); // LPM0, ADC12_ISR will force exit
}
}
// ADC12 interrupt service routine
#pragma vector=ADC_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)
}
程序二是单通道重复采样模式------->》ADC12CTL0 |= ADC12SC 执行后,ADC12SC可以置位。
#include <msp430x14x.h>
#define Num_of_Results 8
static unsigned int results[Num_of_Results]; // Needs to be global in this
// example. Otherwise, the
// compiler removes it because it
// is not used for anything.
void main(void)
{
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
P6SEL |= 0x01; // Enable A/D channel A0
ADC12CTL0 = ADC12ON+SHT0_8+MSC; // Turn on ADC12, set sampling time
ADC12CTL1 = SHP+CONSEQ_2; // Use sampling timer, set mode
ADC12IE = 0x01; // Enable ADC12IFG.0
ADC12CTL0 |= ENC; // Enable conversions
ADC12CTL0 |= ADC12SC; // Start conversion
_BIS_SR(LPM0_bits + GIE); // Enter LPM0,Enable interrupts
}
#pragma vector=ADC_VECTOR
__interrupt void ADC12ISR (void)
{
static unsigned int index = 0;
results[index] = ADC12MEM0; // Move results
index = (index+1)%Num_of_Results; // Increment results index, modulo
}
求解啊。我之前都用过这几个演示程序,都好的,怎么现在不行了。。。。。
大虾们,高手们,出来帮帮忙吧!
此帖出自
小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>