# Run a program on a PICKit 2 chip

I've got a PICKit 2 with a PIC16F690 chip plugged in, and installed MPLAB and made a sample program in C, which compiles fine. However, there's only the option to "Program to target device", "Read from target device", or some other options to erase memory, all of which work fine, but I can't work out how to actually make the program run on the chip. MPLAB says I can't debug the chip:
"PK2Error0028: Unable to enter debug mode"
"NOTE: This device requires an ICD Header for debug. See "Header Specification" DS51292." After some research, apparently I need a different interface board to debug it.
When debugging, the option to run the program comes up, but when set to "Release" mode, it only gives the option to read/write/erase from the board. How can I run it?

The code is as follows:

#include <htc.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv) {
return (EXIT_SUCCESS);
}


Which doesn't actually do anything yet

"PK2Error0028: Unable to enter debug mode"

Is it a genuine PICkit2? Many cheap clones cannot debug.

When you program the chip you place the code onto the chip. When you aren't programming the chip, if MCLR isn't held low, the program is running. You don't "run" the program, it just runs unless told specifically not to.

You need what Microchip calls a "Debug Header" in order to debug this chip. The Debug Header brings out all of the chip's I/O pins for your use and includes extra pins that connect to the debugger (PICkit or ICD).

The easiest way to see if your chip is working is to include some very simple LED blink routines and see what happens when you run the chip with just power supply and the LEDs.

Be sure to hold MCLR HI when testing your blink code.

What's there to run? Your program starts and immediately exits. Embedded program should never exit main. Instead there should always be some sort of infinite loop.

Something like this:

#include <htc.h>

void init_io()
{
// init timer(s) here

// init an I/O pint for output here
}

int main()
{
init_io();
while (1)
{
// set i/O pin high
// wait 1/2 second
// set i/o low
// wait 1/2 second
}
}


You can then look at the I/O pin with a scope, or connect it to a multimeter, or light an LED.