Hi nazstaphobia,
Just refer to PIC16F877A datasheet and you would find the answer yourself. It is very simple. Take a look at the ADCON0 register in the datasheet.
Actually, you are not adding another ADC module, but you are going to use one more ADC input channel. There is only one ADC module in the controller and there are 8 inputs to the ADC and these inputs are multiplexed ie; only one input channel is selected at a time. To select a particular channel you need to manipulate few bits in the ADCON0 register.
In the ADCON0 register, bits 5,6,3 (starts at bit7 and ends at bit0) are used to select the channel.
bit 5-3 CHS2:CHS0: Analog Channel Select bits
000 = Channel 0 (AN0)
001 = Channel 1 (AN1)
010 = Channel 2 (AN2)
011 = Channel 3 (AN3)
100 = Channel 4 (AN4)
101 = Channel 5 (AN5)
110 = Channel 6 (AN6)
111 = Channel 7 (AN7)
So for AN0: ADCON0=0b10000001;
AN1: ADCON0=0b10001001;
AN2: ADCON0=0b10010001;
and so on.
In your code, make following modifications:
void Read_Adc()
{
ADCON0.GO=1; // Start Convert
while(ADCON0.GO); // Wait Until Convert Complete
Adc=(ADRESH*4)+(ADRESL/64); // 10 bit Data ==> Adc
}
void main()
{
TRISA=0xFF; //SET PORT A AS INPUT
TRISC = 0X00; //SET PORT C AS OUTPUT
while(1)
{
//FOR READING AN0
ADCON0=0b10000001;//SELSECT AN0
Read_Adc();
//CONTROL PART
//FOR READING AN1
ADCON0=0b10001001;//SELSECT AN1
Read_Adc();
//CONTROL PART
//FOR READING AN2
ADCON0=0b10010001;//SELSECT AN2
Read_Adc();
//CONTROL PART
.
.
.
.
.
.
.