为什么这个程序不能够读出转换后的数值?
#include "msp430g2553.h"
#define ADC_0 0
#define ADC_F 679
#define VCAL 1 //ADC测电压校准参数,1v
unsigned char m=0;
int ave,R_PT100,T_PT100,n=0;
unsigned long AD_Result;
float Calculate(int ADC_Result)
{
float Vol;
Vol=(float)(ADC_Result-ADC_0)*VCAL/(ADC_F-ADC_0);
return(Vol);
}
void ADC10_Init(void)
{
ADC10CTL1=CONSEQ_2;//单通道多次转换,这句应当写在最前面
ADC10CTL0 = REFON+SREF_1+REF2_5V; //打开2.5V 正参考,地为负参考,默认1.5V
ADC10CTL0 |= ADC10ON+ADC10SHT_3+ADC10IE;//打开ADC10 内核,设定采样保持时间为64个ADC10CLK,使能ADC10中断
ADC10CTL1 = INCH_6+SHS_0+ADC10SSEL_2; // input A6,采样保持
ADC10AE0 |= 0x10; // P1.4 DC option select。A6模拟信号输入使能
}
void main()
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
ADC10_Init();
_BIS_SR(GIE);//开中断
while(1)
{
ADC10CTL0 |= ENC + ADC10SC;
}
}
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
ADC10CTL0 &= ~ENC; // Disable ADC conversion
m++; //计数变量加一,记录进入AD中断的次数
AD_Result+=ADC10MEM; //累加每次采样值
if(m>=8) //判断采样的次数,若采样次数等于8 ,作下面处理
{
m=0;
ave=AD_Result>>3; //对累加和求平均
AD_Result=0;
R_PT100=Calculate(ave);
R_PT100=R_PT100*1000/4.0;
T_PT100=(int)((R_PT100/1.055-100)/0.03851); //计算PT100所测温度
}
} |