It’s really hard to say exactly. It sounds like you are designing and building your own system. So without seeing the schematics of what you’ve build it’s hard to do remote diagnostics.
Things that can easily burn up parts of the PIC chip are overloads on the ports. The output ports to the HBridges can easily be over-driven (put out more current) than they are rated for. This will cause just that port to fail.
Your HBridge is also prone to excessive current flow which may damage the control parts or one leg of the bridge. It’s also possible that back EMF (caused when your DC motor becomes a DC generator) feeds into the HBridge backwards and destroys the drive transistors.
Off the top of my head that’s the two places I’d look (after low battery and loose connections)
I would agree that what you are describing sounds like back-EMF is damaging the microcontroller. The inline resistors will help protect against this some, but it’s still possible that enough current could pass back through them to damage the control logic (can’t be exactly sure without knowing the value of the resistors and what their current rating is). What I’ve seen a lot of people do when constructing circuits like this is to use opto-isolators between the microcontroller and the motor drivers, which is a pretty standard way of eliminating back-EMF.
Like was mentioned, I would suspect that after the circuit stops working, that the program is actually still running but since the port circuitry is damaged you won’t see any output. If you’re certain that the code is not actually running, it’s possible that instead of the microcontroller, some of the power/clock circuitry could have been damaged. Usually the PIC Programmers supply their own power and clock signals, so this would account for it working while programming, but not otherwise.
If it is back-emf problem , could I use diodes to protect my Microcontroller from it ? and if yes , where to put the diodes in transistor , is it on Base ?
By the way , the value of resistors is 500 ohm , and the transistor is TIP-31