once, and verifies it three times. Overkill, but I get the
messages I want.
That’s it. Follow these steps and you should have your
PICkit 2 running within MicroCode Studio, with the
PICBASIC PRO compiler, and have a one-click, compile and
program solution . . . or will you? If everything is perfect,
then you will. However, there are always a few gotchas
when trying to do something new like this.
If, for some reason, the PICkit 2 command-line
interface has a problem, then an error message will appear.
However, the window will close so fast that you won’t see
it. I haven’t figured out a way to add a delay to the error
messages since they are displayed automatically. This is
one of the shortcomings to the way the command-line
program is written.
If you see the DOS command-line window open and
then close quickly, assume you have an error. To view it,
you have to open the command line yourself and run the
pk2cmd.exe file from the DOS command line (if you know
how to do that). Only then can you see what the error is.
The next step is figuring out what the error(s) mean(s). Here
are a few tips you’ll need to make sure you are successful
in getting this to work.
Make sure your PICkit 2 has firmware level V2.10.00 or
later, otherwise it won’t work with the command-line
option. This is stated in the README file. You can update
the firmware through the command line interface, but I find
it easier to use the GUI interface that comes with your
Make sure your board with the PIC installed is powered
separately from the PICkit 2 if you want it to run after
programming. Even though the PICkit 2 can power a circuit
after the chip has been programmed, the command-line
option doesn’t support that feature. The PICkit 2 under
command line control will only power the board during the
Once you have successfully programmed and verified
your PIC, and have seen the success messages in the DOS
command line window, you will see the DOS window close
but your program will not run in your circuit. This is because
the PICkit 2 is holding the reset or MCLR pin low, keeping
the PIC in reset mode. You have to disconnect the PICkit 2
from the circuit to release the MCLR line, and then
your program should start to run. You can easily add a
program/run switch to the MCLR pin on your circuit to
make this easier.
I’m sure the command-line interface will get updated
to correct a lot of these quirks, as this is only version 1.00.
I’m also told that the source code may be made public,
so all of you great PC programmers out there may be
able to do a lot to improve this command-line interface.
As it stands, it can easily be placed in a batch file for
automatic programming if you have several prototypes
to build. The options are endless for this great addition
to the PICkit 2.
GETTING STARTED WITH PICs
As you can see, the PICkit 2 just gets better and better.
Now, the ability to use this with a third-party IDE such as
MicroCode Studio opens up a whole new arena for the
PICkit 2. This won’t give you the DEBUG support that the
PICkit 2 offers. That requires you to run the PICkit 2 from
the Microchip MPLAB IDE but, for many beginners, all they
want is an easy path to write a program and one click
compile and program, so this is a great USB option to do
this for a really low cost.
There are other USB PIC MCU programmers that have
a command-line interface, but I still like to use the PICkit 2
programmer because of the low cost and simple six-pin
interface. It’s easier to build that six-pin interface on a circuit
board or even a bread board. I have been searching the
web for a DOS version ever since I first started using
the PICkit 2. Hats off to the team at Microchip who made
this happen. This adds another step to making it easier
for beginners to get started programming Microchip
microcontrollers. As usual, email me your comments and
questions. I look forward to hearing about how well this
worked for you. See you next month. NV
CONTACT THE AUTHOR
■ Chuck Hellebuyck can be reached at firstname.lastname@example.org
January 2008 69