You are on page 1of 2

Creating Library with HI-TECH Compiler Steps: 1. Creating the *.c library source file 2.

Generating Library a) Use the output=lpp option to create library b) Use the libr.exe utility to create library c) Create library from MPLAB IDE 3. Including the Libraries a) Add to Library category in MPLAB IDE b) Add to Build Options in MPLAB IDE c) Add to command line 4. Calling the library Step I : Creating the *.c library source file 1. Create the c file containing the library routine. Save this c file in your project directory. // Library Code File : lib_add.c // Library Routine : int lib_add(int x, int y); int lib_add (int x, int y) { return (int)(x + y); } // Library Code File : lib_multiply.c // Library Routine : int lib_multiply(int x, int y); int lib_multiply (int x, int y) { return (int)(x * y); } Step 2: Generating Library Method 1: Use the output=lpp option to create library picc.exe --chip=16Fxxx lib_add.c lib_multiply.c -olibrary.cof --output=lpp // --chip option is to specify the device you are using in your project // library.lpp is the generated library source file (For PIC18 Device use picc18.exe along with the appropriate PIC18 Device) Method 2: Use the libr.exe utility to create a library "picc.exe" lib_add.c --chip=16Fxxx // Creates a lib_add.p1 file "picc.exe" lib_multiply.c --chip=16Fxxx // Creates a lib_multiply.p1 file (For PIC18 Device use picc18.exe along with the appropriate PIC18 Device)

Run the libr command as: libr.exe" r library.lpp lib_add.p1 lib_multiply.p1 >> libr.exe is the librarian executable >> r is the option to replace a previous library module with a new one / creates new library if library.lpp doesnt exist already >> library.lpp is the generated library file Method 3: Create library from MPLAB IDE a) Create a MPLAB IDE Project b) Add the library source files lib_add.c & lib_multiply.c to the Project c) Under Project >> Build Options >> Global >> Additional Command Line Options >> Add --output=lpp d) Build the Project. A xxx.lpp file is created bearing the same name as the MPLAB IDE Project. Step 3: Including the Libraries 1. Library can now be included into the project in 3 ways: e) Add the Library to the Project Window under the category Library Files f) Add the Library File library.lpp to the Project Build Options >> Global >> Additional Command Line Options >> Add >> library.lpp g) From the command line, library can be added as picc.exe main.c library.lpp --chip=16Fxxx (For PICC Compiler) (For PIC18 Device use picc18.exe along with the appropriate PIC18 Device) Step 4: : Calling the library from main line code // Code to call the routines in the library: extern int lib_add (int a, int b); extern int lib_multiply(int a, int b); void main() { int x=20, y=10; volatile int p, s; p = lib_add (x, y); s= lib_multiply (x,y); }

You might also like