First; when you look at a Special Function Register in the Data Sheet, there are letters & numbers above each Bit in the Register. For example, ADCON0 bit 7 (denoted as ADCON0.7) has "R/W-0" above it. This means you can read that bit (Bit_Var = ADCON0.7), you can write to that bit (ADCON0.7 = 1), and the default value is "0" (R/W-0). ADCON1 is just your A/D Conversion Clock selector, which is handled with your "DEFINE ADC_CLOCK 3" statement. Get rid of your "ADCON1 = %10000010" statement. First, it is handled with the DEFINE ADC_CLOCK 3", secondly, you have bits 7 & 2 set which are not used and default to 0.
Starting on page 73 (Section 9.0) of the PIC16F610/16HV10_PIC16F616/16HV616 Data Sheet (which you can download from Microchip.com) the ADC Function is covered. Read that section to get a better idea of what you're asking the PIC to do for you. On page 78 (Register 9-1) is the ADCON0 Register. Look at the ADFM bit (bit 7 on the left). It determines if the result is Left or Right Justified. To better understand what that means, look at Registers 9-3, 9-4, 9-5, and 9-6 on page 80. If you wanted an 8-bit result you would Justify Left (ADCON0.7 = 0) and simply read ADRESH. If you want a 10-bit result, Justify Right (ADCON0.7 = 1) and read ADRESL into the LOWBYTE of your variable, and ADRESH into the HIGHBYTE. This isn't covered in the PBP3 Reference Manual, and you don't need to know it to use the ADC feature with PBP3. However, it helps to at least understand what's under the hood.
Next, look at Section 4, starting on page 33 of the Data Sheet. It covers I/O Ports. Register 4-1 is your PORTA Register; 1 = HIGH, 0 = LOW. Next is your TRISA Register, which stands for TRIState. Bits 7-6 are shaded grey as this PIC only has PORTA <5:0>, there is no PORTA.6 or 7. Next, if the bit is clear (0) the port is configured as an Output. If the bit is set (1) it is configured as an input. An easy way to remember this is a number 1 looks like the letter I for Input. The number 0 looks like the letter O for Output. Register 4-3 is your ANSELA Register, which is used to denote Input ports as Analog Inputs. A "1" makes it analog. You must configure the port as an Input in the TRISA Register for the ANSELA Register to work. Setting an ANSELA bit on a pin set up as an output in the TRISA Register can cause unpredictable results (on some PICs it causes a current overload). And now for one that I think may be causing you issues, the WPUA Register (Register 4-4 on page 35). Remember the number above the Bit in the Register denotes the default value. The Weak Pull Up Enable is defaulted to ON. Unless you turn it off with the WPUA Register, it could be causing you...well, what you described. "WPUA = 0" is a quick fix.
Take a weekend to read through the Data Sheet. It's a lot to absorb, but your answers are always in there. Although I've never worked with the PIC16F616, it looks like a pretty good one. I hope this helps.
Bookmarks