Great information (and you are closer to a solution) -
Let me make sure I understand

- The code works on a 16F876 but not a 16F877A
- The alive test does not work on the 16F877a when inserted into your code and the PIC inserted into your circuit
- The same16F877A works when tested with other code in another circuit

If the above is all true, it sure sounds like a hardware / config issue.

What do you have connected to pin 1 of the 877A

Describe your power supply?

Do you have all four Vdd and Vss pins connected?

Do you have decoupling caps between each pair of Vdd and Vss?

What are your config setting?

What are you using for an oscillator?

What registers are you using and how are they set?

If we cannot find the problem with this information, the nest step is to post a schematic and code.

Paul Borgmeier
Salt Lake City, Utah
USA