//******************************************************************************
// II20-20 Maximum Function, Example							S215  09 0920
// *****************************************************************************
#include "s215-header10.h"
#pragma code
void main (void)
{
	unsigned short max, adc;
    InitPorts();		 //Initialize I/O ports and ADC (set it to ADC channel 0).
	RstMinMax0();				//Reset minimum and maximum
	InitRunAvg0(ADC10bit()); 	//Initialize running average to the value
								//  returned by the ADC.
	while (1)
    {
    //|||||||||||||||||||||||||| Main Loop ||||||||||||||||||||||||||||||||
	if (PB==1)					//Reset minimum and maximum when button pressed.
	{
		LED0 = 1;				//Turn LED on to verify that button was pressed.
		RstMinMax0( );
	}
	LED0 = 0;					//Turn LED back off.
	
	adc = Runavg0(ADC10bit());
	max = Mx0(adc);
	DispNmbr(max, 2);	
		//Display number. Decimal point between 2nd and 3rd digits from the right.

	Delay10ms(1);
     //|||||||||||||||||||||||| End of Main Loop ||||||||||||||||||||||||||		
    }
}
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
