typedef struct{
int total;
int out;
char counter;
bool ok;
}t_ADC;
t_ADC adc;
void adc_ave(void)
{
if(flag_5ms){
flag_5ms = 0;
total += adc_once();
if(++counter >= 5){
counter = 0;
if(adc.ok == false){
adc.out = total / 5;
adc.ok = true;
}
total = 0;
}
}
}
void main(void)
{
init();
while(1)
{
adc_ave();
if(adc.ok == true){
...
adc.ok = false;
}
}
}
|