Examples of use

Top  Previous  Next

 

The ChipProgUSB software includes a few examples of use the Application Control Interface functions and structures. The examples reside in the subdirectory ACI\Programmer ACI Examples in the directory where the ChipProg program is installed.

 

The examples are written in the C language. They represent the projects that can be compiled by Microsoft Visual Studio® 2008. The project sources can also be compiled by other C/C++ compilers, sometimes with minor adjustments. After building the project you get the Windows consol application executable file.

 

In order to adjust the example project (or a part of it) for use in your application you have to set correct paths to the ACI functions called by the main() function. This includes paths to the ChipProg executable file, to the file that is supposed to be loaded to the programmer's memory buffer or to be saved from the buffer. You also have to specify your target device. See an example of the main() function's fragment below.

 

/*+                main                                    °                    01.07.09 17:37:24*/

......

 

 // Launch the programmer executable

 if (!Attach("C:\\Program Files\\ChipProgUSB\\4_72_00\\UPrognt2.exe", "", FALSE)) return -1;

 

 // Select device to operate on

 if (!SetDevice("Microchip", "PIC18F242")) return -1;

 

 // Load .hex file to buffer 0, layer 0

 if (!LoadHexFile("C:\\Program\\test.hex", 0, 0)) return -1;

 

 ....

 

All examples uses the ACI.DLL file that must be either in the same folder where the example executable file resides or in the folder specified in the variable PATH. In the supplied examples the ACI.DLL file is already copied into the folders where the MS Visual Studio creates executable files.

 

Example Descriptions

 

Each example has a comment header briefly describing the program purposes. Additionally, some comments are inserted in the code texts. All examples begin from executing the ACI_Launch() function that activates the programmer.

 

AutoProgramming.c

 

This is the simplest and most frequently used example of the ChipProg external control. The program launches the programmer, selects the PIC18F242 target device, loads the test.hex file into the programmer buffer, sets default programming options and then executes a preset Auto Programming batch of functions: Erase, Blank Check, Program, Verify.

 

LongProgramming.c

 

This example shows how to monitor a process of the AutoProgramming procedure if it may last quite a long time. The program acts as the example above. The programming launches by the ACI_StartFunction. Then it keeps checking the percentage of the operation completion by means of the ACI_GetStatus function. If the operation fails, the programmer issues an error message; otherwise it allows operation to continue.

 

ProgrammingOptions.c

 

This example shows how to get, print out and change options settable in the Device and Algorithm Parameters Editor window. First, the program checks the device insertion into the programmer's socket by calling the ACI_GetStatus(&Status) function. Then, after detecting correct and reliable insertion of the device into the programmer's socket, the program reads the current set of options by using the ACI_GetProgOption function, and prints them out. Then it changes the Vpp value from the default to 10.5V and disables the device Brown-out Reset feature.  

 

SaveMemory.c

 

This example shows how to save a binary image of the device in a file. First, the program checks the device insertion into the programmer's socket by calling the ACI_GetStatus(&Status) function. Then, after detecting correct and reliable insertion, the program reads data from a specified range of the SST89V564RD device's memory and saves them in the file test.bin.

 

Checksum.c

 

This example shows how to calculate a checksum of the data read out from a device. First, the program checks the device insertion into the programmer's socket by calling the ACI_GetStatus(&Status) function. After detecting correct and reliable insertion, the program figures out the real size of the SST89V564RD device's flash memory by executing the ACI_ExecFunction function. Then it assigns the buffer 'buf' in the host computer's memory in order to accommodate the data read out from the device, moves the data to this buffer and calculates the checksum of the buffer's content.