Electronic – PIC’s output pin not turning LED on

ledmicrochippic

I've been trying to test my PIC just by turning a LED on, I verified that the PIC is energized and that the MCLR pin is HIGH.

The PIC I'm using is the PIC18F45K22, running at 3.3 volts.

The LED has a Vf of 1.8 volts and I have verified that its polarity is correct. It is connected to pin RB4 with a 1 kΩ resistor in series.

Not sure what else to try here. I have only 1 LED connected and that's RB4, is there something that might be blocking RB4 from giving the output? Is there anything else that I have to setup?

This is my complete source code:

#include <p18f45k22.h>

void main(void)
{
  ANSELB = 0;
  TRISB = 0;
  while(1)
  {
    LATBbits.LATB4 = 1;
  }
  return;
}

Best Answer

Sounds to me as thought your oscillator settings are incorrect. Some modes will have your PIC just stall waiting for a correct clock. Interestingly enough, I've been able to program and verify a pic32 with a broken oscillator.

  1. Make sure you set your configuration bits corresponding to the board you have.
  2. Verify that the board has proper bypass capacitors.
  3. If you have access to an oscilloscope, verify that the oscillator is running by probing on the driven pin (refer to the oscillator section of the PICs family datasheets).
  4. Also try running with the internal oscillator.