I can't seem to get the A/D to work correctly. I have tried different configs yet no luck. The pin I am using to measure voltage is RC0/AN4/C2IN+. So I configure the pin to analogue with ANSEL.4=1, disable the comparator with CM2CON0.7=0 and select the analogue bit with ADCON0.5-2.

I check voltage at the pin with my scope and its .650v. Yet debugging I get a value of '0' with any input from 0-5v. Any input is appreciated.

Code:
INCLUDE "modedefs.bas"
  
FF           var PortC.0
FrontOut     var PortC.1
RearOut      var PortC.2

Voltage      var word
Perfect      var word

define OSC 20
DEFINE DEBUG_REG PortC          'SET DEBUG PIN PORT
DEFINE DEBUG_BIT 5             'SET DEBUG PIN BIT
DEFINE DEBUG_BAUD 9600         'SET DEBUG BAUD RATE
DEFINE DEBUG_MODE 1            'SET DEBUG MODE 0=TRUE / 1=INVERTED

Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 10 ' Set sampling time in uSec

TRISC.0 = 1  'FF (Flip/Flop)
TRISC.1 = 0  'FrontOut
TRISC.2 = 0  'RearOut

'0 Digital 1 Analogue
ANSEL.6=0 'RearOut
ANSEL.5=0 'FrontOut
ANSEL.4=1 'FF 

CM2CON0.7=0 'Disable comparator

ADCON0.7=1 'Right Justified
ADCON0.6=0 ''Voltage reference is VDD
ADCON0.5=0 'Turns on AN4 to analogue
ADCON0.4=1
ADCON0.3=0
ADCON0.2=0
ADCON0.0=1

Perfect = 512

Loop:
  GOSUB Get_Voltage
  gOSUB Compare
  debug "Voltage=", DEC VOltage, cr
Goto Loop

Get_Voltage:
ADCIN FF, Voltage
Return

Compare:
If Voltage < Perfect then
   Low FrontOut
endif

If Voltage > Perfect then
   Low RearOut
endif
Return