Quote Originally Posted by flotulopex View Post
Don't use a VAR to define the A/D channel. Use the channel's number instead:
Code:
ADCIN 5, bat
I strongly disagree with this. First, in this particular example, he's using Ai as a constant, not a changing variable. That allows you to change PICs (or PIC pins), and just change the setup constant, without searching for all of the references to the pin.

Second, there is nothing wrong with using a variable variable to read adcin.

What you did do wrong, however, is you referenced the AN# with a PORT#. You don't do that. You should only use the ANx number; in this case, assuming your comments are your target, 6, NOT Portb.7.

Correct:
adcin 6, bat
NOT Correct:
adcin portb.7, bat

Correct:
Ai var 6 'Notice we use "x" of ANx.
adcin Ai, bat

NOT Correct:
Ai var portb.7 'Do NOT use the Port pin the ANx is on.
adcin Ai, bat