Hello All-
I am working with a new chip (to me) and I am having difficulty in understanding how to figure the A2D on the 18F46K80.
I looked into a post by Darrel on TAD but I don't seem to be able to get the LCD to display anything like I think it should.
I am trying to monitor the 5 volt line to the proc. AN0 is fed from a voltage divider 4.53k to +5 and 8.25K to ground.
I have never used a 12 bit A2D and I am certain it is stupid silly, but I can't seem to get it.
Code is below, includes configs, defines, sub-routine, and test code.

Any advice would be greatly appreciated
-Steve
PS - going to have to try to get the formatting correct one of these days when posting!.......

'Define configuration
#CONFIG
CONFIG RETEN = ON ;Ultra-low regulator ON
CONFIG FOSC = EC3 ;External HS oscillator, port function on RA6
CONFIG INTOSCSEL = LOW ;LF-INTOSC in Low-power mode during Sleep
CONFIG SOSCSEL = DIG ;Digital (SCLKI) mode
;FCMEM doesn't seem to work here.....
; CONFIG FCMEM = OFF ;Fail Safe CLock Monitor is OFF
CONFIG IESO = OFF ;Internal/External oscillator switchover is OFF
CONFIG PWRTEN = ON ;Power Up timer is ON
CONFIG BOREN = OFF ;Brown Out Reset is OFF - for now
CONFIG BORV = 0 ;Brown Out level is 4.6v
CONFIG WDTEN = OFF ;Watchdog is OFF - for now
CONFIG MCLRE = ON ;MCLR pin is ENABLED
CONFIG STVREN = ON ;Stack FULL/UNDERFLOW reset is ENABLED
CONFIG BBSIZ = BB1K ;Boot Block size - 1K?
CONFIG XINST = OFF ;Extended Instructgion set is DISABLED
#ENDCONFIG

'---------------------------------------------------------------------------------------
'Define the oscillator and setup the INCLUDE files
DEFINE OSC 64 '64 MHz oscillator, external
INCLUDE "DT_INTS-18.bas" 'Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" 'Include if using PBP interrupts

'---------------------------------------------------------------------------------------
'OKAY, Lets set up the registers.....
OSCCON= %00001000 'Device enters SLEEP mode when SLEEP is executed
OSCCON2= %00000000 'System clock comes from other osc than internal
REFOCON.7=0 'Refrence oscillator is DISABLED
WPUB= %00000000 'PORTB pullups DISABLED
PADCFG1= %00000000 'ALL pull up resistors DISABLED on ports D,E
ANCON0= %00000001 'Selects AN1-AN7 as DIGITAL, AN0 as ANALOG
ANCON1= %00000000 'Selects remaining analog/digital inputs as DIGITAL
ADCON0= %00000000 'Turns OFF ADC - REMEMBER TO TURN IT BACK ON AFTER DEBUG-, selects AD0 as input
ADCON1= %10110000 'Vref is INTERNAL 4.1v and AVss
ADCON2= %10100110 'RIGHT justified, 8 TAD A2D aq time select, Fosc/64
T0CON.7=0 'DISABLES TMR0
CM1CON= %00000000 'Turns OFF CM1 comparator
CM2CON= %00000000 'Turns OFF CM2 comparator
CVRCON.7=0 'Comparator voltage ref is powered DOWN
HLVDCON.4=0 'High Low Voltage Detect is DISABLED
CCP1CON=%00000000 'Turns OFF capture, compare, pwm
CCP2CON=%00000000 'Turns OFF capture, compare, pwm
CCP3CON=%00000000 'Turns OFF capture, compare, pwm
CCP4CON=%00000000 'Turns OFF capture, compare, pwm
CCP5CON=%00000000 'Turns OFF capture, compare, pwm
CANCON=%00100000 'CAN disabled
CTMUCONH.7=0 'CTMU disabled
INTCON= %00000000 'INT0 and POIRTB change external interrupt is DISABLED
INTCON2= %01111100 'PORTB pullups enabled by TRIS, int are RISING edge, TMR0 hi and rest low priority
INTCON3.3=0 'Disables INT1 external interupt
IOCB= %00000000 'PORTB interrupt on change all bits DISABLED
SLRCON=%00000000 'Slew rate for all ports is STANDARD
SSPCON1.5=0 'MSSP port is DISABLED
ODCON=%00000000 'Open Drain capability is DISABLED
PSTR1CON= %00000000
' MDCON=%00000000 'Modulation Control is DISABLED
'---------------------------------------------------------------------------------------
'Direction registers
TRISA = %10001011 'Set PORTA for bit7 is clk in, 2 led out, 1 temp in, 1 A/D in, ext Vref
TRISB = %11001111 'PORTB is ICSP, 2 pins for LCD, low nibble for 4 button inputs
TRISC = %10001111 'Set RC7 (RX), rest are outputs, low 4 bits used as inputs for addressing
TRISD = %10000000 'Set PORTD for serial, 1 LED, 4 LCD data
TRISE = %00001000 'Set PORTE for MCLR, low 3 bits for addressing - high order not used
'----------------------------------------------------------------------------------------
'Constants here
sync con $54
Line1 CON 128 'Point to beginning of line 1 ($2)
Line2 CON 192 'Point to beginning of line 2 ($C0)
Line3 con 148 'Point to beginning of line 3 ($94)
line4 con 212 'Point to beginning of line 4 ($D4)

'----------------------------------------------------------------------------------------
'Define the Analog to Digital conversions
DEFINE ADC_BITS 12 '12-bit resolution
' DEFINE ADC_CLOCK 5 'Set clock source to Frc/16
DEFINE ADC_CLOCK 6 'FOSC/64, 0.8uS @ 64Mhz
DEFINE ADC_SAMPLEUS 50 'Sample time in uS before A/D conversion is started

'-----------------------------------------------------------------------------------------
ADCval var word 'Result of 12 bit ADC
ADCavg var word 'Running ADC average


Volt:
ADCON0=%00000011 'Start ADC conversion, channel AN0
while ADCON0.1 = 1 :wend 'Wait for ADC DONE
ADCval.highbyte = ADRESH 'Move HIGH byte of result to adcVAL
ADCval.lowbyte = ADRESL 'Move LOW byte of result to adcVAL
ADCavg=ADCavg+ADCval 'Add latest ADC reading to running total
return

'-----------------------------------------------------------------
PB:
'Get PBs to work and print to LCD
gosub volt
if PB1=1 then lcdout $FE,line1,"+5 volt= ", dec ADCavg," "
lcdout $FE,line2," "
lcdout $FE,line3,DEC (temperature / 100), ".", DEC2 temperature, " F "
' lcdout $FE,line4," " 'Display done with init
pause 100 'Display for a while
goto PB