
void ADC0_ISR (void) interrupt 15
{
   static unsigned int_dec=INT_DEC;              // Integrate/decimate counter
                                                 // we post a new result when
                                                 // int_dec = 0
   static long accumulator[ANALOG_INPUTS] ={0L};       
                                                 // Here's where we integrate the
                                                 // ADC samples from input AIN0.0
   unsigned char i;
   AD0INT = 0;                                   //clear ADC conversion complete overflow
   accumulator[amux_convert] += ADC0;            // Read ADC value and add to running
                                                 // total
   if(amux_convert == (ANALOG_INPUTS-1))         // reset input index if the last input 
                                                 //was just read
      {
      int_dec--;                                 // Update decimation counter
                                                 // when last of the analog inputs 
                                                 // sampled
      }
   if (int_dec == 0)                             // If zero, then post result
   {
      int_dec = INT_DEC;                         // Reset counter
      for(i=0; i<ANALOG_INPUTS; i++)
         {
         Result[i] = accumulator[i] >> 8;        // ## Copy decimated values into Result 
         accumulator[i] = 0L;                    // Reset accumulators
         }
   }
   amux_convert = amux_input;                    // now that conversion results are 
                                                 // stored, advance index to the analog
                                                 // input currently selected on the mux
   
}