#define ADC_CH_5VOLTS   0
#define ADC_CH_TEMP     1

extern unsigned AdcRead(unsigned char channel);

struct MOVING_AVG
{
    unsigned char sampleIdx;
    unsigned      sample[16];
    unsigned      sampleTotal;
};

struct MOVING_AVG Ma5Volts;
struct MOVING_AVG MaTemp;

unsigned Adc5Volts;
unsigned AdcTemp;

static unsigned maUpdate(struct MOVING_AVG *maP, unsigned sample)
{
    maP->sampleTotal      -= maP->sample[sampleIdx];
    maP->sampleTotal      += sample;
    maP->sample[sampleIdx] = sample;

    return (maP->sampleTotal >> 4);
}

void main(void)
{
    for (;;)
    {
        Adc5Volts = maUpdate(&Ma5Volts, AdcRead(ADC_CH_5VOLTS));
        AdcTemp   = maUpdate(&MaTemp,   AdcRead(ADC_CH_TEMP));
    }
}
