Porting μC/OS-II to a PIC Microcontrolle
Active In SP
Joined: Feb 2011
18-02-2011, 12:21 PM
report.pdf (Size: 162.93 KB / Downloads: 93)
Porting μC/OS-II to a PIC Microcontroller
1. Project Idea
Microchip’s 8-bit low-cost PIC microcontrollers feature a powerful architecture, flexiblememory technologies, and comprehensive easy-to-use development tools . The authorhas used PIC microcontrollers many times and is still fascinated by the simplicity of theirarchitecture and instruction set.Porting μC/OS-II to a PIC microcontroller is the first goal of this project and implimentation. The μC/OS-IIwebsite  indicates that there is a possibility to port μC/OS-II to the PIC18Fmicrocontroller family.For convenience reasons, a software simulator (Virtual Breadboard) for emulating somepopular PIC microcontrollers without using any hardware will be used. Also, there is a freestudent version of the C-compiler that is tailored for the PIC18F family.After porting μC/OS-II, the ultimate goal of this project and implimentation is to create, run, and manageseveral independent tasks with different priorities in μC/OS-II on a PIC. The tasks will besimple counters and their progress will be observed on a display.
There are two possible approaches for completing this project and implimentation:
•Set up the hardware exclusively with virtual components in Virtual Breadboard.
•Set up the hardware on a real breadboard with real components.If possible the first approach will be used. If there are any problems with the first approach,the second approach is an equally good but more time-consuming backup solution.
1.2 Hardware Requirements
Following the first approach, no actual hardware is needed. The PIC microcontroller and allperipheral components can be simulated using Virtual Breadboard.However, for the PIC18F family and especially Virtual Breadboard, the code for μC/OS-II isquite sophisticated. Therefore, there is the possibility that the simulator will not be able toprocess μC/OS-II correctly. If this should happen, the hardware will be built on a realbreadboard using real components according to the second approach. The details will bediscussed in a later chapter.
1.3 Software Requirements
The following software packages will be used:
•Embedded OS: μC/OS-II
•C-compiler: MPLAB C18 v3.02 Student Edition 
•Assembler: MPLAB IDE v7.40 
•PIC simulator: Virtual Breadboard 
2. Approach 1: Running μC/OS-II in Virtual Breadboard
Following the first approach, the goal is to get the basic μC/OS-II port running in VirtualBreadboard. The steps for reaching this goal are described in the following chapters.
2.1 Choosing the Target System
The first decision that had to be made was the selection of the actual microcontroller withinthe PIC18F family. The PIC18F452  is one of the most widely used microcontrollers inthis particular family and support for most of the problems that might occur can be found onthe Internet. It is also implemented in the Virtual Breadboard simulator. Therefore, μC/OS-IIwill be ported to the PIC18F452 microcontroller.
2.2 Getting the μC/OS-II Code
The standard μC/OS-II code was obtained from the CD that comes with the book by JeanJ. Labrosse . There is a link on  pointing to . This website contains a personalproject and implimentation executed by Nathan Brown, in which he wrote a PIC18F family port code forμC/OS-II. However, his code is from 2002 and is not quite compatible with the new versionof the MPLAB C18 compiler (v3.02). Nevertheless, his code is available free of charge and will be used as a basis for further development steps.
2.3 Compiling μC/OS-II with MPLAB for the PIC18F452
Table 2-1 shows an overview of all the files needed for compiling. The links among the files is shown in Figure 2-1. After understanding the purpose of each file and the different links among them, a project and implimentation structure in MPLAB has been created (see Figure 2-2). Most of the C- and H-files are part of the μC/OS-II kernel and some of them have not been changed at all.The test.c file contains a simple test function to verify the correct execution of μC/OS-II. It activates a 4-bit counter that counts from 0 to 9 in an endless loop. The counter outputs are directed to PORTD of the PIC and the counting can be observed on a 7-segment display.The details of the other files can be seen in Table 2-1.Some compiler settings tips are posted on Nathan Brown’s website . Additionally, heclaims that the libraries that come with MPLAB C18 have to be recompiled with the multibank stack model enabled. As far as the author knows, the libraries of the current MPLAB C18 version already have this feature enabled. Therefore, nothing has to be done in this matter.
2.3.1 Compiling Problems
Compiling the combination of original and ported code files generated a number of errorswhich had to be resolved first.•Some labels for floating point operations were out of date•The path for included code files was incorrect•Include, library, and linker paths were incorrectAfter resolving the problems, the project and implimentation has successfully been compiled.
2.4 Virtual Breadboard Simulator
Virtual Breadboard  can be used to simulate hardware setups without using any actualhardware. At this point, it is used to visualize the correct function of μC/OS-II.After the hex-code generated by the MPLAB C18 compiler is loaded into the virtualPIC18F452, the simulation can be started.Figure 2-3 shows the setup for testing the first running task (the counter described inchapter 2.3) in μC/OS-II. PORTD of the PIC18F452 feeds a 7-segment driver (the chiplabeled 4511), which is connected to the 7-segment display.
2.4.1 Virtual Breadboard Problems
Unfortunately, the new version 1.6 of Virtual Breadboard, which supports microcontrollersfrom the PIC18F family for the first time, has still some bugs:
•Start-up problems with the compiled code
•Wait function (for loop) is not working
•Microcontroller flags may be faulty
The first problem has been resolved by the Virtual Breadboard developer, the second andthe third could not be resolved so far. Another more serious problem is that the μC/OS-IIfunction OSStart(), which starts the counting task in the multitask environment, is notworking. This might have something to do with the other Virtual Breadboard bugs, but itmay also be another problem. If the counting task is called in a foreground/backgroundenvironment, it works fine.At this point, the author decided to use a real breadboard to set up the hardware instead ofVirtual Breadboard.