Creating New Library
mikroC PRO for PIC allows you to create your own libraries. In order to create a library in mikroC PRO for PIC follow the steps bellow:
- Create a new source file, see Managing Source Files
- Save the file in one of the subfolders of the compiler's Uses folder:
DriveName:\Program Files\Mikroelektronika\mikroC PRO for PIC\Uses\P16\
DriveName:\Program Files\Mikroelektronika\mikroC PRO for PIC\Uses\P18\
If you are creating library for PIC16 MCU family the file should be saved in P16 folder.
If you are creating library for PIC18 MCU family the file should be saved in P18 folder.
If you are creating library for PIC16 and PIC18 MCU families the file should be saved in both folders.
- Write a code for your library and save it.
__Lib_Examplefile in some project, see Project Manager. Recompile the project.
If you wish to use this library for all MCUs, then you should go to Tools › Options › Output settings, and check Build all files as library box.
This will build libraries in a common form which will work with all MCUs. If this box is not checked, then library will be built for selected MCU.
Bear in mind that compiler will report an error if a library built for specific MCU is used for another one.
- Compiled file
__Lib_Example.mclshould appear in
...\mikroC PRO for PIC\Uses\folder.
- Open the definition file for the MCU that you want to use. This file is placed in the compiler's Defs folder:
DriveName:\Program Files\Mikroelektronika\mikroC PRO for PIC\Defs\
and it is named
MCU_NAME.mlk, for example
- Add the the following segment of code to
<LIBRARIES>node of the definition file (definition file is in XML format):
- Add Library to mlk file for each MCU that you want to use with your library.
- Click Refresh button in Library Manager
Example_Libraryshould appear in the Library manager window.
Multiple Library Versions
Library Alias represents unique name that is linked to corresponding Library
For example UART library for 16F887 is different from UART library for 18F4520 MCU.
Therefore, two different UART Library versions were made, see
mlk files for these two MCUs.
Note that these two libraries have the same Library Alias (UART) in both
This approach enables you to have identical representation of UART library for both MCUs
in Library Manager.
What do you think about this topic ? Send us feedback!