Electronic – PIC18F2550 runs and then stops

oscillatoroscilloscopepic

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.

enter image description here

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.

enter image description here

Here are the parts that I'm using

Crystal
Crystal Capacitors

Best Answer

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.