You've come to the right place...

Rather than give you an 'answer on a plate' (I'm feeling mean), I'll throw you in at the deep end to sink or swim... figure this and you'll know what to do with any PIC you'll ever encounter from now on... so a bit of pain now makes for a real easy life later...

You've obviously not read the DATASHEET for the 16F877.

Step 1. Download it from the Microchip website.

Step 2. Arm yourself with a Beer or a Glass of Warm Milk.

Step 3. When you've woken, you'll discover the pretty pictures at the start of the datasheet (pin diagrams) tell you that PortA and PortE (and others) are multifunction Ports multiplexed with various goodies (such as Analogue functions).

Step 4. Since PortA and PortE features are SHARED between Digital I/O and Analogue I/O... and by default on Power-Up they are ANALOG (discover that from the Special Features of the CPU Section what the Initialisation (Power-Up) conditions are for all the Registers). You need to switch them to DIGITAL before you perform any I/O on them. Go to the Section marked Analgue to Digital Converter Module... you will discover what REGISTER settings you need to switch those ports to DIGITAL in that section.

Step 5. If you have an 16F877A, you need to repeat Step 4 whilst looking at the COMPARATOR Module Section as well.

This excercise will tell you that if a pin has multiple functions, you need to discover how to turn on the features you want, and turn off those you don't want. You NEED to do that FIRST, before you start using that pin. The Datasheet is your bible on this. So when looking at RD5/PSP5, you need to discover "What is PSP5?" and is it going to get in my way when I want to use RD5 for Digital I/O. Look in the Datasheet for the answer to that.

Come back and tell us how you've done, or if you need a few more pointers. Trust me, the Datasheet is your friend... everything you need to know about your chosen PIC is in there... go get...