Hi
Below is my code..
// Header Files
#include <p18cxxx.h>
#include <stdio.h>
// Configuration Bit Settings
#pragma config FOSC = HSPLL,DEBUG = ON, WDTEN = OFF, XINST = OFF
void adc_init();
void ADC_value();
unsigned int ADCRead_ch0();
unsigned int ADCRead_ch1();
unsigned int ADCRead_ch4();
void DelayFor18TCY();
void Read_ADC_All_Segments();
unsigned int adc_value,adc_value_1,adc_value_2;
unsigned int a0 = 0;
unsigned int a1 = 0;
unsigned int a4 = 0;
unsigned int val_0 ;
unsigned int val_1 ;
unsigned int val_4 ;
main
{
adc_init();
while(1)
{
Read_ADC_All_Segments();
}
}
// Delay Function
{
Delay10TCYx(20);
}
// ADC initialisation
void adc_init()
{
ADCON1bits.VCFG1 = 0;
ADCON1bits.VCFG0 = 0;
ADCON1bits.PCFG = 0b1010;
ADCON2bits.ADFM = 1;
ADCON2bits.ACQT = 0b010;
ADCON2bits.ADCS = 0b0010;
}
// Copying ADRESH and ADRESL
void ADC_value()
{
adc_value = ADRESH;
adc_value_1 = ADRESL;
adc_value = adc_value << 8;
adc_value_2 = adc_value | adc_value_1;
}
// Reading channel 0
unsigned int ADCRead_ch0()
{
ADCON0 = 0x04;
ADCON0bits.ADON = 1;
ADCON0bits.GO_DONE = 1;
while(ADCON0bits.GO_DONE);
ADC_value();
a0 = adc_value_2;
return a0;
}
// Reading channel 1
unsigned int ADCRead_ch1( )
{
ADCON0 = 0x00;
ADCON0bits.ADON = 1;
ADCON0bits.GO_DONE = 1;
while(ADCON0bits.GO_DONE);
ADC_value();
a1 = adc_value_2;
return a1;
}
// Reading channel 4
unsigned int ADCRead_ch4( )
{
ADCON0 = 0x10;
ADCON0bits.ADON = 1;
ADCON0bits.GO_DONE = 1;
while(ADCON0bits.GO_DONE);
ADC_value();
a4 = adc_value_2;
return a4;
}
void Read_ADC_All_Segments(void)
{
val_0 = ADCRead_ch0();
DelayFor18TCY();
val_1 = ADCRead_ch1( );
DelayFor18TCY();
val_4 = ADCRead_ch4();
DelayFor18TCY();
}
Thank you