I've moved your post to the correct section of Edaboard.
The reason it only runs once is that at the end of main() the program terminates, in your case it probably crashes or tries to run random instructions beyond the end of the program. To make it repeat you need to put it in a loop. There are several methods:
Code:
while(1)
{put the code here}
will run forever because the '1' equates to 'true'.
Code:
for(start value, end condition, change to value)
{put the code here}
will run until 'value' changes from it's starting value unto the end condition is met.
Code:
do
{put the code here}
while(condition);
will run once then if the condition is met, will repeat.
The ADCON0 code first makes the channel select bits zero using the &= mask so you have a known starting point then aligns the new channel selection bits by shifting them to the left twice and finally ANDs then with ADCON0 using the |= function. It's a common way of substituting several bits in another value, in this case the bits to select the channel in the ADCON0 register. When this is done, ADCON0 is configured to use the ADC input selected by the 'channel' variable.
Brian.