Use PICKit3 with MikroC

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
AllenM
Posts: 75
Joined: 20 Mar 2013 17:30
Location: Rome, NY, USA

Use PICKit3 with MikroC

#1 Post by AllenM » 13 Jul 2013 19:12

I love my EasyPICv7 for development but it just can't do ICSP. I use a PICKit3 for that. Here is one way to do it from MikroC.

There are a couple of caveats. First MikroC separates the program hex file from the EEPROM (ihex) hex file. I think this is usually a good idea. Secondly in the tools/parameters MikroC prepends "PIC" (or dsPIC, etc.) to the device (part) name. This needs to be stripped off - easy to do in a batch file. Thirdly the PICKit3 has separate parameters, /MP and /ME to program either the program or the EEPROM; however, using either of these will erase the other even if the /E (erase) parameter is not used. Fortunately there is a REPROGRAM command which allows us to work around this.

In the MikroC Tools/Options menu make two tools to run the batch files which follow. Use this parameter line:

%CHIP_NAME "%HEX_FILE_NAME"

Note the quotes around HEX_FILE_NAME. These are necessary if there are spaces in the file name or path. MikroC does not have an ihex file name parameter so we will use the same parameters for both operations but edit the name for programming the EEPROM.

Program Batch File:

Code: Select all

C:
cd "\Program Files (x86)\Microchip\MPLAB IDE\Programmer Utilities\PICkit3"
set dev=%1
rem strip off the first three characters
set dev=%dev:~3%
PK3CMD.exe /I /MP /V5 /Y /P%dev% /F%2
pause
EEPROM Batch File:

Code: Select all

C:
cd "\Program Files (x86)\Microchip\MPLAB IDE\Programmer Utilities\PICkit3"
set dev=%1
rem strip off the first three characters
set dev=%dev:~3%
set hexf=%2
rem change .hex to .ihex
set hexf=%hexf:.hex=.ihex%
rem PK3CMD.exe /F%hexf% /ME /P%dev% /V5.000
PK3CMD.exe /V5.000 /P%dev% /GF"TempFile.hex" /R%hexf%
pause
I REMed out the line with the /ME parameter. The documentation seems to indicate that, without the /E parameter, it should work. For my device it does not but you might want to experiment with it. You should also run the PC3CMD executable with the /? parameter to see if there are any additional parameters you want to use. You might want to edit or delete the /V5.000 parameter which powers the chip with 5v from the PICKit3.

The pause is necessary for you to see the status or any errors.

Obviously you will have to edit the path to your PICKit3 executable if you do not have a 64 bit Windows 7 workstation or the program is otherwise installed in a different location. The EEPROM file uses the REPROGRAM command but the Program file does not so the order you use them is important. The Program batch file will erase the entire chip so it must be used first. The EEPROM file must have permission to create the file "TempFile.hex" in the PICKit3 folder. You may want to add a path and put this file in a temp folder somewhere. You could also delete it at the end of the batch file.

I also made a third tool to erase the chip.

Code: Select all

C:
cd "\Program Files (x86)\Microchip\MPLAB IDE\Programmer Utilities\PICkit3"
set dev=%1
rem strip off the first three characters
set dev=%dev:~3%
PK3CMD.exe /E /V5.000 /P%dev%
pause
This file needs only the %CHIP_NAME parameter.

I hope this is helpful.
Allen

There is one thing I could not figure out. (I didn't spend much time on it either.) My tools display as blank buttons. I need to hover over them to get their names. Can I assign icons to them?

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Use PICKit3 with MikroC

#2 Post by filip » 15 Jul 2013 09:43

Hi,

Thank you for this extensive tutorial, this is something the users will benefit from. :)
There is one thing I could not figure out. (I didn't spend much time on it either.) My tools display as blank buttons. I need to hover over them to get their names. Can I assign icons to them?
The icon is automatically added from the executable file that is added as an external tool.
If the batch file is in question, the icon will be the one given by the Windows OS.

Regards,
Filip.

AllenM
Posts: 75
Joined: 20 Mar 2013 17:30
Location: Rome, NY, USA

Re: Use PICKit3 with MikroC

#3 Post by AllenM » 16 Jul 2013 19:57

Thanks. I suspected that was the problem. Batch files don't have icons. I could probably make a shortcut to the batch file and assign an icon to that.

Post Reply

Return to “mikroC PRO for PIC General”