我不知道程序出错在那里,调节温度(由高变低或者由低变低)测出来的温度变化变态的,由大变小再变大变小,有几段变的。要疯了
测温函数如下
#include<。。。。>
const unsigned long NTC_Tem_Table[90] PROGMEM= //热敏电阻 电阻电压 转换表
{
838,830,822,815,807,798,790,782,773,764, //-10~-1
755,746,737,728,719,709,700,690,680,670, //0~9
661,651,641,631,621,611,601,591,581,571, //10~19
561,551,541,531,521,512,502,492,483,473, //20~29
464,455,445,436,427,418,410,401,393,384, //30~39
376,368,360,352,344,337,329,322,315,307, //40~49
301,294,287,281,274,268,262,256,250,244, //50~59
238,233,228,222,217,212,207,202,198,193, //60~69
189,184,180,176,172,168,164,160,157,153 //70~79
};
uint16 ADC_Convert(uint8 ch) //ADC通道选择
{
uint8 i;
uint8 g_advalue[8]; //A/D转换缓冲区
uint16 ret=0;
uint8 max_id=1,min_id=1,max_val=0,min_val=0;
ADMUX=((1<
for(i=0;i<8;i++) //连续转换8次
{
ADCSRA|=_BV(ADSC);
loop_until_bit_is_set(ADCSRA,ADIF); // 等待AD转换结束
ADCSRA|=(1<
}
ret=0;
for(i=1;i<8;i++)
{
ret+=g_advalue[i];
}
//找出最大值和最小值索引
ret/=7;
for(i=1;i<8;i++)
{
if(g_advalue[i]>ret)
{
if(g_advalue[i]-ret>max_val)
{
max_val=g_advalue[i]-ret;
max_id=i;
}
}
else
{
if(ret-g_advalue[i]>min_val)
{
min_val=ret-g_advalue[i];
min_id=i;
}
}
}
//去掉第一个、最大值和最小值后的平均值
ret=0;
for(i=1;i<8;i++)
{
if((i!=min_id)&&(i!=max_id))
ret+=g_advalue[i];
}
if(min_id!=max_id)
ret/=5;
else
ret/=6;
ADCSRA&=~(1<
}
//查表读取温度
char CH_Temp(uint8 c)
{
uint8 i;
uint8 temp;
uint16 v;
v=ADC_Convert(c);
for(i=0;i<91;i++)
{
if(v>=pgm_read_word(NTC_Tem_Table+i))
{
temp=i-10;
return temp;
}
}
temp=255;
return temp;
}
int main()
{
PORTA=0x00;
ADCSRA|=(1<
while(1)
{
//获取温度并显示
}
}
真的要找人帮帮忙了,自己一个人怎样看都不知道那里错。
先 谢谢了!