/*
Low Pass Filter
Ruler : AD_Val = (ADCR + (2^k-1)*older ADCR) / 2^k;
K = 1 : AD_Val = (ADCR + older ADCR) / 2;
K = 2 : AD_Val = (ADCR + 3 * older ADCR) / 4;
K = 3 : AD_Val = (ADCR + 7 * older ADCR) / 8;
AD_Filter = (2^k)*Older ADCR, AD_Shift = Older ADCR.
*/
#define K 3 // 1 ~ 4
static WORD AD_Val;static WORD AD_Shift, AD_Filter;
static void Get_AD_By_K (void)
{
AD_Val = (ADCRH << 8) | ADCRL; // Get 12 Bit of ADC
AD_Val >>= 4; //
AD_Shift = AD_Filter >> K; // K为常量1,2,3,4
AD_Filter -= AD_Shift; // Low Pass Filter
AD_Filter += AD_Val; //
AD_Shift = AD_Filter >> K; // K为常量1,2,3,4
AD_Val = AD_Shift; // Get new 12 Bit of ADC
}