首先建立一个简单的模型
进行一下设置
快捷键 ctrl+B ,编译
此时生成的代码:
/*
* File: untitled.c
*
* Code generated for Simulink model 'untitled'.
*
* Model version : 1.0
* Simulink Coder version : 9.3 (R2020a) 18-Nov-2019
* C/C++ source code generated on : Sun Jul 19 21:00:16 2020
*
* Target selection: ert.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
* Code generation objectives: Unspecified
* Validation result: Not run
*/
#include "untitled.h"
#include "untitled_private.h"
/* External inputs (root inport signals with default storage) */
ExtU_untitled_T untitled_U;
/* External outputs (root outports fed by signals with default storage) */
ExtY_untitled_T untitled_Y;
/* Real-time model */
RT_MODEL_untitled_T untitled_M_;
RT_MODEL_untitled_T *const untitled_M = &untitled_M_;
/* Model step function */
void untitled_step(void)
{
/* Outport: '<Root>/Out1' incorporates:
* Inport: '<Root>/In1'
* Inport: '<Root>/In2'
* Sum: '<Root>/Sum'
*/
untitled_Y.Out1 = untitled_U.In2 + untitled_U.In1;
}
/* Model initialize function */
void untitled_initialize(void)
{
/* (no initialization code required) */
}
/* Model terminate function */
void untitled_terminate(void)
{
/* (no terminate code required) */
}
/*
* File trailer for generated code.
*
* [EOF]
*/
有用的:
void untitled_step(void)
{
/* Outport: '<Root>/Out1' incorporates:
* Inport: '<Root>/In1'
* Inport: '<Root>/In2'
* Sum: '<Root>/Sum'
*/
untitled_Y.Out1 = untitled_U.In2 + untitled_U.In1;
}
参数修改
参数配置
- 以下几张图的位置有变,以上一张为准
输入设置为:
通过上方按钮添加向相应参数和信号
输出设置为:
参数k设置为:
注: 参数K要有初始值
参数关联
双击连线:更改为之前的,并右键设置property
k直接填就行
编译完后,最终效果:
/*
* File: gen3.c
*
* Code generated for Simulink model 'gen3'.
*
* Model version : 1.1
* Simulink Coder version : 9.3 (R2020a) 18-Nov-2019
* C/C++ source code generated on : Sun Jul 19 21:47:19 2020
*
* Target selection: ert.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
* Code generation objectives: Unspecified
* Validation result: Not run
*/
#include "gen3.h"
#include "gen3_private.h"
/* Exported block signals */
real_T z; /* '<Root>/Gain' */
/* Real-time model */
RT_MODEL_gen3_T gen3_M_;
RT_MODEL_gen3_T *const gen3_M = &gen3_M_;
/* Model step function */
void gen3_step(void)
{
/* Gain: '<Root>/Gain' incorporates:
* Inport: '<Root>/In1'
* Inport: '<Root>/In2'
* Sum: '<Root>/Sum'
*/
z = (x + y) * k;
}
/* Model initialize function */
void gen3_initialize(void)
{
/* (no initialization code required) */
}
/* Model terminate function */
void gen3_terminate(void)
{
/* (no terminate code required) */
}
/*
* File trailer for generated code.
*
* [EOF]
*/
有用的
void gen3_step(void)
{
/* Gain: '<Root>/Gain' incorporates:
* Inport: '<Root>/In1'
* Inport: '<Root>/In2'
* Sum: '<Root>/Sum'
*/
z = (x + y) * k;
}