亚洲春色中文字幕久久久-三上亚,一吻二脱三床四吻胸,国产真实伦对白视频全集,在线毛片观看,精品成品入口黄网,国产毛aⅴ片久久久,亚洲AV色香蕉一区二区三区老师,萧皇后A级艳片,色情日本视频更新,99久久亚洲精品日本无码
標題:
matlab生成51單片機的pwm源代碼 附仿真圖等資料
[打印本頁]
作者:
maojingkui
時間:
2018-4-26 21:29
標題:
matlab生成51單片機的pwm源代碼 附仿真圖等資料
用matlab自動生成PWM源代碼,keil4編譯后灌入8051芯片內,在proteus上仿真實現pwm.很好地顯示了自動代碼生成的過程。pwm.mdl是模型文件,pwmsil_ert_rtw在環測試。pwmsil8051_ert_rtw是keil4文件夾。pwm.dsn是proteus仿真電路圖。pwmsil8051_ert_rtw是keil4文件夾。pwm.dsn是proteus電路圖。
0.png
(47.67 KB, 下載次數: 28)
下載附件
2018-4-26 23:53 上傳
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
0.png
(23.58 KB, 下載次數: 35)
下載附件
2018-4-26 23:53 上傳
單片機源程序如下:
/*
* File: pwmSIL.c
*
* Real-Time Workshop code generated for Simulink model pwmSIL.
*
* Model version : 1.11
* Real-Time Workshop file version : 7.6 (R2010b) 03-Aug-2010
* Real-Time Workshop file generated on : Sun May 26 11:24:29 2013
* TLC version : 7.6 (Jul 13 2010)
* C/C++ source code generated on : Sun May 26 11:24:30 2013
*
* Target selection: ert.tlc
* Embedded hardware selection: Intel->8051 Compatible
* Code generation objectives: Unspecified
* Validation result: Not run
*/
#include "pwmSIL.h"
#include "pwmSIL_private.h"
/* Named constants for Stateflow: '<Root>/Chart' */
#define pwmSIL_IN_a (1U)
#define pwmSIL_IN_b (2U)
/* Block signals (auto storage) */
BlockIO_pwmSIL pwmSIL_B;
/* Block states (auto storage) */
D_Work_pwmSIL pwmSIL_DWork;
/* External inputs (root inport signals with auto storage) */
ExternalInputs_pwmSIL pwmSIL_U;
/* External outputs (root outports fed by signals with auto storage) */
ExternalOutputs_pwmSIL pwmSIL_Y;
/* Real-time model */
RT_MODEL_pwmSIL pwmSIL_M_;
RT_MODEL_pwmSIL *pwmSIL_M = &pwmSIL_M_;
/* Model step function */
void pwmSIL_step(void)
{
uint16_T tmp;
uint8_T tmp_0;
uint8_T tmp_1;
/* Stateflow: '<Root>/Chart' incorporates:
* Inport: '<Root>/In1'
* Inport: '<Root>/In2'
* Inport: '<Root>/In3'
* Inport: '<Root>/In4'
* Inport: '<Root>/In5'
* Inport: '<Root>/In6'
* Inport: '<Root>/In7'
* Inport: '<Root>/In8'
*/
/* Gateway: Chart */
/* During: Chart */
if (pwmSIL_DWork.temporalCounter_i1 < MAX_uint32_T) {
pwmSIL_DWork.temporalCounter_i1 = pwmSIL_DWork.temporalCounter_i1 + 1UL;
}
if (pwmSIL_DWork.is_active_c1_pwmSIL == 0) {
/* Entry: Chart */
pwmSIL_DWork.is_active_c1_pwmSIL = 1U;
/* Transition: '<S1>:13' */
/* Entry 'a': '<S1>:1' */
pwmSIL_DWork.is_c1_pwmSIL = pwmSIL_IN_a;
pwmSIL_DWork.temporalCounter_i1 = 0UL;
/* Embedded MATLAB Function 'bin2dec': '<S1>:16' */
/* '<S1>:16:2' */
if (pwmSIL_U.In8 > 1) {
tmp_0 = MAX_uint8_T;
} else {
tmp_0 = (uint8_T)(pwmSIL_U.In8 << 7);
}
if (pwmSIL_U.In7 > 3) {
tmp_1 = MAX_uint8_T;
} else {
tmp_1 = (uint8_T)(pwmSIL_U.In7 << 6);
}
tmp = (uint16_T)tmp_0 + (uint16_T)tmp_1;
if (tmp > 255U) {
tmp = 255U;
}
if (pwmSIL_U.In6 > 7) {
tmp_0 = MAX_uint8_T;
} else {
tmp_0 = (uint8_T)(pwmSIL_U.In6 << 5);
}
tmp += (uint16_T)tmp_0;
if (tmp > 255U) {
tmp = 255U;
}
if (pwmSIL_U.In5 > 15) {
tmp_0 = MAX_uint8_T;
} else {
tmp_0 = (uint8_T)(pwmSIL_U.In5 << 4);
}
tmp += (uint16_T)tmp_0;
if (tmp > 255U) {
tmp = 255U;
}
if (pwmSIL_U.In4 > 31) {
tmp_0 = MAX_uint8_T;
} else {
tmp_0 = (uint8_T)(pwmSIL_U.In4 << 3);
}
tmp += (uint16_T)tmp_0;
if (tmp > 255U) {
tmp = 255U;
}
if (pwmSIL_U.In3 > 63) {
tmp_0 = MAX_uint8_T;
} else {
tmp_0 = (uint8_T)(pwmSIL_U.In3 << 2);
}
tmp += (uint16_T)tmp_0;
if (tmp > 255U) {
tmp = 255U;
}
if (pwmSIL_U.In2 > 127) {
tmp_0 = MAX_uint8_T;
} else {
tmp_0 = (uint8_T)(pwmSIL_U.In2 << 1);
}
tmp += (uint16_T)tmp_0;
if (tmp > 255U) {
tmp = 255U;
}
tmp += (uint16_T)pwmSIL_U.In1;
if (tmp > 255U) {
tmp = 255U;
}
pwmSIL_DWork.v = (uint8_T)tmp;
pwmSIL_B.pwm = 1U;
} else {
switch (pwmSIL_DWork.is_c1_pwmSIL) {
case pwmSIL_IN_a:
/* During 'a': '<S1>:1' */
if (pwmSIL_DWork.temporalCounter_i1 >= (uint32_T)(pwmSIL_DWork.v / 10)) {
/* Transition: '<S1>:14' */
/* Exit 'a': '<S1>:1' */
/* Entry 'b': '<S1>:12' */
pwmSIL_DWork.is_c1_pwmSIL = pwmSIL_IN_b;
pwmSIL_DWork.temporalCounter_i1 = 0UL;
/* Embedded MATLAB Function 'bin2dec': '<S1>:16' */
/* '<S1>:16:2' */
if (pwmSIL_U.In8 > 1) {
tmp_0 = MAX_uint8_T;
} else {
tmp_0 = (uint8_T)(pwmSIL_U.In8 << 7);
}
if (pwmSIL_U.In7 > 3) {
tmp_1 = MAX_uint8_T;
} else {
tmp_1 = (uint8_T)(pwmSIL_U.In7 << 6);
}
tmp = (uint16_T)tmp_0 + (uint16_T)tmp_1;
if (tmp > 255U) {
tmp = 255U;
}
if (pwmSIL_U.In6 > 7) {
tmp_0 = MAX_uint8_T;
} else {
tmp_0 = (uint8_T)(pwmSIL_U.In6 << 5);
}
tmp += (uint16_T)tmp_0;
if (tmp > 255U) {
tmp = 255U;
}
if (pwmSIL_U.In5 > 15) {
tmp_0 = MAX_uint8_T;
} else {
tmp_0 = (uint8_T)(pwmSIL_U.In5 << 4);
}
tmp += (uint16_T)tmp_0;
if (tmp > 255U) {
tmp = 255U;
}
if (pwmSIL_U.In4 > 31) {
tmp_0 = MAX_uint8_T;
} else {
tmp_0 = (uint8_T)(pwmSIL_U.In4 << 3);
}
tmp += (uint16_T)tmp_0;
if (tmp > 255U) {
tmp = 255U;
}
if (pwmSIL_U.In3 > 63) {
tmp_0 = MAX_uint8_T;
} else {
tmp_0 = (uint8_T)(pwmSIL_U.In3 << 2);
}
tmp += (uint16_T)tmp_0;
if (tmp > 255U) {
tmp = 255U;
}
if (pwmSIL_U.In2 > 127) {
tmp_0 = MAX_uint8_T;
} else {
tmp_0 = (uint8_T)(pwmSIL_U.In2 << 1);
}
tmp += (uint16_T)tmp_0;
if (tmp > 255U) {
tmp = 255U;
}
tmp += (uint16_T)pwmSIL_U.In1;
if (tmp > 255U) {
tmp = 255U;
}
pwmSIL_DWork.v = (uint8_T)tmp;
pwmSIL_B.pwm = 0U;
}
break;
case pwmSIL_IN_b:
/* During 'b': '<S1>:12' */
if (pwmSIL_DWork.temporalCounter_i1 >= (uint32_T)((255 - pwmSIL_DWork.v) /
10)) {
/* Transition: '<S1>:15' */
/* Exit 'b': '<S1>:12' */
/* Entry 'a': '<S1>:1' */
pwmSIL_DWork.is_c1_pwmSIL = pwmSIL_IN_a;
pwmSIL_DWork.temporalCounter_i1 = 0UL;
/* Embedded MATLAB Function 'bin2dec': '<S1>:16' */
/* '<S1>:16:2' */
if (pwmSIL_U.In8 > 1) {
tmp_0 = MAX_uint8_T;
} else {
tmp_0 = (uint8_T)(pwmSIL_U.In8 << 7);
}
if (pwmSIL_U.In7 > 3) {
tmp_1 = MAX_uint8_T;
} else {
tmp_1 = (uint8_T)(pwmSIL_U.In7 << 6);
}
tmp = (uint16_T)tmp_0 + (uint16_T)tmp_1;
if (tmp > 255U) {
tmp = 255U;
}
if (pwmSIL_U.In6 > 7) {
tmp_0 = MAX_uint8_T;
} else {
tmp_0 = (uint8_T)(pwmSIL_U.In6 << 5);
}
tmp += (uint16_T)tmp_0;
if (tmp > 255U) {
tmp = 255U;
}
if (pwmSIL_U.In5 > 15) {
tmp_0 = MAX_uint8_T;
} else {
tmp_0 = (uint8_T)(pwmSIL_U.In5 << 4);
}
tmp += (uint16_T)tmp_0;
if (tmp > 255U) {
tmp = 255U;
}
if (pwmSIL_U.In4 > 31) {
tmp_0 = MAX_uint8_T;
} else {
tmp_0 = (uint8_T)(pwmSIL_U.In4 << 3);
}
tmp += (uint16_T)tmp_0;
if (tmp > 255U) {
tmp = 255U;
}
if (pwmSIL_U.In3 > 63) {
tmp_0 = MAX_uint8_T;
} else {
tmp_0 = (uint8_T)(pwmSIL_U.In3 << 2);
}
tmp += (uint16_T)tmp_0;
if (tmp > 255U) {
tmp = 255U;
}
if (pwmSIL_U.In2 > 127) {
tmp_0 = MAX_uint8_T;
} else {
tmp_0 = (uint8_T)(pwmSIL_U.In2 << 1);
}
tmp += (uint16_T)tmp_0;
if (tmp > 255U) {
tmp = 255U;
}
tmp += (uint16_T)pwmSIL_U.In1;
if (tmp > 255U) {
tmp = 255U;
}
pwmSIL_DWork.v = (uint8_T)tmp;
pwmSIL_B.pwm = 1U;
}
break;
default:
/* Transition: '<S1>:13' */
/* Entry 'a': '<S1>:1' */
pwmSIL_DWork.is_c1_pwmSIL = pwmSIL_IN_a;
pwmSIL_DWork.temporalCounter_i1 = 0UL;
/* Embedded MATLAB Function 'bin2dec': '<S1>:16' */
/* '<S1>:16:2' */
if (pwmSIL_U.In8 > 1) {
tmp_0 = MAX_uint8_T;
} else {
tmp_0 = (uint8_T)(pwmSIL_U.In8 << 7);
}
if (pwmSIL_U.In7 > 3) {
tmp_1 = MAX_uint8_T;
} else {
tmp_1 = (uint8_T)(pwmSIL_U.In7 << 6);
}
tmp = (uint16_T)tmp_0 + (uint16_T)tmp_1;
if (tmp > 255U) {
tmp = 255U;
}
if (pwmSIL_U.In6 > 7) {
tmp_0 = MAX_uint8_T;
} else {
tmp_0 = (uint8_T)(pwmSIL_U.In6 << 5);
}
tmp += (uint16_T)tmp_0;
if (tmp > 255U) {
tmp = 255U;
}
if (pwmSIL_U.In5 > 15) {
tmp_0 = MAX_uint8_T;
} else {
tmp_0 = (uint8_T)(pwmSIL_U.In5 << 4);
}
tmp += (uint16_T)tmp_0;
if (tmp > 255U) {
tmp = 255U;
}
if (pwmSIL_U.In4 > 31) {
tmp_0 = MAX_uint8_T;
} else {
tmp_0 = (uint8_T)(pwmSIL_U.In4 << 3);
}
tmp += (uint16_T)tmp_0;
if (tmp > 255U) {
tmp = 255U;
}
if (pwmSIL_U.In3 > 63) {
tmp_0 = MAX_uint8_T;
} else {
tmp_0 = (uint8_T)(pwmSIL_U.In3 << 2);
}
tmp += (uint16_T)tmp_0;
if (tmp > 255U) {
tmp = 255U;
}
if (pwmSIL_U.In2 > 127) {
tmp_0 = MAX_uint8_T;
} else {
tmp_0 = (uint8_T)(pwmSIL_U.In2 << 1);
}
tmp += (uint16_T)tmp_0;
if (tmp > 255U) {
tmp = 255U;
}
tmp += (uint16_T)pwmSIL_U.In1;
if (tmp > 255U) {
tmp = 255U;
}
pwmSIL_DWork.v = (uint8_T)tmp;
……………………
…………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
pwm-simulink.zip
(472.35 KB, 下載次數: 41)
2018-4-26 21:28 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
作者:
qwertylg
時間:
2018-12-4 17:45
我也在做這個例子,但是我在生成hex文件后,在proteus里面仿真的時候,程序死在了startup.a51里面。請問這個你遇到過嗎?
歡迎光臨 (http://www.denmoz.com/bbs/)
Powered by Discuz! X3.1