C Code Simulation

From Flowcode Help
Revision as of 10:45, 30 May 2018 by DanielM (talk | contribs)
Jump to navigationJump to search

Unlike previous versions, Flowcode 8 can simulate C code inside C Code icons. Note, in order to use this feature you will need to have purchased the C Simulation feature pack.

This feature can be great for debugging custom C code within your project, prior to compilation to a microcontroller. It is also invaluable as a teaching tool, and allows you to teach students the effects of certain C language statements on variables. When simulating C code, you can step through individual statements within a block in the same way that you step through multiple icons in your Flowchart.

How to simulate C code

CSimButton.jpg

By default no C code will be simulated until the C Simulation button is enabled. C Code icons will simply be skipped by the simulator. The C Simulation button can be found on the main toolbar and via the DEBUG menu. C Simulation is enabled when the button icon is highlighted by a bounding square.


The Conversion Messages window

When simulating C code, a helpful Conversion Messages window will appear.

Errors

The Conversion Messages window will detail any problems that Flowcode has encountered when trying to parse your C code. Certain C language features such as pointers, and advanced modifiers such as const and typedef are not supported. If Flowcode encounters a statement within your C code that it cannot simulate, this information will be displayed in the Conversion Window, and Flowcode will simply skip that statement. Flowcode will still attempt to simulate the rest of the code within the C code icon.

Temporary variable renaming

The Conversion Messages window will also detail any information that is useful for debugging the values of variables. Flowcode may temporarily rename variables within your C code when simulating. This due to the fact that multiple variables in C may use the same name, as long as they exist at different scopes (e.g. a name can be used to define a variable at the top of a function, as well as a variable inside the curly braces of a while-loop). This renaming ability allows you to use the Simulation Debugger to track the values of different variables, even if they share a name in the C code. No variable renaming performed by Flowcode will alter the behavior of your C code. If a variable is renamed by Flowcode during simulation, then this information, including the name to use in the Simulation Debugger, will appear in the Conversion Messages window.


Example

Here is an example program that counts up and down in binary using Port A and a Combo Board component to show the LED signals.

FC6 Icon.png C Simulation Example

CSim.jpg


The C Simulation feature is similar to the C Code to Flowchart Conversion feature that converts C code into Flowchart icons.