本帖最后由 arm菜鸟人 于 2013-12-10 16:47 编辑
使用MSP430F149ADC12,输出一直是0x0FFF。很郁闷,大家帮找茬,看问题出在哪里。不胜感激。
void ADC12_Init(void)
{
volatile unsigned int i;
P6SEL |= 0x01; // Enable A/D channel A0
P6DIR &= ~BIT0; // 设置P6.0为输入
ADC12CTL0 &= ~ENC;
ADC12CTL0 = ADC12ON+SHT0_2+REFON+REF2_5V; // Turn on and set up ADC12
ADC12CTL1 = SHP; // Use sampling timer
ADC12MCTL1 = SREF_1 + INCH_0; // Vr+=Vref+
for ( i=0; i<0x3600; i++) // Delay for reference start-up
{
}
ADC12CTL0 |= ENC; // Enable conversions
}
/****************************************************************************************
函数名称: ADC12_Convert(void)
功 能: ADC12 启动函数
参 数: 无
返回值 : 无
说明 :
****************************************************************************************/
unsigned int ADC12_Convert(void)
{
unsigned int temp = 0;
ADC12CTL0 |= ADC12SC; // ADC12SC 启动模式
while ((ADC12IFG & BIT0) == 0); // 等待ADC 完成
temp = ADC12MEM0;
return temp;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
- void Init_ADC()
- {
- P6SEL = 0x07;
- P6DIR &= ~BIT0;
- P6DIR &= ~BIT1;
- P6DIR &= ~BIT2;
- P6DIR &= ~BIT3;
- ADC12CTL0 &= ~(ENC);
- ADC12CTL1 |= CSTARTADD_0;
- ADC12MCTL0 = INCH_0;
- ADC12MCTL1 = INCH_1;
- ADC12MCTL2 = INCH_2;
- ADC12MCTL3 = INCH_3 + EOS;
- ADC12CTL0 |= ADC12ON;
- ADC12CTL0 |= MSC;
- ADC12CTL1 |= CONSEQ_1;
- ADC12CTL1 |= ADC12SSEL_1;
- ADC12CTL1 |= ADC12DIV_0;
- ADC12CTL1 |= (SHP);
- ADC12CTL0 |= ENC;
- return;
- }
- void Init_TimerA()
- {
- TACTL = TASSEL1 + TACLR;
- CCTL0 = CCIE;
- CCR0 = 40000;
- TACTL |= MC0;
- }
- #pragma vector = TIMERA0_VECTOR
- __interrupt void TimerA_ISR(void)
- {
- int results[4] = {0};
- uchar SendL, SendH;
- ADC12CTL0 &= ~ENC;
- results[0] = ADC12MEM0;
- // ADC12MEM1 = 0x0E0D;
- results[1] = ADC12MEM1;
- SendL = results[1] % 256;
- SendH = results[1] >> 8;
- Uart0_Send(SendH);
- Uart0_Send(SendL);
- Uart0_Send(0xEE);
- results[2] = ADC12MEM2;
- results[3] = ADC12MEM3;
- ADC12MEM1 = 0x0000;
- ADC12CTL0 |= ENC + ADC12SC;
- }
复制代码新写了一段定时器触发的程序,这样是否能证明AD挂掉了?
收到的数据 一直是 00 00.
一周热门 更多>