Once I have the hardware setup I can begin to read from it. On the right you can see the code which does this. The key part is the code which actually gets the number converted.

/* enable the converter and start */
/* a conversion                   */
ADCON0 = 0x05;

Remember that we are in bank 0 most of the time, and this is where ADCON0 lives. I set two bits in this address, one of them (bit 0) turns on the ADC and the other (bit 2) starts the conversion. Being lazy, I do this each time I do the conversion. In a real program, where you might be concerned about power consumption you may want to turn the ADC hardware on and off since it does consume extra power. If you are not going to use it for a while it should be disabled. Note that other bits in this register control how fast the conversion is performed, and whether an internal or external clock is used. Once I've got the conversion process going I must then wait until it completes.

/* spin while the conversion runs  */
while (ADCON0 & 0x04 );

The bit 2 (representing the value 4) is the one which is cleared by the ADC hardware when the conversion is complete. I'm not sure how long in absolute terms the conversion takes; I put a counter in there and found that it reached two or three before the conversion finished. This is with the system set to fastest (and therefore least accurate) conversion. The bottom line is that when this condition fails the program will stop performing the while loop and then move on to the next statement. If this statement looks a bit strange, then don't worry it does work.