205 lines
12 KiB
Plaintext
205 lines
12 KiB
Plaintext
C51 COMPILER V9.60.0.0 PWM 03/13/2023 17:49:47 PAGE 1
|
||
|
||
|
||
C51 COMPILER V9.60.0.0, COMPILATION OF MODULE PWM
|
||
OBJECT MODULE PLACED IN .\Objects\PWM.obj
|
||
COMPILER INVOKED BY: d:\Keil_v5\C51\BIN\C51.EXE mycode\PWM.C OPTIMIZE(8,SPEED) BROWSE INCDIR(.\myinc) DEBUG OBJECTEXTEND
|
||
- PRINT(.\Listings\PWM.lst) TABS(2) OBJECT(.\Objects\PWM.obj)
|
||
|
||
line level source
|
||
|
||
1 /*---------------------------------------------------------------------*/
|
||
2 /* --- STC MCU Limited ------------------------------------------------*/
|
||
3 /* --- STC 1T Series MCU Demo Programme -------------------------------*/
|
||
4 /* --- Mobile: (86)13922805190 ----------------------------------------*/
|
||
5 /* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/
|
||
6 /* --- Tel: 86-0513-55012928,55012929,55012966 ------------------------*/
|
||
7 /* --- Web: www.STCMCU.com --------------------------------------------*/
|
||
8 /* --- Web: www.STCMCUDATA.com ---------------------------------------*/
|
||
9 /* --- QQ: 800003751 -------------------------------------------------*/
|
||
10 /* 如果要在程序中使用此代码,请在程序中注明使用了STC的资料及程序 */
|
||
11 /*---------------------------------------------------------------------*/
|
||
12
|
||
13 #include "PWM.h"
|
||
14 PWMx_Duty PWMA_Duty;
|
||
15 u8 PWM_Configuration(u8 PWM, PWMx_InitDefine *PWMx)
|
||
16 {
|
||
17 1 if(PWM == PWMA)
|
||
18 1 {
|
||
19 2 EAXSFR(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展SFR(XSFR) */
|
||
20 2
|
||
21 2 if(PWMx->PWM1_SetPriority <= Priority_3) PWM1_Priority(PWMx->PWM1_SetPriority); //指定中断优先级(低到高)
|
||
- Priority_0,Priority_1,Priority_2,Priority_3
|
||
22 2 if(PWMx->PWM2_SetPriority <= Priority_3) PWM2_Priority(PWMx->PWM2_SetPriority); //指定中断优先级(低到高)
|
||
- Priority_0,Priority_1,Priority_2,Priority_3
|
||
23 2 if(PWMx->PWM3_SetPriority <= Priority_3) PWM3_Priority(PWMx->PWM3_SetPriority); //指定中断优先级(低到高)
|
||
- Priority_0,Priority_1,Priority_2,Priority_3
|
||
24 2 if(PWMx->PWM4_SetPriority <= Priority_3) PWM4_Priority(PWMx->PWM4_SetPriority); //指定中断优先级(低到高)
|
||
- Priority_0,Priority_1,Priority_2,Priority_3
|
||
25 2
|
||
26 2 PWMA_CCER1_Disable(); //关闭所有输入捕获/比较输出
|
||
27 2 PWMA_CCER2_Disable(); //关闭所有输入捕获/比较输出
|
||
28 2 PWMA_OC1ModeSet(PWMx->PWM1_Mode); //设置输出比较模式
|
||
29 2 PWMA_OC2ModeSet(PWMx->PWM2_Mode); //设置输出比较模式
|
||
30 2 PWMA_OC3ModeSet(PWMx->PWM3_Mode); //设置输出比较模式
|
||
31 2 PWMA_OC4ModeSet(PWMx->PWM4_Mode); //设置输出比较模式
|
||
32 2 if(PWMx->PWM_Reload == ENABLE) PWMA_OC1_ReloadEnable(); //输出比较的预装载使能
|
||
33 2 else PWMA_OC1_RelosdDisable(); //禁止输出比较的预装载
|
||
34 2 if(PWMx->PWM_Fast == ENABLE) PWMA_OC1_FastEnable(); //输出比较快速功能使能
|
||
35 2 else PWMA_OC1_FastDisable(); //禁止输出比较快速功能
|
||
36 2
|
||
37 2 if(PWMx->PWM_CC1Enable == ENABLE) PWMA_CC1E_Enable(); //开启输入捕获/比较输出
|
||
38 2 else PWMA_CC1E_Disable(); //关闭输入捕获/比较输出
|
||
39 2 if(PWMx->PWM_CC1NEnable == ENABLE) PWMA_CC1NE_Enable(); //开启输入捕获/比较输出
|
||
40 2 else PWMA_CC1NE_Disable(); //关闭输入捕获/比较输出
|
||
41 2 if(PWMx->PWM_CC2Enable == ENABLE) PWMA_CC2E_Enable(); //开启输入捕获/比较输出
|
||
42 2 else PWMA_CC2E_Disable(); //关闭输入捕获/比较输出
|
||
43 2 if(PWMx->PWM_CC2NEnable == ENABLE) PWMA_CC2NE_Enable(); //开启输入捕获/比较输出
|
||
44 2 else PWMA_CC2NE_Disable(); //关闭输入捕获/比较输出
|
||
45 2 if(PWMx->PWM_CC3Enable == ENABLE) PWMA_CC3E_Enable(); //开启输入捕获/比较输出
|
||
46 2 else PWMA_CC3E_Disable(); //关闭输入捕获/比较输出
|
||
47 2 if(PWMx->PWM_CC3NEnable == ENABLE) PWMA_CC3NE_Enable(); //开启输入捕获/比较输出
|
||
48 2 else PWMA_CC3NE_Disable(); //关闭输入捕获/比较输出
|
||
49 2 if(PWMx->PWM_CC4Enable == ENABLE) PWMA_CC4E_Enable(); //开启输入捕获/比较输出
|
||
50 2 else PWMA_CC4E_Disable(); //关闭输入捕获/比较输出
|
||
C51 COMPILER V9.60.0.0 PWM 03/13/2023 17:49:47 PAGE 2
|
||
|
||
51 2 if(PWMx->PWM_CC4NEnable == ENABLE) PWMA_CC4NE_Enable(); //开启输入捕获/比较输出
|
||
52 2 else PWMA_CC4NE_Disable(); //关闭输入捕获/比较输出
|
||
53 2
|
||
54 2 PWMA_AutoReload(PWMx->PWM_Period);
|
||
55 2 PWMA_Duty1(PWMx->PWM1_Duty);
|
||
56 2 PWMA_Duty2(PWMx->PWM2_Duty);
|
||
57 2 PWMA_Duty3(PWMx->PWM3_Duty);
|
||
58 2 PWMA_Duty4(PWMx->PWM4_Duty);
|
||
59 2
|
||
60 2 PWMA_CCPCAPreloaded(PWMx->PWM_PreLoad); //捕获/比较预装载控制位(该位只对具有互补输出的通道起作用)
|
||
61 2 PWMA_PS = PWMx->PWM_PS_SW; //切换IO
|
||
62 2 PWMA_ENO = PWMx->PWM_EnoSelect; //输出通道选择
|
||
63 2 PWMA_DeadTime(PWMx->PWM_DeadTime); //死区发生器设置
|
||
64 2
|
||
65 2 if(PWMx->PWM_BrakeEnable == ENABLE) PWMA_BrakeEnable(); //开启刹车输入
|
||
66 2 else PWMA_BrakeDisable(); //禁止刹车输入
|
||
67 2 if(PWMx->PWM_MainOutEnable == ENABLE) PWMA_BrakeOutputEnable(); //主输出使能
|
||
68 2 else PWMA_BrakeOutputDisable(); //主输出禁止
|
||
69 2 if(PWMx->PWM_CEN_Enable == ENABLE) PWMA_CEN_Enable(); //使能计数器
|
||
70 2 else PWMA_CEN_Disable(); //禁止计数器
|
||
71 2
|
||
72 2 EAXRAM(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展RAM(XRAM) */
|
||
73 2 return 0;
|
||
74 2 }
|
||
75 1
|
||
76 1 if(PWM == PWMB)
|
||
77 1 {
|
||
78 2 EAXSFR(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展SFR(XSFR) */
|
||
79 2
|
||
80 2 if(PWMx->PWM5_SetPriority <= Priority_3) PWM5_Priority(PWMx->PWM5_SetPriority); //指定中断优先级(低到高)
|
||
- Priority_0,Priority_1,Priority_2,Priority_3
|
||
81 2
|
||
82 2 PWMB_CCER1_Disable(); //关闭所有输入捕获/比较输出
|
||
83 2 PWMB_CCER2_Disable(); //关闭所有输入捕获/比较输出
|
||
84 2 PWMB_OC5ModeSet(PWMx->PWM5_Mode); //设置输出比较模式
|
||
85 2 PWMB_OC6ModeSet(PWMx->PWM6_Mode); //设置输出比较模式
|
||
86 2 PWMB_OC7ModeSet(PWMx->PWM7_Mode); //设置输出比较模式
|
||
87 2 PWMB_OC8ModeSet(PWMx->PWM8_Mode); //设置输出比较模式
|
||
88 2 if(PWMx->PWM_Reload == ENABLE) PWMB_OC5_ReloadEnable(); //输出比较的预装载使能
|
||
89 2 else PWMB_OC5_RelosdDisable(); //禁止输出比较的预装载
|
||
90 2 if(PWMx->PWM_Fast == ENABLE) PWMB_OC5_FastEnable(); //输出比较快速功能使能
|
||
91 2 else PWMB_OC5_FastDisable(); //禁止输出比较快速功能
|
||
92 2
|
||
93 2 if(PWMx->PWM_CC5Enable == ENABLE) PWMB_CC5E_Enable(); //开启输入捕获/比较输出
|
||
94 2 else PWMB_CC5E_Disable(); //关闭输入捕获/比较输出
|
||
95 2 if(PWMx->PWM_CC6Enable == ENABLE) PWMB_CC6E_Enable(); //开启输入捕获/比较输出
|
||
96 2 else PWMB_CC6E_Disable(); //关闭输入捕获/比较输出
|
||
97 2 if(PWMx->PWM_CC7Enable == ENABLE) PWMB_CC7E_Enable(); //开启输入捕获/比较输出
|
||
98 2 else PWMB_CC7E_Disable(); //关闭输入捕获/比较输出
|
||
99 2 if(PWMx->PWM_CC8Enable == ENABLE) PWMB_CC8E_Enable(); //开启输入捕获/比较输出
|
||
100 2 else PWMB_CC8E_Disable(); //关闭输入捕获/比较输出
|
||
101 2
|
||
102 2 PWMB_AutoReload(PWMx->PWM_Period);
|
||
103 2 PWMB_Duty5(PWMx->PWM5_Duty);
|
||
104 2 PWMB_Duty6(PWMx->PWM6_Duty);
|
||
105 2 PWMB_Duty7(PWMx->PWM7_Duty);
|
||
106 2 PWMB_Duty8(PWMx->PWM8_Duty);
|
||
107 2
|
||
108 2 PWMB_CCPCBPreloaded(PWMx->PWM_PreLoad); //捕获/比较预装载控制位(该位只对具有互补输出的通道起作用)
|
||
109 2 PWMB_PS = PWMx->PWM_PS_SW; //切换IO
|
||
110 2 PWMB_ENO = PWMx->PWM_EnoSelect; //输出通道选择
|
||
111 2 PWMB_DeadTime(PWMx->PWM_DeadTime); //死区发生器设置
|
||
C51 COMPILER V9.60.0.0 PWM 03/13/2023 17:49:47 PAGE 3
|
||
|
||
112 2
|
||
113 2 if(PWMx->PWM_BrakeEnable == ENABLE) PWMB_BrakeEnable(); //开启刹车输入
|
||
114 2 else PWMB_BrakeDisable(); //禁止刹车输入
|
||
115 2 if(PWMx->PWM_MainOutEnable == ENABLE) PWMB_BrakeOutputEnable(); //主输出使能
|
||
116 2 else PWMB_BrakeOutputDisable(); //主输出禁止
|
||
117 2 if(PWMx->PWM_CEN_Enable == ENABLE) PWMB_CEN_Enable(); //使能计数器
|
||
118 2 else PWMB_CEN_Disable(); //禁止计数器
|
||
119 2
|
||
120 2 EAXRAM(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展RAM(XRAM) */
|
||
121 2 return 0;
|
||
122 2 }
|
||
123 1
|
||
124 1 return 2; //错误
|
||
125 1 }
|
||
126
|
||
127 /*********************************************************/
|
||
128
|
||
129 /******************* PWM 占空比设置函数 *******************/
|
||
130 void UpdatePwm(u8 PWM, PWMx_Duty *PWMx)
|
||
131 {
|
||
132 1 EAXSFR(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展SFR(XSFR) */
|
||
133 1
|
||
134 1 if(PWM == PWMA)
|
||
135 1 {
|
||
136 2 PWMA_Duty1(PWMx->PWM1_Duty);
|
||
137 2 PWMA_Duty2(PWMx->PWM2_Duty);
|
||
138 2 PWMA_Duty3(PWMx->PWM3_Duty);
|
||
139 2 PWMA_Duty4(PWMx->PWM4_Duty);
|
||
140 2 }
|
||
141 1 else
|
||
142 1 {
|
||
143 2 PWMB_Duty5(PWMx->PWM5_Duty);
|
||
144 2 PWMB_Duty6(PWMx->PWM6_Duty);
|
||
145 2 PWMB_Duty7(PWMx->PWM7_Duty);
|
||
146 2 PWMB_Duty8(PWMx->PWM8_Duty);
|
||
147 2 }
|
||
148 1
|
||
149 1 EAXRAM(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展RAM(XRAM) */
|
||
150 1 }
|
||
151
|
||
152 /*********************************************************/
|
||
153 void PWM_config(void)
|
||
154 {
|
||
155 1 PWMx_InitDefine PWMx_InitStructure;
|
||
156 1 PWMx_InitStructure.PWM2_Mode = CCMRn_PWM_MODE1; //模式, CCMRn_FREEZE,CCMRn_MATCH_VALID,CCMRn_MATCH_IN
|
||
-VALID,CCMRn_ROLLOVER,CCMRn_FORCE_INVALID,CCMRn_FORCE_VALID,CCMRn_PWM_MODE1,CCMRn_PWM_MODE2
|
||
157 1 PWMx_InitStructure.PWM2_SetPriority = Priority_0; //指定中断优先级(低到高) Priority_0,Priority_1,Prior
|
||
-ity_2,Priority_3
|
||
158 1 PWMx_InitStructure.PWM_Period = 2047; //周期时间, 0~65535
|
||
159 1 PWMx_InitStructure.PWM2_Duty = PWMA_Duty.PWM2_Duty; //PWM2占空比时间, 0~Period
|
||
160 1 PWMx_InitStructure.PWM_DeadTime = 0; //死区发生器设置, 0~255
|
||
161 1 PWMx_InitStructure.PWM_EnoSelect = ENO2N ;
|
||
162 1 PWMx_InitStructure.PWM_PS_SW =PWM2_SW_P12_P13;
|
||
163 1 PWMx_InitStructure.PWM_CC2NEnable = ENABLE; //开启PWM2N输入捕获/比较输出, ENABLE,DISABLE
|
||
164 1 PWMx_InitStructure.PWM_MainOutEnable= ENABLE; //主输出使能, ENABLE,DISABLE
|
||
165 1 PWMx_InitStructure.PWM_CEN_Enable = ENABLE; //使能计数器, ENABLE,DISABLE
|
||
166 1 PWM_Configuration(PWMA, &PWMx_InitStructure); //初始化PWM, PWMA,PWMB
|
||
167 1 }
|
||
|
||
|
||
MODULE INFORMATION: STATIC OVERLAYABLE
|
||
CODE SIZE = 1440 ----
|
||
C51 COMPILER V9.60.0.0 PWM 03/13/2023 17:49:47 PAGE 4
|
||
|
||
CONSTANT SIZE = ---- ----
|
||
XDATA SIZE = ---- ----
|
||
PDATA SIZE = ---- ----
|
||
DATA SIZE = 16 52
|
||
IDATA SIZE = ---- ----
|
||
BIT SIZE = ---- ----
|
||
END OF MODULE INFORMATION.
|
||
|
||
|
||
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
|