Hi,
First, check the ADCON1 register (it's commented out in your code) and the CMCON register (not included in your code) against the datasheet and make sure all pins used as digital are setup as digital.
Second, you're doing a lot of consecuitive bit-operations on the port registers which, depending on pin loading and oscillator speed, can suffer from RMW-effects. Since you're on an 18F part try changing the aliases from PORT-register to LAT-register for all pins acting as outputs.
Third, I'm surprised RB6 and RB7 is working properly as outputs since you have their corrsponding TRIS bits set (ie pins are inputs).
/Henrik.
Bookmarks