How can I make the following code shorter using a for loop?
Do I have to include a header file?
while(1){// run forever in a loop
OpenADC(ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_20_TAD,ADC_CH0 & ADC_INT_OFF & ADC_VREFPLUS_VDD &
ADC_VREFMINUS_VSS, 0b1011);
SetChanADC(ADC_CH0); /* Selects the pin used as i/p to the */
ConvertADC( ); /* start A/D conversion */
while(BusyADC( )); /* wait for completion */
/* Get results and store at Ports D & B */
LATD = ADRESL; /* Results Register Low displayed, least sign on Port D */
LATB = ADRESH; /* Results Register High displayed on Port B */
CloseADC( );
Delay10KTCYx(200); //1second delay
OpenADC(ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_20_TAD,ADC_CH1 & ADC_INT_OFF & ADC_VREFPLUS_VDD &
ADC_VREFMINUS_VSS, 0b1011);
SetChanADC(ADC_CH1); /* Selects the pin used as i/p to the */
ConvertADC( ); /* start A/D conversion */
while(BusyADC( )); /* wait for completion */
/* Get results and store at Ports D & B */
LATD = ADRESL; /* Results Register Low displayed, least sign on Port D */
LATB = ADRESH; /* Results Register High displayed on Port B */
CloseADC( );
Delay10KTCYx(200); //1second delay
OpenADC(ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_20_TAD,ADC_CH2 & ADC_INT_OFF & ADC_VREFPLUS_VDD &
ADC_VREFMINUS_VSS, 0b1011);
SetChanADC(ADC_CH2); /* Selects the pin used as i/p to the */
ConvertADC( ); /* start A/D conversion */
while(BusyADC( )); /* wait for completion */
/* Get results and store at Ports D & B */
LATD = ADRESL; /* Results Register Low displayed, least sign on Port D */
LATB = ADRESH; /* Results Register High displayed on Port B */
CloseADC( );
Delay10KTCYx(200); //1second delay
OpenADC(ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_20_TAD,ADC_CH3 & ADC_INT_OFF & ADC_VREFPLUS_VDD &
ADC_VREFMINUS_VSS, 0b1011);
SetChanADC(ADC_CH3); /* Selects the pin used as i/p to the */
ConvertADC( ); /* start A/D conversion */
while(BusyADC( )); /* wait for completion */
/* Get results and store at Ports D & B */
LATD = ADRESL; /* Results Register Low displayed, least sign on Port D */
LATB = ADRESH; /* Results Register High displayed on Port B */
CloseADC( );
Delay10KTCYx(200); //1second delay
}
}
Do I have to include a header file?
while(1){// run forever in a loop
OpenADC(ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_20_TAD,ADC_CH0 & ADC_INT_OFF & ADC_VREFPLUS_VDD &
ADC_VREFMINUS_VSS, 0b1011);
SetChanADC(ADC_CH0); /* Selects the pin used as i/p to the */
ConvertADC( ); /* start A/D conversion */
while(BusyADC( )); /* wait for completion */
/* Get results and store at Ports D & B */
LATD = ADRESL; /* Results Register Low displayed, least sign on Port D */
LATB = ADRESH; /* Results Register High displayed on Port B */
CloseADC( );
Delay10KTCYx(200); //1second delay
OpenADC(ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_20_TAD,ADC_CH1 & ADC_INT_OFF & ADC_VREFPLUS_VDD &
ADC_VREFMINUS_VSS, 0b1011);
SetChanADC(ADC_CH1); /* Selects the pin used as i/p to the */
ConvertADC( ); /* start A/D conversion */
while(BusyADC( )); /* wait for completion */
/* Get results and store at Ports D & B */
LATD = ADRESL; /* Results Register Low displayed, least sign on Port D */
LATB = ADRESH; /* Results Register High displayed on Port B */
CloseADC( );
Delay10KTCYx(200); //1second delay
OpenADC(ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_20_TAD,ADC_CH2 & ADC_INT_OFF & ADC_VREFPLUS_VDD &
ADC_VREFMINUS_VSS, 0b1011);
SetChanADC(ADC_CH2); /* Selects the pin used as i/p to the */
ConvertADC( ); /* start A/D conversion */
while(BusyADC( )); /* wait for completion */
/* Get results and store at Ports D & B */
LATD = ADRESL; /* Results Register Low displayed, least sign on Port D */
LATB = ADRESH; /* Results Register High displayed on Port B */
CloseADC( );
Delay10KTCYx(200); //1second delay
OpenADC(ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_20_TAD,ADC_CH3 & ADC_INT_OFF & ADC_VREFPLUS_VDD &
ADC_VREFMINUS_VSS, 0b1011);
SetChanADC(ADC_CH3); /* Selects the pin used as i/p to the */
ConvertADC( ); /* start A/D conversion */
while(BusyADC( )); /* wait for completion */
/* Get results and store at Ports D & B */
LATD = ADRESL; /* Results Register Low displayed, least sign on Port D */
LATB = ADRESH; /* Results Register High displayed on Port B */
CloseADC( );
Delay10KTCYx(200); //1second delay
}
}