PICOS18 > Tutorial > Env

PICOS18 : development tools

In this first chapter you will create a entier project based on PICos18. To do so you will use the MPLAB® develpment environnement from Microchip and the C18 compiler.


> Project sources

Before executing MPLAB®, download here the sources of PICos18, including kernel sources and the tutorial's application. Here is the meaning of each file :



Include
This directory contains all the PICos18 kernel headers. The headers dedicated to the application and drivers are located in the appropriate directories (under Project). One header exists for each sub-system of the kernel : alarms, events, interruption and process. The file device.h contains the generic definition of the kernel like the values returned by the PICos18 services (the API).
Kernel
You will found here all the kernel sources. The C files are dedicated to a group of kernel services (the API), and the kernel.asm file, the only one coded in assembling language, stores all the basic features of the kernel : scheduler algorithms, task priority and order and error management.
The sources are provided for your information or if you wish to modify them for a specific need. TO let you use PICos18 more easily we have added the PICos18 library : picos18.lib.
Moreover the startup codes (runtime) provided by Microchip are not well adapted to PICos18, then we have choosen to modify them. The new startup codes are provided with PICos18 like .o files (PICos18iz.o for example).
You don't have to tak care of the picos18.lib library and the startup code because they are automaticaly included in your PICos18 project !
Linker
When you build your application with PICos18 you write your application in a C language. Then you have to compile your application with C18 (to build each .o file corresponding to one .c file) and to link them thanks to MPLINK. The way you are linking the .o files can be set with linker scripts, the .lkr files included in this directory. For each major microcontroler of the PIC18 family a LKR script is present under this directory to avoid to let you manage by yourself this complex part of the build process. For each new PIC18 manage by PICos18 a new script will be added to this directory in the futur.
Project/MyApp
This directory contains all the files dedicated to a basic project with PICos18. As you cna notice there are very few files : the main.c file which is the first file of your application executed by PICos18, the int.c file that contains all the interrupt and fast interrupt routines, the taskdesc.c file which describes precisely all the features of your application (alarms, counters, task features, ...), and a C file for each task of the application.
Project/Tutorial
The tutorial is based on a typical PICos18 application. Through the different chapters you will discover how to program with PICos18 and to build your own application. The files presents under this directory are those of the final application when the tutorial is finished. This brings something more practical to this tutorial with a base composed by source code.

Unzip the PICos18_v2_xx.zip file directly under C:\. All the tutorial chapters assume the PICos18 directory is located under C:\. If not modify by yourself what is necessary.

At this moment the tutorial is validated under MPLAB® / Windows™ development environment (MPLAB® v7.xx with C18 compiler from Microchip release 3.xx. You can download the free versions of these tools from the Microchip web site. The free version of C18 is the same as the full version but without the optimization management. In fact you have to disable such options with PICos18, some are not well adapted for a multi-task application. Then the free version of C18 suits well for PICos18 and PIC18, le assembling code generated is very good compared to other commercial compiler.

The target is a PIC18F452 (don't forget to select it under MPLAB®).

 

> C18 compiler

Start by installing MPLAB® and the Microchip® C compiler for PIC18 family. By default we assume the path would be "C:\mcc18\".

Under MPLAB® click on "Project / Set Language Tool Location..." and set up MPASM, MPLAB C18 and MPLINK location.

 

> Project creation

Then creat a new project under MPLAB®. Click on "Project / New..." et name the project with a length minus than 8 characters. I've choosen "picos.pjt" for the next. Take care to have the filename path without any space character !

Then click on "Project / Select Language Toolsuite..." and select the "Microchip C18 Toolsuite".

 

> Project options

Click on "Project / Build Options..." and set the include and library directories for C18 and for the compiler. Be carrefull : you cannot place a space character between the directory paths.

Then click on the "MPLAB® C18" sheet and check the "Use alternate settings" options and add the "-On" option in the command line.

This force the compiler to disable the bank selection optimization, not efficiant with PICos18.

 

> Adding files

Then right click on the project window to add what follows :

- int.c, main.c, taskdesc.c et tsk_task0.c presents under MyApp
- define.h present under MyApp
- 18f452.lkr present under the Linker directory

The picos18.lib and PICos18iz.o files are automaticaly included by the compiler toolsuite.

 

> Compiling project

Finally compile the project with F10 button.

The compile compiles all the files of the application one by one. It won't build any file of the kernel itself, because the PICos18 library is added to your project.

Then the linker put together all the .o file to build the files necessary to the simulation and the PIC18 programming sequence.

 

> Disable the Watchdog

The MPLAB® simulation is based on the settings of the PIC18 config bits.

Setup your simulation as described on the screenshot.
The watchdog must be disabled
.

 

> Project simulation

Start the simulation by selecting"Debugger / Select Tool / MPLAB® SIM" then F9 (Run). Wait for few secondes and stop with the F5 button (Stop).

The simulation is stopped on the "while(1)" instruction of the task 1. But this instruction does not block the PIC18 by an infinite loop, because the kernel can be called if necessary : try few more times to stop in one part of the kernel.

The kernel source in which you're stopped will be displayed, but the kernel sources have never been added to your project !
Actually you have unzipped the PICos18 sources under C:\ and the library has been build according to this path...