1
\$\begingroup\$

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;
}
\$\endgroup\$
  • 1
    \$\begingroup\$ have you verified that the LED itself isn't dead? \$\endgroup\$ – Makoto Mar 15 '17 at 7:41
  • \$\begingroup\$ Have you measured the output of your pin? Also try to measure it without the LED connected. See if you actually get the voltage. \$\endgroup\$ – Arsenal Mar 15 '17 at 7:42
  • \$\begingroup\$ I verified that the LED is not dead and it would be hard to measure the output of the pin without the LED connected because it's a PCB and it's all soldered but I checked another PIN and tried to set it to high with ANSELC = 0, TRISC = 0 then LATCbits.LATC0 = 1; in the code and it didn't set it as high. I measured the output of the LED pin and it's 0V \$\endgroup\$ – Yasu Flores Mar 15 '17 at 7:55
  • \$\begingroup\$ Are you running the PIC at 5V or 3.3V? What is the forward voltage of the LED? \$\endgroup\$ – Roger Rowland Mar 15 '17 at 8:04
  • 4
    \$\begingroup\$ You have no config settings in your code - is that all you have? If not, please show the config bits too. \$\endgroup\$ – Roger Rowland Mar 15 '17 at 8:20
2
\$\begingroup\$

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.
\$\endgroup\$
  • \$\begingroup\$ thanks Mathieu! I tried using the internal oscillator and it worked! the external oscillator that I'm using might be damaged. Appreciate your help! \$\endgroup\$ – Yasu Flores Mar 16 '17 at 7:02
1
\$\begingroup\$

These what i have in mind try any of the following: 1- try to use a different pin say portB pin3 2- reduce the resistor value make it 450 ohm. 3- add delay to your code. 4- make sure that you are connecting the LED in an active high connection (anode to the PIC and cathode to GND)

\$\endgroup\$
0
\$\begingroup\$

Two things.

1 set the fuse.

  1. Initialize the pins as goio.

edit: your code, when it is done right.

enter image description here

\$\endgroup\$
  • \$\begingroup\$ Wow someone is in a bad mood voting this down. Who's simulator? I'll fix the down vote. I always liked ^=, elegant. \$\endgroup\$ – Misunderstood Mar 15 '17 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.