User manual

194
mikoPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
Units
In mikroPascal PRO for dsPIC30/33 and PIC24, each project consists of a single project le and one or more unit
les. Project le, with extension .mppds contains information about the project, while unit les, with extension .mpas,
contain the actual source code.
Units allow you to:
- break large programs into encapsulated parts that can be edited separately,
- create libraries that can be used in different projects,
- distribute libraries to other developers without disclosing the source code.
Each unit is stored in its own le and compiled separately. Compiled units are linked to create an application. In order
to build a project, the compiler needs either a source le or a compiled unit le (.mcl le) for each unit.
Uses Clause
mikroPascal PRO for dsPIC30/33 and PIC24 includes units by means of the uses clause. It consists of the reserved
word uses, followed by one or more comma-delimited unit names, followed by a semicolon. Extension of the le should
not be included. There can be at most one uses clause in each source le, and it must appear immediately after the
program (or unit) name.
Here’s an example:
uses utils, strings, Unit2, MyUnit;
For the given unit name, the compiler will check for the presence of .mcl and .mpas les, in order specied by the
search paths.
- If both .mpas and .mcl les are found, the compiler will check their dates and include the newer one in the
project. If the .mpas le is newer than .mcl, a new library will be written over the old one;
- If only .mpas le is found, the compiler will create the .mcl le and include it in the project;
- If only .mcl le is present, i.e. no source code is available, the compiler will include it as it is found;
- If none found, the compiler will issue a “File not found” warning.
Main Unit
Every project in mikroPascal PRO for dsPIC30/33 and PIC24 requires a single main unit le. The main unit le is
identied by the keyword program at the beginning; it instructs the compiler where to “start”.
After you have successfully created an empty project with the Project Wizard, the Code Editor will display a new main
unit. It contains the bare-bones of the Pascal program:
program MyProject;
{ main procedure }
begin
{ Place program code here }
end.