用msp430f5529的P6.4管脚,模拟输入A4,现在初始化后,使用ADC转换,即便A4无输入(实际也测量为0左右)采集回来的AD值在2000左右,感觉初始化代码没问题的。
//#include <msp430.h>
#include <msp430f5529.h>
#include "Adc.h"
/**********************************************************************
* 函数名称:void ADC12Init()
* 功能描述:12bit adc 初始化
* 输入参数:
* 返回值:
* 其它说明:无
***********************************************************************/
void ADC12Init()
{
// P6SEL |= 0x10;
// //ADC12CTL0 = ADC12ENC+ADC12ON+ADC12MSC+ADC12SHT0_8;
// //ADC12CTL1 = ADC12SHP+ADC12CONSEQ_2;//单通道循环
// ADC12CTL0 = ADC12SHT02 + ADC12ON; // Sampling time, ADC12 on
// ADC12CTL1 = ADC12SHP+ADC12CSTARTADD_4; // Use sampling timer
// ADC12IE = 0x10; // Enable interrupt
// ADC12CTL0 |= ADC12ENC;
// ADC12CTL2 |= ADC12RES_2;
// ADC12MCTL4 = ADC12INCH_4;//Pin6.4引脚 通道4
// //ADC12IE = 0x10;
// //ADC12CTL0 |= ADC12SC;
ADC12CTL0 &= ~ADC12ENC;
P6SEL |= 0x10;
ADC12CTL1 = ADC12CSTARTADD_4+ADC12SHP+ADC12DIV0+ADC12SSEL_3;
//ADC12CTL1 = 0x4238;
//ADC12CTL2 = 0x00A0;
ADC12CTL2 = ADC12TCOFF+ADC12RES_2;
//ADC12MCTL4 = 0x04;
ADC12MCTL4 = ADC12INCH_4;
ADC12CTL0 = ADC12SHT0_2 + ADC12ON + ADC12ENC;
}
/**********************************************************************
* 函数名称:int GetADCValue()
* 功能描述:
* 输入参数:
* 返回值: AD转换的数值
* 其它说明:无
***********************************************************************/
int GetADCValue()
{
int res = 0;
ADC12CTL0 |= ADC12SC;
while (!(ADC12IFG & BIT4));
res = ADC12MEM4;
ADC12CTL0 &= ~ADC12SC;
return res;
}
请大家指导,问题出的莫名奇妙 |