unsigned char TLC549_GetValue(void)
{
unsigned char ConvertValue;
TLC549_CS=0; //打开片选
ConvertValue=TLC549_ReadByte(); //读取转换后的8位AD值
TLC549_CS=1; //关闭片选
delayus(50); //等待转换结束 最长17us
return ConvertValue; //返回转换结果
}
unsigned char TLC549_Filter() //滤波函数
{
char count,i,j;
unsigned char value_buf[N],temp;
int sum=0;
for (count=0;count
value_buf[count] = TLC549_GetValue();
delayus(300);
}
for (j=0;j
for (i=0;i
if ( value_buf[j]>value_buf[i+j] )
{
temp = value_buf[j];
value_buf[j] = value_buf[i+j];
value_buf[i+j] = temp;
}
}
}
for(count=1;count
return (unsigned char)(sum/(N-2));
}
unsigned char AD_Convert(void)
{
unsigned char AD_Value;
AD_Value=TLC549_Filter();
return AD_Value;
}/*
unsigned char TLC549_Filter(void)
{
unsigned int sum=0;
for(count=0;count
sum+=TLC549_GetValue();
delayus(300);
}
return (unsigned char)(sum>>3);//求平均值,左移三位相当于除以8
} */
评论
查看更多