
//------------------------------------------------------------------------------------
// CONFIG ROUTINE
//------------------------------------------------------------------------------------ 
void config(void)
{
	// Configure the PRTnMX Registers	
	PRT0MX = 0x00;	// PRT0MX: Initial Reset Value
	PRT1MX = 0x00;	// PRT1MX: Initial Reset Value
	PRT2MX = 0x00;	// PRT2MX: Initial Reset Value

	// Port configuration (1 = Push Pull Output)
	PRT0CF = 0xFF;	// Output configuration for P0 
	PRT1CF = 0xFF;	// Output configuration for P1 
	PRT2CF = 0xFF;// Output configuration for P2 
	PRT3CF = 0xFF; // Output configuration for P3

	P0MODE = 0x00; // Input configuration for P0
	P1MODE = 0x00; // Input configuration for P1
	P2MODE = 0xFF; //Input configuration for P2
	P3MODE = 0xFF; // Input configuration for P3

	CPT0CN = 0x00;	// Comparator 0 Control Register
	CPT1CN = 0x00;	// Comparator 1 Control Register

	OSCXCN = 0x30;	// EXTERNAL Oscillator Control Register	
	OSCICN = 0x14;	// Internal Oscillator Control Register

	REF0CN = 0x03;	// Reference Control Register
/*----------------
 ADC Configuration
 -----------------*/
	AMX0SL = 0xE0;	// AMUX Channel Select Register
	ADC0CF = 0x78;	// ADC Configuration Register
	ADC0CN = 0x40;	// ADC Control Register
	
	ADC0LTH = 0xFF;	// ADC Less-Than High Byte Register
	ADC0GTH = 0xFF;	// ADC Greater-Than High Byte Register

void adcdata(void)
{
signed char value;
value=0x00;

ADCINT = 0;
ADBUSY = 1;

while(ADCINT == 0);

value = ADC0H;
ADCEN=0;

}

void main()
{
config();
ADCEN = 1; //enable ADC
delay(500000);
adcdata();
delay(500000);
} 

