This thesis describes two implementations of automatic code generation for PLCs based on StateCharts diagrams implemented in the MATLAB Stateflow environment. In both cases, the purpose of the code generation is to provide users lacking a profound and reliable knowledge of PLC programming languages with a possibility to develop control systems and accomplish control engineering tasks. Also, the software modules aim to provide experienced programmers with a tool that facilitates the fast validation of a designed control algorithm by modelling the controlled process in Simulink. The software module that accomplishes the simple code generation task generates Instruction List code based on a simple Stateflow chart lacking hierarchical and parallel components. In this case, code generation essentially means using a clear and easy-to-read generic template and plugging in relevant information retrieved from the Stateflow chart with the help of Stateflow API functions. The resulting code cannot directly be executed on the PLC as the associating of physical IOs to inputs and outputs used by the generated program is still left to the user. In contrast, the advanced code generation module generates executable Structured Text code. This software module is capable of handling more complex Stateflow charts containing hierarchical and orthogonal components. Also, the usability of the module is improved by an easy-to-use and intuitive graphical user interface, which guides the user through the code generation process. The resulting text files containing the code can be directly compiled and downloaded to a PLC by a suitable PLC developer software as the association of physical IOs to the inputs and outputs used by the chart is resolved during the process. The thesis also presents the outcome of tests and evaluates the results, as well as the possibilities for future development.