You sure are good at C, right?
Firstly I tought of writing it in VB, but decided to try it in shell. Before this I have written a batch that programs the microcontroller with specified hex. By using this two batches (or even merging the two together) I have a fully automatic method using a PICKIT3 programmer which I already have.
Plus I get an easy access to change parameters (part and hex name) by editing batch files instead of recompiling an exe application.
The last byte is checksum so it should change as well.
Thank you very much for the warning. I would have missed that...
Here is a batch that erases and programs the microcontroller with specified hex:
@ECHO OFF
REM A command batch for programming a PIC device and increase the serial number in hex file after successful write
REM By: Mat Kar
SET DEVICE = P18Fxxx
ECHO PIC FLASH PROGRAMMER WITH SERIAL NUMBER AUTO INCREMENT
ECHO.
REM PK3CMD.exe, test.hex and this batch file must be in the same folder
REM For erasing the device enable the following block by commenting "GOTO skip_erase" line.
::*************************************************
GOTO skip_erase
ECHO Starting erase...
START /WAIT PK3CMD /P18Fxxx /V5.0 /E
IF %ERRORLEVEL% == 0 (
ECHO Device sucessfully erased!
) ELSE (
ECHO A problem occured during device erase!
ECHO Press any key to exit from erroneous erase.
pause>null
exit
)
:skip_erase
::*************************************************
REM For programming the device enable the following block by commenting "GOTO skip_program" line.
::*************************************************
GOTO skip_program
ECHO Starting programming...
START /WAIT PK3CMD /P18Fxxx /V5.0 /Ftest.hex
IF %ERRORLEVEL% == 0 (
ECHO Device sucessfully programmed!
) ELSE (
ECHO A problem occured during device programming!
ECHO Press any key to exit from erroneous programming.
pause>null
exit
)
:skip_program
::*************************************************
REM For incrementing the serial number after successful write enable the following block by commenting "GOTO skip_increment" line.
::*************************************************
GOTO skip_increment
REM here comes the code for serial number update......
ECHO Serial number successfully updated!
:skip_increment
::*************************************************
ECHO Press any key to exit.
pause>null
Note:
- instead of P18Fxxx put the exact part number
- if you power the device from an external power supply omit "/V5.0" from START /WAIT PK3CMD /P18Fxxx
/V5.0 /Ftest.hex and START /WAIT PK3CMD /P18Fxxx
/V5.0 /E .
If you want to power the device form PICKIT3 verify part voltage and set the voltage accordingly. For 3.3V devices write /V3.3 instead of /V5.0.