Originally Posted by
phoenix23
Hi i have this piece of code and was wondering where it returns the value?
Code:
void ReadPOT(void)
{
ADCON0bits.GO = 1; // Start AD conversion
while(ADCON0bits.NOT_DONE); // Wait for conversion
return;
}//end ReadPOT
i just wanted to check also that this means that the number 1 is put into the member named GO.
I'm not sure how NOT_DONE as a member would detect whether the AD conversion has completed - does anyone have any idea? how can using a dot operator here check a bit inside the ADCON0 register?
A guess is that ADCON0bits is declared as a structure with bitfields, and some of the names of these bitfields are GO and NOT_DONE. And I would further guess that some implementation specific method is used to absolutely place this structure atop the location of a status and control register for A/D conversion. And as Salem mentioned, it is also likely volatile qualified to keep the optimizer away from the idle loop code. All of this magic is probably found in some platform-specific header.
So this:
Code:
ADCON0bits.GO = 1; // Start AD conversion
is used to set that particular bit in the register (which starts the A/D).
Then this:
Code:
while(ADCON0bits.NOT_DONE); // Wait for conversion
is an idle loop that waits for the A/D conversion to complete, at which time the bit corresponding to NOT_DONE is cleared -- by the micro.