已经完成调试了 谢谢各位。完整程序如下:
#include <msp430x12x2.h>
#define TEM_ADC_CHL 0x0a
void InitSys(void);
void Read_ADC(unsigned int INCH_channel);
void ADC_TO_TEM(void);
unsigned int ADC_sample_val;
unsigned int long temp1,temp2;
unsigned int long IntDegC;
unsigned int long IntDegF;
void main(void)
{
InitSys();
while(1)
{
Read_ADC(TEM_ADC_CHL);
ADC_TO_TEM();
}
}
void InitSys(void)
{
// INIT SYSTEM CLKS(ACLK AND DCO/MCLK)
WDTCTL = WDTPW+WDTHOLD; //关闭看门狗
BCSCTL1 = 0x87; //ACLK 分频系数是1,内部电阻选7
DCOCTL = 0xe0; //设置DCO输出时钟频率5MHZ
BCSCTL2 = SELM_0; //选择MCLK为DCOCLK,内部电阻
ADC10CTL1 |= 0x08; // 转换时钟为ACLK
ADC10CTL0 = SREF_1 + ADC10SHT_0 + REFOUT + REFON + ADC10ON;
//选择内部电压1.5V,采样时间4XADC10CLKS
}
void Read_ADC(unsigned int INCH_channel)
{
unsigned int tmp;
ADC10CTL0 &= ~ENC;
tmp = ADC10CTL1;
tmp &= 0x0fff;
tmp |= (INCH_channel<<12);
ADC10CTL1 = tmp;
ADC10CTL0 |= ENC + ADC10SC;
while(ADC10CTL1 & ADC10BUSY)
{}
ADC_sample_val = ADC10MEM;
ADC10CTL0 &= ~ENC;
}
void ADC_TO_TEM(void)
{
//oC = ((A10/1024)*1500mV)-986mV)*1/3.55mV = A10*423/1024 - 278
temp1 = ADC10MEM;
IntDegC = ((temp1 - 673) * 423) / 1024;
// oF = ((A10/1024)*1500mV)-923mV)*1/1.97mV = x*761/1024 - 468
temp2 = ADC10MEM;
IntDegF = ((temp2 - 630) * 761) / 1024;
}