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
} ? ?*/
評論
查看更多