Visual PIC

PIC (18F4550) Plugin for StarUML

Microcontroller:
   Microchip PIC18F4550

Requirements:
   Star UML (available here)
   Microchip C18 Compiler (available here)
   .NET Framework 2.0 (not tested with >=3.0)

License:
   Creative Commons License
  The source code of this work is licensed under a
  Creative Commons License.

»  Introduction
This project is a plugin for the popular Open Source UML/MDA Platform StarUML . The plugin extends StarUML with some new UML elements for modelling, compiling and downloading an application (via USB) to the microcontroller PIC 18F4550. This project does not comprise full modelling capabilities for all peripherials of the PIC but shall serve as inspiration and/or basis for your own extensions. The following picture shows a screenshot of StarUML with a small application model that creates a changing PWM signal.


(click to enlarge)

Dashed lines show the object flow (the usage of objects by the activities as input or output) while solid lines are used for modelling the program flow, e.g. the transition between different activities.
»  Installation
After having downloaded the ZIP-File containing all required files (including the source files and some demo projects) here you need to unzip the files into the "modules" folder of your StarUML installation. The resulting structure should look like this: C:\Programme\StarUML\modules\visualPic\....
Now you need to make the plugin accessible to StarUML as a COM object. Therefore you need to execute the batch file "register.bat". Note: The Assembly Registration Tool "regasm.exe" must be in your search path for the batch file to work properly. It comes with the .NET framework and should be lokated in "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727", for example.
Now the VisualPIC AddIn is ready for action.
»  Tutorial
The following UML elements are available:

ElementUML base elementPurpose
Flow start
ActivityStart of the program flow
Assignment
ActivityAssigns the value of one incoming object to one or more outcoming objects
Addition
ActivityAdds up all incoming objects and assigns the result to the outgoing object
IsZero
ActivityChecks if the value of an incoming object is zero and triggers different successor activities depending on the result
GreaterZero
ActivityChecks if the value of an incoming object is larger than zero and triggers different successor activities depending on the result
Delay
ActivityDelays the following activity by the specified amount of milliseconds (currently the timing is only correct when the PIC uses a 48MHz oscillator)
Variable
ObjectFlowStateCan be used to store or read a variable value
Constant
ObjectFlowStateRead as a constant value
BitOut
ObjectFlowStateSets the state of a digital output pin
BitIn
ObjectFlowStateGets the state of a digital input pin
PWMOut
ObjectFlowStateCreates a PWM signal at pin RC2

Objects like Delay or BitIn/Out offer tagged values for modeling specific properties.


»  Some examples

1. Assignment (constant to variable):


Generates the following code:
int to_a_variable;
...

Flowstart:
  //Start of the program flow
and_assigned_to:
  //Assigning 'Constant is read' to 'to a variable'
  to_a_variable = 0;


2. Assignment (BitIn to BitOut):
Port pins are configured using tagged values (via context menu)


Generates the following code:
//BitIn initialization...
TRISBbits.TRISB4 = 1;
//BitOut initialization...
TRISDbits.TRISD0 = 0;
PORTDbits.RD0 = 0;

...

Flowstart:
  //Start of the program flow
and_assigned_to:
  //Assigning 'PortRB4' to 'PortD0'
  PORTDbits.RD0 = PORTBbits.RB4;


3. Branch (IsZero):
Branches are configured using the transitions' guard conditions


Generates the following code:
Flowstart:
  //Start of the program flow
IsZero:
  if (PORTBbits.RB4 == 0)
  {
    goto Delay1;
  }
  else
  {
    goto ElseActivity;
  }
Delay1:
  Delay1KTCYx(0);
ElseActivity:
...


3. Branch (IsZero):
Branches are configured using the transitions' guard conditions


Generates the following code:
Flowstart:
  //Start of the program flow
IsZero:
  if (PORTBbits.RB4 == 0)
  {
    goto Delay1;
  }
  else
  {
    goto ElseActivity;
  }
Delay1:
  Delay1KTCYx(0);
ElseActivity:
...



»  The following table shows a complete overview of the allowed number of successor/predecessor objects and activities for each available activity type:

ActivityObjectsActivities
inoutinout
Flowstart0001
Assignment10..*0..*0..1
Addition2..*10..*0..1
IsZero100..*0..2
GreaterZero100..*0..2
Delay000..*0..1



»  After a UML model of the desired functionality has been created it is required to configure the plugin parameters, so that the code generator and compiler can do their job. This is done in the configuration dialog available via menu "Tools/Options...".



The following parameters have to /can be configured:
CategoryParameterPurpose
CompilerC18 Compiler pathPath to the C18 compiler executable, e.g. C:\MCC18\bin
CompilerInclude file pathPath to the include files delivered with C18, e.g. C:\MCC18\h
LinkerC18 Linker pathPath to the C18 linker executable, e.g. C:\MCC18\bin
LinkerC18 Library PathPath to the library files delivered with C18, e.g. C:\MCC18\lib
BootloaderStart bootloader after build has finishedIf checked, the bootloader starts after successful code generation and compilation.
BootloaderDownload application automaticallyIf checked, the download is done by the bootloader automatically as soon as a PIC running in bootload mode is detected at a USB port.



»  Finally the code generator is started using the menu "Tool/PIC/Generate code..." or the context menu of the diagram: