# PIC18F2550 runs and then stops

I have a PIC18F2550 that I'm trying to get a simple hello world type program to run on. The code is configured to flash an LED on and off with 250ms delays in between the cycles. I have a 4Mhz crystal attached to pins 9 and 10 with 2 18pF capacitors. When I attach my oscilloscope to the output pin and power on the chip, I can see the high low signals go from 0V-5V for about 3-5 seconds then it just flat lines.

If I power the chip off for a while and plug it back in, it starts to work again, but after 3-5 seconds it will go to 0 again.

What can I do to troubleshoot this problem?

Update

I should also add that after repeating the whole process several times (i.e. powering on and off the device), it eventually won't turn on the output at all.

I've tried multiple PIC18F2550 chips with the same software and get the same effect, so it's not the PIC processor.

I'm thinking this must be a hardware issue since the software was copied from a working sample. In case someone thinks it is a software issues, here's the MikroC code (although I don't think this is the right Stack Exchange site for source code):

void main() {
TRISB = 0; //Make all PortB pins output

while(1)
{
PORTB = 0; //Turn off the port
Delay_ms(250);
PORTB = 255; //Turn on the port
Delay_ms(250);
}
}


Here a (very) rough schematic of the circuit. I have the scope hooked to pin 24.

Here are the parts that I'm using

• You need bypass capacitors across the power supply connections. As a 0.1 uF capacitor between pins 19 and 20, as close as you can get it to the IC. – Connor Wolf Jul 20 '13 at 3:05

In my experience accidentally leaving the _MCLR pin floating causes erratic behaviour such as yours. Make sure it is tied to +5V through a resistor (47kΩ or so), in order to prevent the PIC from randomly resetting.

• @Matt The data sheet specifies that the _MCLR pin is connected to some voltage (+5V here) (they are programmable after all) and not to let it get above the system voltage . If it does it enters programming mode. So for all micro's (and a lot of IC's in general) attach all the supply and ground pins plus anything left floating should have a good reason to be floating other wise pull them down or up with a resistor (I prefer resistors because you can override them during debugging without breaking tracks). – Spoon Jul 21 '13 at 0:05
• Yeah, I've read that before, but up until now I've gotten away without doing it (I guess my luck ran out). I'll be sure not to leave pins floating in the future. Thanks for the tip. – Matt Ruwe Jul 22 '13 at 12:05

Usually setting breakpoints is the best way to go at it, but this seems like an initialization/setup problem.

Try disabling the watchdog

   WDTCON  = 0;


Did you setup your oscillator? How about clear most registers? (TRISx, INTCON, TxCON, UCON, etc..)

• I have configured the oscillators and setup the proper TRIS register - the examples that I've seen look like all I need to do is configure the TRISB register. – Matt Ruwe Jul 19 '13 at 21:57
• Are you using a forever while loop? while(1){ [code] }; – Iancovici Jul 19 '13 at 22:00
• Yes, I'll add the code to my post, although, I don't think this is a software problem. – Matt Ruwe Jul 19 '13 at 22:02
• FYI, I tried disabling the watchdog, but it didn't help. Any other ideas? – Matt Ruwe Jul 19 '13 at 22:15
• Can you give us ALL the config info, a circuit diagram, and some datails on how you're powered and bypassed? You'll get a better answer, and faster. A part number for your crystal might also help to see if 18 puffs is the right number – Scott Seidman Jul 19 '13 at 23:38