3.6.4 Why Can’t I Even Blink an LED?
Even if you have set up the TRIS register and written a value to the port, there are several things that can prevent such a seemingly simple program from working.
- Make sure that the device’s configuration registers are set up correctly, as discussed in 7.3 Configuration Bit Access. Make sure that you explicitly specify every bit in these registers and don’t just leave them in their default state. All the configuration features are described in your device data sheet. If the configuration bits that specify the oscillator source are wrong, for example, the device clock may not even be running.
- If the internal oscillator is being used, in addition to Configuration bits there may be SFRs you need to initialize to set the oscillator frequency and modes, see 7.4 ID Locations and your device data sheet.
- To ensure that the device is not resetting because of the watchdog time, either turn off the timer in the configuration bits or clear the timer in your code. There are library functions you can use to handle the watchdog timer, described in the 32-bit Language Tool Libraries manual (DS51685). If the device is resetting, it may never reach the lines of code in your program that blink the LED. Turn off any other features that may cause device Reset until your test program is working.
- The device pins used by the port bits are often multiplexed with other peripherals. A pin might be connected to a bit in a port, or it might be an analog input, or it might be the output of a comparator, for example. If the pin connected to your LED is not internally connected to the port you are using, then your LED will never operate as expected. The port function tables in your device data sheets will show other uses for each pin which will help you identify peripherals to investigate.