采集16次的平均滤波法
int ADCdataH[16], ADCdataL[16], ADCsumH=0, ADCsumL=0;
unsigned char ADCavgH, ADCavgL;
/******************************************************************************
The main C function. Program execution starts
here after stack initialization.
******************************************************************************/
void main (void)
{
int i;
P05_PushPull_Mode;
P05 = 1;
Timer0_Delay1ms(300);
P05 = 0;
Enable_ADC_AIN0; // Enable AIN0 P1.7 as ADC input, Find in "Function_define.h" - "ADC INIT"
ADCsumH = 0x0000;
ADCsumL = 0x0000;
for(i=0;i<16;i++)
{
clr_ADCF;
set_ADCS; // ADC start trig signal
while(ADCF == 0);
ADCdataH[i] = ADCRH;
ADCdataL[i] = ADCRL;
}
for(i=0;i<16;i++)
{
ADCsumH = ADCsumH + ADCdataH[i];
ADCsumL = ADCsumL + ADCdataL[i];
}
ADCavgH = ADCsumH/16;
ADCavgL = ADCsumL/16;
P05 = 1;
while(1);
}
|