1
\$\begingroup\$

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:

Configuration Bits

I do have a 10K resistor between MCLR and VDD, and the Build Configuration is set to "Release".

\$\endgroup\$
  • \$\begingroup\$ what happens when you do a power cycle? \$\endgroup\$ – Andy aka Oct 27 '13 at 15:56
  • \$\begingroup\$ Red LED's come on, followed by Blue and Purple. They never change after that. \$\endgroup\$ – sacredfaith Oct 27 '13 at 20:59
  • 1
    \$\begingroup\$ Have you got proper decoupling of the supply rails i.e. 100nF capacitors on the supply pins to ground? What about your circuit board or whatever you built the circuit on? \$\endgroup\$ – Andy aka Oct 27 '13 at 21:01
  • \$\begingroup\$ Yes on the decoupling. The circuit board I'm using is a pretty standard breadboard. This morning, I just plugged it in, and the LEDS all lit up. Once I plug in the ICD3 (regardless if MPLAB is running), the program will start running, and everything works properly. Once the ICD3 is disconnected, it stops working. \$\endgroup\$ – sacredfaith Nov 1 '13 at 12:40
0
\$\begingroup\$

Thanks so much to Andy aka for helping me eliminate potential causes!

The real reason as to why this occurs is due to Microchips "Low Voltage Programming" mode that is a part of the PIC16F819 architecture, and the fix is explained in more detail here.

The fix, according to the post, was to ground the PGM pin with a 10k resistor (I grounded it outright and got it working).

Alternatively, as another poster in the same forum notes: is to set ICSP to high voltage (via the configuration bits), disable the LVP pin in code (which wasn't necessary for me, but I'm leaving it here as it was contained in the original post), as well as putting a resistor between VDD and the MCLR pin.

\$\endgroup\$

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.