/************************************************************** 函数名称:NtcAD_Testing() 函数功能:温度传感器采样函数 入口参数: 出口参数:Flag_Ntc_OneAd,AdResult 备 注:采样NTC的AD值,采样6次,去掉最大及最小求算术平均值 **************************************************************/ void NtcAD_Testing(unsigned char i) { //static volatile unsigned char admin,admax,adtimes; //static volatile unsigned int adsum; //static volatile bit Flag_ADFrist; if(Flag_AD&&ADIF) { Flag_AD=0; if(!Flag_ADFrist) { admax = ADRESH; admin = ADRESH; Flag_ADFrist=1; } else if(ADRESH > admax) admax = ADRESH; //AD采样最大值 else if(ADRESH < admin) admin = ADRESH; //AD采样最小值 adsum += ADRESH; if(++adtimes >= 6) { adsum -= admax; adsum -= admin; AdResult = adsum >> 2; //8次平均值作为最终结果 Flag_ADFrist=0; if(admax>(admin+20)) { //最大值及最小值差20个8BITAD则当前采样数据作废 adsum = 0; admin = 0; admax = 0; adtimes = 0; } else { adsum = 0; admin = 0; admax = 0; adtimes = 0; ADnex++; Flag_Ntc_OneAd=1; } } } }