Hi,
16F877a has got a Power Control Register (PCON). Section 14.10 page 151 in the datasheet.
In the top of your code just after you initialize the LCD. Read the PCON into some variable and display it on the LCD for say 5 seconds. Note it down just after a reset. This may help decide the cause of the reset---> Brown Out, WDT, MCLR etc.
Also make sure that your RB3 (Pin 37) is not floating. It is the LVP pin and noise on that can trigger the ICSP mode.
Just for information on the opto part you can use a TLP250 optocoupler (works upto a few khz) which has got a totem-pole output. So you drive the LED and get a 0-1 on the output. I use it mainly for my IGBT driver needs.
Bookmarks