unsigned int Aver_Voltage(unsigned int Curr_Volt){static unsigned int Arr_Voltage[ADC_BUFF_SIZE];//定義濾波數(shù)組static unsigned char s_cBufferCounter=0;//定義元素指針并賦初值unsigned int s_dTotal=0;//總數(shù),平均電壓unsigned char n;Arr_Voltage[s_cBufferCounter]=Curr_Volt;//將A/D采樣值加入到數(shù)組中for(n=0;n>ADC_BUFF_SIZE_BIT_COUNT;//用移位的方式做除法,計(jì)算平均值s_cBufferCounter++;if(s_cBufferCounter==ADC_BUFF_SIZE)s_cBufferCounter=0;return Aver_Volt;}void main(){uint ada,i,ad[4];while(1){//ada=mega16_ad();Aver_Voltage(mega16_ad());for(i=0;i<4;i++){ad[3-i]=Aver_Volt%10;Aver_Volt=Aver_Volt/10;}for(i=0;i<4;i++){show(ad[i],i);delay(2);}} }
評(píng)論