How do you use port manipulation to retrieve the value of an analog pin?
I have an Arduino Duemilanove and I am trying to use "Port Manipulation" [Arduino Reference - Arduino Reference] to retrieve the value of an analog port. Apparently you can access it via the PIN register or the port which I can understand for the digital pins which have a HIGH / LOW state but, I don't understand how that works for the analog pins.
I have read halfway a tiny datasheet but maybe the atmega does it a similar way. In order to read an analog pin you have to:
Set up analog mode. You can have differential mode with amplification factor, or a single ended mode (you compare a pin with a predetermined value). Basically in this step you say on which pin you will compare what.
Start analog mode. You can have it running all the time and read the results from time to time or you can have it fire an interrupt for you when a comparison completes.
Read results. Results are aligned and stored in 2 registers (ADCH, ADCL) which are 8 bit and store the 10 bits of data read.
So basically it's a little more complicated (it means that you have to write 10 times more code, or 30 lines of code instead of 3-4 lines).