Why does the program counter not reach the start of main()?
There are a few possible causes. Here are some causes to consider:
- The device linker script or linker command line is inadvertently modified. Check to see if a linker file is in the project tree since this means that a custom linker is used (MPLAB® XC16, XC32), or for command line linkers (MPLAB XC8), start a new project with the same device, and see if the build output command line is different between the new project and the project with the issue.
- The default C startup code is not linked to the project.
- The C startup code is being customized and the branch to main is never reached due to a bug in the modified C startup code.
- The device is resetting before main() can be reached due to a POR, BOR, WDT, or another reset.
- The clock is failing (often a hardware issue). Use an internal oscillator if available for test purposes.
- The device is not experiencing a proper POR. (VDD slew rate specs are being violated or the device is not released from reset).
- The entry point into main() is not defined by the linker.
- There is a hardware issue, like a single disconnected VDD pin. Attempting to duplicating the issue on a Microchip demo platform usually isolates the problem to your hardware when the root cause of the issue lies in the hardware.
- The device errata sheets have not been investigated.
- An unresolved breakpoint is placed at the start of main() (due to optimizations) and you interpret this as main() never being called.
- You have two projects open at once and they are debugging the wrong project and expecting main() to be reached in an inactive project.
- The device has suffered electrical damage. Swap the device with a new one and see if the issue remains.
- The device is only partially programmed. In the device development tool settings, manual memories and ranges have been selected in a way that cuts off the startup code.