ADC
//in this i have setted AN0 as input ADC port
// value after Anolog to digital conversion is stored at variable and
// also shown at portc and portb in combined form(10 bit)
#include<pic.h>
#define _XTAL_FREQ 16000000
__CONFIG(0x3f7a);
int a;
void main()
{
TRISB=0;//setting port B as output
PORTB=0;
TRISC=0;//setting port C as output
PORTC=0;
TRISA=255;//setting the PORTA as input
ADON=1;//enables ADC
ADCS0=0;//setting the clock fo ADC
ADCS1=0;//setting the clock fo ADC
ADCS2=0;//setting the clock fo ADC
ADFM=1;//sets the higher bits of conversion to right justified
PCFG3=0;//Configuring 8 pin as adc input channels
PCFG2=0;//Configuring 8 pin as adc input channels
PCFG1=0;//Configuring 8 pin as adc input channels
PCFG0=0;//Configuring 8 pin as adc input channels
CHS2=0;
CHS1=0;
CHS0=0;
while(1)
{
__delay_ms(100);
a=(ADRESH<<8)+ADRESL; //this only for further data processing
PORTC=ADRESH; //higher data byte
PORTB=ADRESL; //lower data byte
GO=1; // to restart conversion
}
}