I have written a simple program that turns different colored LED's on and off at different intervals. When I program the chip (a PIC16F819), the program runs perfectly, and all is well. However, the moment I disconnect my ICD3 from the setup, it seems like the program halts (or the circuit saturates, or something is happening with MCLR, not sure) and all of my LED's turn on, and stay there. The program is as follows:
#include "pic.h" // load pin names
#include <htc.h> // load delay library
#ifndef _XTAL_FREQ
// Unless already defined assume 4MHz system frequency
// This definition is required to calibrate __delay_us() and __delay_ms()
#define _XTAL_FREQ 31250
#endif
void main() // this is the main program
{
TRISB=0B00000000; // set all pins on port B as output
// XXXBXPRX
while(1) // execute the following code block forever
{
PORTB = 0b11111111; // turn all port B pins ON
__delay_ms(5000); // pause 1 second
PORTB = PORTB & 0b00010100; //turn off Red
__delay_ms(7000);
PORTB = PORTB & 0b00010000; //turn off Purple
__delay_ms(7000);
PORTB = PORTB & 0b00000000; //all off
PORTB = PORTB | 0b00000010; //turn on Red
__delay_ms(7000);
PORTB = PORTB | 0b00010100; //turn on Blue and Purple
PORTB = PORTB & 0b00010100; //turn off Red
__delay_ms(7000);
PORTB = PORTB & 0b00000100; //turn off Blue
__delay_ms(7000);
PORTB = PORTB & 0b00000000; //all off
PORTB = PORTB | 0b00010010; //turn on Red and Blue
__delay_ms(7000);
PORTB = 0b00000000; // turn all port B pins OFF
__delay_ms(3000); // pause 1 second
}
}
And my configuration bits are set up like this:
I do have a 10K resistor between MCLR and VDD, and the Build Configuration is set to "Release".