That's because you've got your A/D converter set up for Left-Justified operation (see the PIC16F870 datasheet, section 11.0, Register 11-2, left-justified is the default operation).
You're peeking $1E, which is ADRESH (A/D result High), the upper 8 bits of the A/D result. You have to peek the other, lower, 2 bits out of the upper 2 bits of $9E.
So try this (I assume you're using PicBasic, and not PicBasicPro, and I'm not 100% with the limitations of PicBasic):
Poke $1f, $45
pause 1
peek $1e, w3
peek $9e, w4
w3 = w3 * 256 'put adresh BYTE into upper 8 bits of w3 (that's a word variable right?)
w3 = w3 + w4 'add adresl into adresh word
w3 = w3 / 64 'shift the whole result down by 6 bits for a 0-1023 result
Bookmarks