To use PBP but without ADCIN, you first have to set-up your ADC Registers... I'll walk you through this with your PIC16F877, but for any PIC the proceedure is essentially the same...

1. Get the Datasheet

Check what Registers are used for ADC... ADCON0, ADCON1, ADRESH, ADRESL. The last two are just for reading the results.

2. Decide 8-Bit mode or 10-bit mode?

If you want 8-bits, then the result is going to be LEFT justified, and read from ADRESH only. The lower bits in ADRESL are ignored. If you want 16-bits then the result is going to be in both registers. You want RIGHT justification and ADRESH becomes the Highbyte of your resultant word, and ADRESL is the Lowbyte.

3. Set-Up the Registers.

First set-up which ADC's you're going to be using, what voltage reference, 8 or 16 bit mode, and TRIS bits. Let's say we're only going to use AN0/RA0 and everything else is Digital with our Voltage Reference being Vdd and Vss. Let's also say we're going to use 10-bit mode... (check Datasheet 11.2 to see what I've done)...

TRISA=%11111111
TRISE=%11111111
ADCON1=%10001110

Now I've set TRISA and TRISE both to INPUT's, but they can be INPUT or OUTPUT however you wish. Only Bit 0 of TRISA must be an INPUT (which is the ADC pin we're playing with).

We also need a variable to play with... since we're going to use 10-bit ADC, we'll need a Word...

MyWord var WORD

Next we configure the remaining Bits of ADCON0... Here we decide on the clock source for the ADC, the channel we're going to use, and we're going to switch-on the ADC so it's all ready for when we need it... This actually can all be done at Read-time... so straight into our ReadADC routine...

ADCON0=%01000001
' Set Fosc, Select Channel, Turn-On A/D - Check Datasheet 11.1
Pauseus 50
' Wait for channel to setup
ADCON0.2 = 1
' Start conversion
While ADCON0.2=1:Wend
' Wait for conversion
MyWord.Highbyte=ADRESH
MyWord.Lowbyte=ADRESL
' Read result from ADC into variable

There's a few alternatives you can try... if you switch-on the ADC when you initialise your PIC, you can dispose of the 50uS pause and jump straight into the read routine by setting the ADCON0.2 start Flag. That might just save you a few uS at each conversion if you really need them. However, if you're switching between multiple inputs (rather than fixed at just one input as in our example), it's better to keep the 50uS delay to allow everything to settle and the sampling capacitor time to charge to the new input value.

So, you can see there are very few lines of actual code. Set the registers up, start the conversion by setting the ADCON0.2 Flag, and when the flag drops you pick up yor result. It really doesn't get any easier than this.

Melanie