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
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
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
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?