pwm输出呼吸灯

This commit is contained in:
徐青宇 2023-04-11 08:51:37 +08:00
parent 9a13d65e16
commit 180e46521d
31 changed files with 2099 additions and 897 deletions

View File

@ -6,3 +6,13 @@
[info] Log at : 2023/4/10|15:46:58|GMT+0800
[info] Log at : 2023/4/10|17:13:31|GMT+0800
[info] Log at : 2023/4/10|17:24:54|GMT+0800
[info] Log at : 2023/4/10|17:35:57|GMT+0800
[info] Log at : 2023/4/11|08:33:52|GMT+0800
[info] Log at : 2023/4/11|08:44:08|GMT+0800

View File

@ -4,6 +4,8 @@
"timer.h": "c",
"exti.h": "c",
"gpio.h": "c",
"config.h": "c"
"config.h": "c",
"PWM.C": "cpp",
"pwm.h": "c"
}
}

6
.vscode/uv4.log vendored
View File

@ -1,10 +1,8 @@
Build target 'Target 1'
compiling Exti.c...
compiling GPIO.c...
compiling main.c...
compiling timer.c...
compiling PWM.C...
linking...
Program Size: data=18.0 xdata=0 code=2183
Program Size: data=79.0 xdata=0 code=3749
creating hex file from ".\Objects\kill_control"...
".\Objects\kill_control" - 0 Error(s), 0 Warning(s).
Build Time Elapsed: 00:00:00

View File

@ -1 +1 @@
2023/4/10 15:47:04
2023/4/11 8:44:51

View File

@ -1,4 +1,4 @@
C51 COMPILER V9.60.0.0 EXTI 04/10/2023 15:47:03 PAGE 1
C51 COMPILER V9.60.0.0 EXTI 04/10/2023 17:45:08 PAGE 1
C51 COMPILER V9.60.0.0, COMPILATION OF MODULE EXTI
@ -62,7 +62,7 @@ line level source
52 void Ext_INT3(void) interrupt INT3_VECTOR
53 {
54 1 }
C51 COMPILER V9.60.0.0 EXTI 04/10/2023 15:47:03 PAGE 2
C51 COMPILER V9.60.0.0 EXTI 04/10/2023 17:45:08 PAGE 2
55
56 /********************* INT4中断函数 *************************/
@ -126,7 +126,7 @@ line level source
112 2 INT_CLKO &= ~(1 << 4); // 禁止中断
113 2 return 0; // 成功
114 2 }
C51 COMPILER V9.60.0.0 EXTI 04/10/2023 15:47:03 PAGE 3
C51 COMPILER V9.60.0.0 EXTI 04/10/2023 17:45:08 PAGE 3
115 1
116 1 if (EXT == EXT_INT3) // 外中断3, 固定为下降沿低优先级中断

View File

@ -1,4 +1,4 @@
C51 COMPILER V9.60.0.0 GPIO 04/10/2023 15:47:03 PAGE 1
C51 COMPILER V9.60.0.0 GPIO 04/10/2023 17:32:45 PAGE 1
C51 COMPILER V9.60.0.0, COMPILATION OF MODULE GPIO
@ -62,7 +62,7 @@ line level source
52 2 P1M1 |= GPIOx->Pin, P1M0 |= GPIOx->Pin; // 开漏输出
53 2 if (GPIOx->Mode == GPIO_OUT_PP)
54 2 P1M1 &= ~GPIOx->Pin, P1M0 |= GPIOx->Pin; // 推挽输出
C51 COMPILER V9.60.0.0 GPIO 04/10/2023 15:47:03 PAGE 2
C51 COMPILER V9.60.0.0 GPIO 04/10/2023 17:32:45 PAGE 2
55 2 }
56 1 if (GPIO == GPIO_P2)
@ -126,7 +126,7 @@ line level source
114 2 P7M1 &= ~GPIOx->Pin, P7M0 &= ~GPIOx->Pin; // 上拉准双向口
115 2 if (GPIOx->Mode == GPIO_HighZ)
116 2 P7M1 |= GPIOx->Pin, P7M0 &= ~GPIOx->Pin; // 浮空输入
C51 COMPILER V9.60.0.0 GPIO 04/10/2023 15:47:03 PAGE 3
C51 COMPILER V9.60.0.0 GPIO 04/10/2023 17:32:45 PAGE 3
117 2 if (GPIOx->Mode == GPIO_OUT_OD)
118 2 P7M1 |= GPIOx->Pin, P7M0 |= GPIOx->Pin; // 开漏输出

252
Listings/PWM.lst Normal file
View File

@ -0,0 +1,252 @@
C51 COMPILER V9.60.0.0 PWM 04/11/2023 08:44:51 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 PWMB_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)
22 2 PWM1_Priority(PWMx->PWM1_SetPriority); // 指定中断优先级(低到高) Priority_0,Priority_1,Priorit
-y_2,Priority_3
23 2 if (PWMx->PWM2_SetPriority <= Priority_3)
24 2 PWM2_Priority(PWMx->PWM2_SetPriority); // 指定中断优先级(低到高) Priority_0,Priority_1,Priorit
-y_2,Priority_3
25 2 if (PWMx->PWM3_SetPriority <= Priority_3)
26 2 PWM3_Priority(PWMx->PWM3_SetPriority); // 指定中断优先级(低到高) Priority_0,Priority_1,Priorit
-y_2,Priority_3
27 2 if (PWMx->PWM4_SetPriority <= Priority_3)
28 2 PWM4_Priority(PWMx->PWM4_SetPriority); // 指定中断优先级(低到高) Priority_0,Priority_1,Priorit
-y_2,Priority_3
29 2
30 2 PWMA_CCER1_Disable(); // 关闭所有输入捕获/比较输出
31 2 PWMA_CCER2_Disable(); // 关闭所有输入捕获/比较输出
32 2 PWMA_OC1ModeSet(PWMx->PWM1_Mode); // 设置输出比较模式
33 2 PWMA_OC2ModeSet(PWMx->PWM2_Mode); // 设置输出比较模式
34 2 PWMA_OC3ModeSet(PWMx->PWM3_Mode); // 设置输出比较模式
35 2 PWMA_OC4ModeSet(PWMx->PWM4_Mode); // 设置输出比较模式
36 2 if (PWMx->PWM_Reload == ENABLE)
37 2 PWMA_OC1_ReloadEnable(); // 输出比较的预装载使能
38 2 else
39 2 PWMA_OC1_RelosdDisable(); // 禁止输出比较的预装载
40 2 if (PWMx->PWM_Fast == ENABLE)
41 2 PWMA_OC1_FastEnable(); // 输出比较快速功能使能
42 2 else
43 2 PWMA_OC1_FastDisable(); // 禁止输出比较快速功能
44 2
45 2 if (PWMx->PWM_CC1Enable == ENABLE)
46 2 PWMA_CC1E_Enable(); // 开启输入捕获/比较输出
47 2 else
48 2 PWMA_CC1E_Disable(); // 关闭输入捕获/比较输出
49 2 if (PWMx->PWM_CC1NEnable == ENABLE)
50 2 PWMA_CC1NE_Enable(); // 开启输入捕获/比较输出
C51 COMPILER V9.60.0.0 PWM 04/11/2023 08:44:51 PAGE 2
51 2 else
52 2 PWMA_CC1NE_Disable(); // 关闭输入捕获/比较输出
53 2 if (PWMx->PWM_CC2Enable == ENABLE)
54 2 PWMA_CC2E_Enable(); // 开启输入捕获/比较输出
55 2 else
56 2 PWMA_CC2E_Disable(); // 关闭输入捕获/比较输出
57 2 if (PWMx->PWM_CC2NEnable == ENABLE)
58 2 PWMA_CC2NE_Enable(); // 开启输入捕获/比较输出
59 2 else
60 2 PWMA_CC2NE_Disable(); // 关闭输入捕获/比较输出
61 2 if (PWMx->PWM_CC3Enable == ENABLE)
62 2 PWMA_CC3E_Enable(); // 开启输入捕获/比较输出
63 2 else
64 2 PWMA_CC3E_Disable(); // 关闭输入捕获/比较输出
65 2 if (PWMx->PWM_CC3NEnable == ENABLE)
66 2 PWMA_CC3NE_Enable(); // 开启输入捕获/比较输出
67 2 else
68 2 PWMA_CC3NE_Disable(); // 关闭输入捕获/比较输出
69 2 if (PWMx->PWM_CC4Enable == ENABLE)
70 2 PWMA_CC4E_Enable(); // 开启输入捕获/比较输出
71 2 else
72 2 PWMA_CC4E_Disable(); // 关闭输入捕获/比较输出
73 2 if (PWMx->PWM_CC4NEnable == ENABLE)
74 2 PWMA_CC4NE_Enable(); // 开启输入捕获/比较输出
75 2 else
76 2 PWMA_CC4NE_Disable(); // 关闭输入捕获/比较输出
77 2
78 2 PWMA_AutoReload(PWMx->PWM_Period);
79 2 PWMA_Duty1(PWMx->PWM1_Duty);
80 2 PWMA_Duty2(PWMx->PWM2_Duty);
81 2 PWMA_Duty3(PWMx->PWM3_Duty);
82 2 PWMA_Duty4(PWMx->PWM4_Duty);
83 2
84 2 PWMA_CCPCAPreloaded(PWMx->PWM_PreLoad); // 捕获/比较预装载控制位(该位只对具有互补输出的通道起作用)
85 2 PWMA_PS = PWMx->PWM_PS_SW; // 切换IO
86 2 PWMA_ENO = PWMx->PWM_EnoSelect; // 输出通道选择
87 2 PWMA_DeadTime(PWMx->PWM_DeadTime); // 死区发生器设置
88 2
89 2 if (PWMx->PWM_BrakeEnable == ENABLE)
90 2 PWMA_BrakeEnable(); // 开启刹车输入
91 2 else
92 2 PWMA_BrakeDisable(); // 禁止刹车输入
93 2 if (PWMx->PWM_MainOutEnable == ENABLE)
94 2 PWMA_BrakeOutputEnable(); // 主输出使能
95 2 else
96 2 PWMA_BrakeOutputDisable(); // 主输出禁止
97 2 if (PWMx->PWM_CEN_Enable == ENABLE)
98 2 PWMA_CEN_Enable(); // 使能计数器
99 2 else
100 2 PWMA_CEN_Disable(); // 禁止计数器
101 2
102 2 EAXRAM(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展RAM(XRAM) */
103 2 return 0;
104 2 }
105 1
106 1 if (PWM == PWMB)
107 1 {
108 2 EAXSFR(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展SFR(XSFR) */
109 2
110 2 if (PWMx->PWM5_SetPriority <= Priority_3)
111 2 PWM5_Priority(PWMx->PWM5_SetPriority); // 指定中断优先级(低到高) Priority_0,Priority_1,Priorit
-y_2,Priority_3
C51 COMPILER V9.60.0.0 PWM 04/11/2023 08:44:51 PAGE 3
112 2
113 2 PWMB_CCER1_Disable(); // 关闭所有输入捕获/比较输出
114 2 PWMB_CCER2_Disable(); // 关闭所有输入捕获/比较输出
115 2 PWMB_OC5ModeSet(PWMx->PWM5_Mode); // 设置输出比较模式
116 2 PWMB_OC6ModeSet(PWMx->PWM6_Mode); // 设置输出比较模式
117 2 PWMB_OC7ModeSet(PWMx->PWM7_Mode); // 设置输出比较模式
118 2 PWMB_OC8ModeSet(PWMx->PWM8_Mode); // 设置输出比较模式
119 2 if (PWMx->PWM_Reload == ENABLE)
120 2 PWMB_OC5_ReloadEnable(); // 输出比较的预装载使能
121 2 else
122 2 PWMB_OC5_RelosdDisable(); // 禁止输出比较的预装载
123 2 if (PWMx->PWM_Fast == ENABLE)
124 2 PWMB_OC5_FastEnable(); // 输出比较快速功能使能
125 2 else
126 2 PWMB_OC5_FastDisable(); // 禁止输出比较快速功能
127 2
128 2 if (PWMx->PWM_CC5Enable == ENABLE)
129 2 PWMB_CC5E_Enable(); // 开启输入捕获/比较输出
130 2 else
131 2 PWMB_CC5E_Disable(); // 关闭输入捕获/比较输出
132 2 if (PWMx->PWM_CC6Enable == ENABLE)
133 2 PWMB_CC6E_Enable(); // 开启输入捕获/比较输出
134 2 else
135 2 PWMB_CC6E_Disable(); // 关闭输入捕获/比较输出
136 2 if (PWMx->PWM_CC7Enable == ENABLE)
137 2 PWMB_CC7E_Enable(); // 开启输入捕获/比较输出
138 2 else
139 2 PWMB_CC7E_Disable(); // 关闭输入捕获/比较输出
140 2 if (PWMx->PWM_CC8Enable == ENABLE)
141 2 PWMB_CC8E_Enable(); // 开启输入捕获/比较输出
142 2 else
143 2 PWMB_CC8E_Disable(); // 关闭输入捕获/比较输出
144 2
145 2 PWMB_AutoReload(PWMx->PWM_Period);
146 2 PWMB_Duty5(PWMx->PWM5_Duty);
147 2 PWMB_Duty6(PWMx->PWM6_Duty);
148 2 PWMB_Duty7(PWMx->PWM7_Duty);
149 2 PWMB_Duty8(PWMx->PWM8_Duty);
150 2
151 2 PWMB_CCPCBPreloaded(PWMx->PWM_PreLoad); // 捕获/比较预装载控制位(该位只对具有互补输出的通道起作用)
152 2 PWMB_PS = PWMx->PWM_PS_SW; // 切换IO
153 2 PWMB_ENO = PWMx->PWM_EnoSelect; // 输出通道选择
154 2 PWMB_DeadTime(PWMx->PWM_DeadTime); // 死区发生器设置
155 2
156 2 if (PWMx->PWM_BrakeEnable == ENABLE)
157 2 PWMB_BrakeEnable(); // 开启刹车输入
158 2 else
159 2 PWMB_BrakeDisable(); // 禁止刹车输入
160 2 if (PWMx->PWM_MainOutEnable == ENABLE)
161 2 PWMB_BrakeOutputEnable(); // 主输出使能
162 2 else
163 2 PWMB_BrakeOutputDisable(); // 主输出禁止
164 2 if (PWMx->PWM_CEN_Enable == ENABLE)
165 2 PWMB_CEN_Enable(); // 使能计数器
166 2 else
167 2 PWMB_CEN_Disable(); // 禁止计数器
168 2
169 2 EAXRAM(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展RAM(XRAM) */
170 2 return 0;
171 2 }
172 1
173 1 return 2; // 错误
C51 COMPILER V9.60.0.0 PWM 04/11/2023 08:44:51 PAGE 4
174 1 }
175
176 /*********************************************************/
177
178 /******************* PWM 占空比设置函数 *******************/
179 void UpdatePwm(u8 PWM, PWMx_Duty *PWMx)
180 {
181 1 EAXSFR(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展SFR(XSFR) */
182 1
183 1 if (PWM == PWMA)
184 1 {
185 2 PWMA_Duty1(PWMx->PWM1_Duty);
186 2 PWMA_Duty2(PWMx->PWM2_Duty);
187 2 PWMA_Duty3(PWMx->PWM3_Duty);
188 2 PWMA_Duty4(PWMx->PWM4_Duty);
189 2 }
190 1 else
191 1 {
192 2 PWMB_Duty5(PWMx->PWM5_Duty);
193 2 PWMB_Duty6(PWMx->PWM6_Duty);
194 2 PWMB_Duty7(PWMx->PWM7_Duty);
195 2 PWMB_Duty8(PWMx->PWM8_Duty);
196 2 }
197 1
198 1 EAXRAM(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展RAM(XRAM) */
199 1 }
200
201 /*********************************************************/
202 void PWM_config(void)
203 {
204 1 PWMx_InitDefine PWMx_InitStructure;
205 1 PWMx_InitStructure.PWM5_Mode = CCMRn_PWM_MODE1;
206 1 PWMx_InitStructure.PWM5_SetPriority = Priority_0;
207 1 PWMx_InitStructure.PWM_Period = 1500;
208 1 PWMx_InitStructure.PWM5_Duty = PWMB_Duty.PWM5_Duty;
209 1 PWMx_InitStructure.PWM_DeadTime = 0;
210 1 PWMx_InitStructure.PWM_EnoSelect = ENO5P;
211 1 PWMx_InitStructure.PWM_PS_SW = PWM5_SW_P17;
212 1 PWMx_InitStructure.PWM_CC5Enable = ENABLE;
213 1 PWMx_InitStructure.PWM_MainOutEnable = ENABLE; // ?÷????????, ENABLE,DISABLE
214 1 PWMx_InitStructure.PWM_CEN_Enable = ENABLE; // ?????????÷, ENABLE,DISABLE
215 1 PWM_Configuration(PWMB, &PWMx_InitStructure); // ??????PWM, PWMA,PWMB
216 1 PWMB_Duty.PWM5_Duty = 1500;
217 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1448 ----
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)

View File

@ -1,4 +1,4 @@
A51 MACRO ASSEMBLER STARTUP 04/10/2023 14:45:02 PAGE 1
A51 MACRO ASSEMBLER STARTUP 04/10/2023 17:32:45 PAGE 1
MACRO ASSEMBLER A51 V8.2.7.0
@ -65,7 +65,7 @@ LOC OBJ LINE SOURCE
55 ;
56 ; <h> Stack Space for reentrant functions in the SMALL model.
57 ; <q> IBPSTACK: Enable SMALL model reentrant stack
A51 MACRO ASSEMBLER STARTUP 04/10/2023 14:45:02 PAGE 2
A51 MACRO ASSEMBLER STARTUP 04/10/2023 17:32:45 PAGE 2
58 ; <i> Stack space for reentrant functions in the SMALL model.
0000 59 IBPSTACK EQU 0 ; set to 1 if small reentrant is used.
@ -133,7 +133,7 @@ LOC OBJ LINE SOURCE
121
122 EXTRN CODE (?C_START)
123 PUBLIC ?C_STARTUP
A51 MACRO ASSEMBLER STARTUP 04/10/2023 14:45:02 PAGE 3
A51 MACRO ASSEMBLER STARTUP 04/10/2023 17:32:45 PAGE 3
124
---- 125 CSEG AT 0
@ -201,7 +201,7 @@ LOC OBJ LINE SOURCE
187 ; This code is required if you use L51_BANK.A51 with Banking Mode 4
188 ;<h> Code Banking
189 ; <q> Select Bank 0 for L51_BANK.A51 Mode 4
A51 MACRO ASSEMBLER STARTUP 04/10/2023 14:45:02 PAGE 4
A51 MACRO ASSEMBLER STARTUP 04/10/2023 17:32:45 PAGE 4
190
@ -212,7 +212,7 @@ LOC OBJ LINE SOURCE
0009 020000 F 196 LJMP ?C_START
197
198 END
A51 MACRO ASSEMBLER STARTUP 04/10/2023 14:45:02 PAGE 5
A51 MACRO ASSEMBLER STARTUP 04/10/2023 17:32:45 PAGE 5
SYMBOL TABLE LISTING
------ ----- -------

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
C51 COMPILER V9.60.0.0 MAIN 04/10/2023 15:47:03 PAGE 1
C51 COMPILER V9.60.0.0 MAIN 04/10/2023 17:45:23 PAGE 1
C51 COMPILER V9.60.0.0, COMPILATION OF MODULE MAIN
@ -24,22 +24,24 @@ line level source
14 #include "GPIO.h"
15 #include "Exti.h"
16 #include "timer.h"
17
17 #include "PWM.h"
18 /******************** Ö÷º¯Êý***********************/
19 void main(void)
20 {
21 1 GPIO_config();
22 1 Exti_config();
23 1 Timer_config();
24 1 EA = 1;
25 1 while (1)
26 1 {
27 2 }
28 1 }
24 1 PWM_config();
25 1 EA = 1;
26 1 while (1)
27 1 {
28 2 UpdatePwm(PWMB, &PWMB_Duty);
29 2 }
30 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 13 ----
CODE SIZE = 27 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----

View File

@ -1,4 +1,4 @@
C51 COMPILER V9.60.0.0 TIMER 04/10/2023 15:47:03 PAGE 1
C51 COMPILER V9.60.0.0 TIMER 04/11/2023 08:44:51 PAGE 1
C51 COMPILER V9.60.0.0, COMPILATION OF MODULE TIMER
@ -26,182 +26,253 @@ line level source
16
17 ******************************************/
18
19 #include "timer.h"
20 u8 KILL_time = 0;
21 /********************* Timer0中断函数************************/
22 void timer0_int (void) interrupt TIMER0_VECTOR
23 {
24 1 if (KILL_time)
25 1 {
26 2 KILL_time--;
27 2 }
28 1 }
29
30 /********************* Timer1中断函数************************/
31 void timer1_int (void) interrupt TIMER1_VECTOR
32 {
33 1
34 1 }
35
36 /********************* Timer2中断函数************************/
37 void timer2_int (void) interrupt TIMER2_VECTOR
38 {
39 1
40 1 }
41
42 /********************* Timer3中断函数************************/
43 void timer3_int (void) interrupt TIMER3_VECTOR
44 {
45 1
46 1 }
47
48 /********************* Timer4中断函数************************/
49 void timer4_int (void) interrupt TIMER4_VECTOR
50 {
51 1
52 1 }
53
54
C51 COMPILER V9.60.0.0 TIMER 04/10/2023 15:47:03 PAGE 2
19 #include "timer.h"
20 #include "PWM.h"
21 #include "GPIO.h"
22 u8 KILL_time = 0;
23 u8 pwm_direction = 0;
24
25 /********************* Timer0中断函数************************/
26 void timer0_int(void) interrupt TIMER0_VECTOR
27 {
28 1 if (KILL_time)
29 1 KILL_time--;
30 1 if (!power3_gpio)
31 1 {
32 2 if (pwm_direction)
33 2 {
34 3 PWMB_Duty.PWM5_Duty++;
35 3 if (PWMB_Duty.PWM5_Duty >= 1500)
36 3 pwm_direction = 0;
37 3 }
38 2 else
39 2 {
40 3 PWMB_Duty.PWM5_Duty--;
41 3 if (!PWMB_Duty.PWM5_Duty)
42 3 pwm_direction = 1;
43 3 }
44 2 }
45 1 else
46 1 {
47 2 PWMB_Duty.PWM5_Duty = 1500;
48 2 }
49 1 }
50
51 /********************* Timer1中断函数************************/
52 void timer1_int(void) interrupt TIMER1_VECTOR
53 {
54 1 }
C51 COMPILER V9.60.0.0 TIMER 04/11/2023 08:44:51 PAGE 2
55 //========================================================================
56 // 函数: u8 Timer_Inilize(u8 TIM, TIM_InitTypeDef *TIMx)
57 // 描述: 定时器初始化程序.
58 // 参数: TIMx: 结构参数,请参考timer.h里的定义.
59 // 返回: 成功返回0, 空操作返回1,错误返回2.
60 // 版本: V1.0, 2012-10-22
61 //========================================================================
62 u8 Timer_Inilize(u8 TIM, TIM_InitTypeDef *TIMx)
55
56 /********************* Timer2中断函数************************/
57 void timer2_int(void) interrupt TIMER2_VECTOR
58 {
59 1 }
60
61 /********************* Timer3中断函数************************/
62 void timer3_int(void) interrupt TIMER3_VECTOR
63 {
64 1 if(TIM > Timer4) return 1; //空操作
65 1
66 1 if(TIM == Timer0)
67 1 {
68 2 Timer0_Stop(); //停止计数
69 2 if(TIMx->TIM_Interrupt == ENABLE) Timer0_InterruptEnable(); //允许中断
70 2 else Timer0_InterruptDisable(); //禁止中断
71 2 if(TIMx->TIM_Priority > Priority_3) return 2; //错误
72 2 Timer0_Priority(TIMx->TIM_Priority); //指定中断优先级(低到高) Priority_0,Priority_1,Priority_2,Priority_
-3
73 2
74 2 if(TIMx->TIM_Mode >= TIM_16BitAutoReloadNoMask) return 2; //错误
75 2 TMOD = (TMOD & ~0x03) | TIMx->TIM_Mode; //工作模式,0: 16位自动重装, 1: 16位定时/计数, 2: 8位自动重装, 3:
- 不可屏蔽16位自动重装
76 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer0_12T(); //12T
77 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer0_1T(); //1T
78 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer0_AsCounter(); //对外计数或分频
79 2 else Timer0_AsTimer(); //定时
80 2 if(TIMx->TIM_ClkOut == ENABLE) Timer0_CLKO_Enable(); //输出时钟
81 2 else Timer0_CLKO_Disable(); //不输出时钟
82 2
83 2 T0_Load(TIMx->TIM_Value);
84 2 if(TIMx->TIM_Run == ENABLE) Timer0_Run(); //开始运行
85 2 return 0; //成功
86 2 }
87 1
88 1 if(TIM == Timer1)
89 1 {
90 2 Timer1_Stop(); //停止计数
91 2 if(TIMx->TIM_Interrupt == ENABLE) Timer1_InterruptEnable(); //允许中断
92 2 else Timer1_InterruptDisable(); //禁止中断
93 2 if(TIMx->TIM_Priority > Priority_3) return 2; //错误
94 2 Timer1_Priority(TIMx->TIM_Priority); //指定中断优先级(低到高) Priority_0,Priority_1,Priority_2,Priority_
-3
95 2 if(TIMx->TIM_Mode >= TIM_16BitAutoReloadNoMask) return 2; //错误
96 2 TMOD = (TMOD & ~0x30) | (TIMx->TIM_Mode<<4); //工作模式,0: 16位自动重装, 1: 16位定时/计数, 2: 8位自动重<E58AA8>
-<2D>, 3: 停止工作
97 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer1_12T(); //12T
98 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer1_1T(); //1T
99 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer1_AsCounter(); //对外计数或分频
100 2 else Timer1_AsTimer(); //定时
101 2 if(TIMx->TIM_ClkOut == ENABLE) Timer1_CLKO_Enable(); //输出时钟
102 2 else Timer1_CLKO_Disable(); //不输出时钟
103 2
104 2 T1_Load(TIMx->TIM_Value);
105 2 if(TIMx->TIM_Run == ENABLE) Timer1_Run(); //开始运行
106 2 return 0; //成功
107 2 }
108 1
109 1 if(TIM == Timer2) //Timer2,固定为16位自动重装, 中断无优先级
110 1 {
111 2 Timer2_Stop(); //停止计数
112 2 if(TIMx->TIM_Interrupt == ENABLE) Timer2_InterruptEnable(); //允许中断
C51 COMPILER V9.60.0.0 TIMER 04/10/2023 15:47:03 PAGE 3
64 1 }
65
66 /********************* Timer4中断函数************************/
67 void timer4_int(void) interrupt TIMER4_VECTOR
68 {
69 1 }
70
71 //========================================================================
72 // 函数: u8 Timer_Inilize(u8 TIM, TIM_InitTypeDef *TIMx)
73 // 描述: 定时器初始化程序.
74 // 参数: TIMx: 结构参数,请参考timer.h里的定义.
75 // 返回: 成功返回0, 空操作返回1,错误返回2.
76 // 版本: V1.0, 2012-10-22
77 //========================================================================
78 u8 Timer_Inilize(u8 TIM, TIM_InitTypeDef *TIMx)
79 {
80 1 if (TIM > Timer4)
81 1 return 1; // 空操作
82 1
83 1 if (TIM == Timer0)
84 1 {
85 2 Timer0_Stop(); // 停止计数
86 2 if (TIMx->TIM_Interrupt == ENABLE)
87 2 Timer0_InterruptEnable(); // 允许中断
88 2 else
89 2 Timer0_InterruptDisable(); // 禁止中断
90 2 if (TIMx->TIM_Priority > Priority_3)
91 2 return 2; // 错误
92 2 Timer0_Priority(TIMx->TIM_Priority); // 指定中断优先级(低到高) Priority_0,Priority_1,Priority_2,Pr
-iority_3
93 2
94 2 if (TIMx->TIM_Mode >= TIM_16BitAutoReloadNoMask)
95 2 return 2; // 错误
96 2 TMOD = (TMOD & ~0x03) | TIMx->TIM_Mode; // 工作模式,0: 16位自动重装, 1: 16位定时/计数, 2: 8位自动<E887AA>
-刈<>, 3: 不可屏蔽16位自动重装
97 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_12T)
98 2 Timer0_12T(); // 12T
99 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_1T)
100 2 Timer0_1T(); // 1T
101 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_Ext)
102 2 Timer0_AsCounter(); // 对外计数或分频
103 2 else
104 2 Timer0_AsTimer(); // 定时
105 2 if (TIMx->TIM_ClkOut == ENABLE)
106 2 Timer0_CLKO_Enable(); // 输出时钟
107 2 else
108 2 Timer0_CLKO_Disable(); // 不输出时钟
109 2
110 2 T0_Load(TIMx->TIM_Value);
111 2 if (TIMx->TIM_Run == ENABLE)
112 2 Timer0_Run(); // 开始运行
113 2 return 0; // 成功
114 2 }
C51 COMPILER V9.60.0.0 TIMER 04/11/2023 08:44:51 PAGE 3
113 2 else Timer2_InterruptDisable(); //禁止中断
114 2 if(TIMx->TIM_ClkSource > TIM_CLOCK_Ext) return 2;
115 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer2_12T(); //12T
116 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer2_1T(); //1T
117 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer2_AsCounter(); //对外计数或分频
118 2 else Timer2_AsTimer(); //定时
119 2 if(TIMx->TIM_ClkOut == ENABLE) Timer2_CLKO_Enable(); //输出时钟
120 2 else Timer2_CLKO_Disable(); //不输出时钟
121 2
122 2 T2_Load(TIMx->TIM_Value);
123 2 if(TIMx->TIM_Run == ENABLE) Timer2_Run(); //开始运行
124 2 return 0; //成功
125 2 }
126 1
127 1 if(TIM == Timer3) //Timer3,固定为16位自动重装, 中断无优先级
128 1 {
129 2 Timer3_Stop(); //停止计数
130 2 if(TIMx->TIM_Interrupt == ENABLE) Timer3_InterruptEnable(); //允许中断
131 2 else Timer3_InterruptDisable(); //禁止中断
132 2 if(TIMx->TIM_ClkSource > TIM_CLOCK_Ext) return 2;
133 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer3_12T(); //12T
134 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer3_1T(); //1T
135 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer3_AsCounter(); //对外计数或分频
136 2 else Timer3_AsTimer(); //定时
137 2 if(TIMx->TIM_ClkOut == ENABLE) Timer3_CLKO_Enable(); //输出时钟
138 2 else Timer3_CLKO_Disable(); //不输出时钟
139 2
140 2 T3_Load(TIMx->TIM_Value);
141 2 if(TIMx->TIM_Run == ENABLE) Timer3_Run(); //开始运行
142 2 return 0; //成功
143 2 }
144 1
145 1 if(TIM == Timer4) //Timer3,固定为16位自动重装, 中断无优先级
146 1 {
147 2 Timer4_Stop(); //停止计数
148 2 if(TIMx->TIM_Interrupt == ENABLE) Timer4_InterruptEnable(); //允许中断
149 2 else Timer4_InterruptDisable(); //禁止中断
150 2 if(TIMx->TIM_ClkSource > TIM_CLOCK_Ext) return 2;
151 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer4_12T(); //12T
152 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer4_1T(); //1T
153 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer4_AsCounter(); //对外计数或分频
154 2 else Timer4_AsTimer(); //定时
155 2 if(TIMx->TIM_ClkOut == ENABLE) Timer4_CLKO_Enable(); //输出时钟
156 2 else Timer4_CLKO_Disable(); //不输出时钟
157 2
158 2 T4_Load(TIMx->TIM_Value);
159 2 if(TIMx->TIM_Run == ENABLE) Timer4_Run(); //开始运行
160 2 return 0; //成功
161 2 }
162 1 return 2; //错误
163 1 }
164 /************************ ?¨?±?÷???? ****************************/
165 void Timer_config(void)
166 {
167 1 TIM_InitTypeDef TIM_InitStructure;
168 1 TIM_InitStructure.TIM_Mode = TIM_16BitAutoReload;
169 1 TIM_InitStructure.TIM_Priority = Priority_0;
170 1 TIM_InitStructure.TIM_Interrupt = ENABLE;
171 1 TIM_InitStructure.TIM_ClkSource = TIM_CLOCK_1T;
172 1 TIM_InitStructure.TIM_ClkOut = DISABLE;
173 1 TIM_InitStructure.TIM_Value = 65536UL - (MAIN_Fosc / 1000UL);
174 1 TIM_InitStructure.TIM_Run = ENABLE;
C51 COMPILER V9.60.0.0 TIMER 04/10/2023 15:47:03 PAGE 4
115 1
116 1 if (TIM == Timer1)
117 1 {
118 2 Timer1_Stop(); // 停止计数
119 2 if (TIMx->TIM_Interrupt == ENABLE)
120 2 Timer1_InterruptEnable(); // 允许中断
121 2 else
122 2 Timer1_InterruptDisable(); // 禁止中断
123 2 if (TIMx->TIM_Priority > Priority_3)
124 2 return 2; // 错误
125 2 Timer1_Priority(TIMx->TIM_Priority); // 指定中断优先级(低到高) Priority_0,Priority_1,Priority_2,Pr
-iority_3
126 2 if (TIMx->TIM_Mode >= TIM_16BitAutoReloadNoMask)
127 2 return 2; // 错误
128 2 TMOD = (TMOD & ~0x30) | (TIMx->TIM_Mode << 4); // 工作模式,0: 16位自动重装, 1: 16位定时/计数, 2: 8
-位自动重装, 3: 停止工作
129 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_12T)
130 2 Timer1_12T(); // 12T
131 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_1T)
132 2 Timer1_1T(); // 1T
133 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_Ext)
134 2 Timer1_AsCounter(); // 对外计数或分频
135 2 else
136 2 Timer1_AsTimer(); // 定时
137 2 if (TIMx->TIM_ClkOut == ENABLE)
138 2 Timer1_CLKO_Enable(); // 输出时钟
139 2 else
140 2 Timer1_CLKO_Disable(); // 不输出时钟
141 2
142 2 T1_Load(TIMx->TIM_Value);
143 2 if (TIMx->TIM_Run == ENABLE)
144 2 Timer1_Run(); // 开始运行
145 2 return 0; // 成功
146 2 }
147 1
148 1 if (TIM == Timer2) // Timer2,固定为16位自动重装, 中断无优先级
149 1 {
150 2 Timer2_Stop(); // 停止计数
151 2 if (TIMx->TIM_Interrupt == ENABLE)
152 2 Timer2_InterruptEnable(); // 允许中断
153 2 else
154 2 Timer2_InterruptDisable(); // 禁止中断
155 2 if (TIMx->TIM_ClkSource > TIM_CLOCK_Ext)
156 2 return 2;
157 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_12T)
158 2 Timer2_12T(); // 12T
159 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_1T)
160 2 Timer2_1T(); // 1T
161 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_Ext)
162 2 Timer2_AsCounter(); // 对外计数或分频
163 2 else
164 2 Timer2_AsTimer(); // 定时
165 2 if (TIMx->TIM_ClkOut == ENABLE)
166 2 Timer2_CLKO_Enable(); // 输出时钟
167 2 else
168 2 Timer2_CLKO_Disable(); // 不输出时钟
169 2
170 2 T2_Load(TIMx->TIM_Value);
171 2 if (TIMx->TIM_Run == ENABLE)
172 2 Timer2_Run(); // 开始运行
173 2 return 0; // 成功
174 2 }
C51 COMPILER V9.60.0.0 TIMER 04/11/2023 08:44:51 PAGE 4
175 1 Timer_Inilize(Timer0,&TIM_InitStructure);
176 1 }
175 1
176 1 if (TIM == Timer3) // Timer3,固定为16位自动重装, 中断无优先级
177 1 {
178 2 Timer3_Stop(); // 停止计数
179 2 if (TIMx->TIM_Interrupt == ENABLE)
180 2 Timer3_InterruptEnable(); // 允许中断
181 2 else
182 2 Timer3_InterruptDisable(); // 禁止中断
183 2 if (TIMx->TIM_ClkSource > TIM_CLOCK_Ext)
184 2 return 2;
185 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_12T)
186 2 Timer3_12T(); // 12T
187 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_1T)
188 2 Timer3_1T(); // 1T
189 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_Ext)
190 2 Timer3_AsCounter(); // 对外计数或分频
191 2 else
192 2 Timer3_AsTimer(); // 定时
193 2 if (TIMx->TIM_ClkOut == ENABLE)
194 2 Timer3_CLKO_Enable(); // 输出时钟
195 2 else
196 2 Timer3_CLKO_Disable(); // 不输出时钟
197 2
198 2 T3_Load(TIMx->TIM_Value);
199 2 if (TIMx->TIM_Run == ENABLE)
200 2 Timer3_Run(); // 开始运行
201 2 return 0; // 成功
202 2 }
203 1
204 1 if (TIM == Timer4) // Timer3,固定为16位自动重装, 中断无优先级
205 1 {
206 2 Timer4_Stop(); // 停止计数
207 2 if (TIMx->TIM_Interrupt == ENABLE)
208 2 Timer4_InterruptEnable(); // 允许中断
209 2 else
210 2 Timer4_InterruptDisable(); // 禁止中断
211 2 if (TIMx->TIM_ClkSource > TIM_CLOCK_Ext)
212 2 return 2;
213 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_12T)
214 2 Timer4_12T(); // 12T
215 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_1T)
216 2 Timer4_1T(); // 1T
217 2 if (TIMx->TIM_ClkSource == TIM_CLOCK_Ext)
218 2 Timer4_AsCounter(); // 对外计数或分频
219 2 else
220 2 Timer4_AsTimer(); // 定时
221 2 if (TIMx->TIM_ClkOut == ENABLE)
222 2 Timer4_CLKO_Enable(); // 输出时钟
223 2 else
224 2 Timer4_CLKO_Disable(); // 不输出时钟
225 2
226 2 T4_Load(TIMx->TIM_Value);
227 2 if (TIMx->TIM_Run == ENABLE)
228 2 Timer4_Run(); // 开始运行
229 2 return 0; // 成功
230 2 }
231 1 return 2; // 错误
232 1 }
233 /************************ ?¨?±?÷???? ****************************/
234 void Timer_config(void)
235 {
236 1 TIM_InitTypeDef TIM_InitStructure;
C51 COMPILER V9.60.0.0 TIMER 04/11/2023 08:44:51 PAGE 5
237 1 TIM_InitStructure.TIM_Mode = TIM_16BitAutoReload;
238 1 TIM_InitStructure.TIM_Priority = Priority_0;
239 1 TIM_InitStructure.TIM_Interrupt = ENABLE;
240 1 TIM_InitStructure.TIM_ClkSource = TIM_CLOCK_1T;
241 1 TIM_InitStructure.TIM_ClkOut = DISABLE;
242 1 TIM_InitStructure.TIM_Value = 65536UL - (MAIN_Fosc / 1000UL);
243 1 TIM_InitStructure.TIM_Run = ENABLE;
244 1 Timer_Inilize(Timer0, &TIM_InitStructure);
245 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 862 ----
CODE SIZE = 920 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 1 8
DATA SIZE = 2 8
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.

Binary file not shown.

View File

@ -1 +0,0 @@
"mycode\GPIO.c" OPTIMIZE (8,SPEED) BROWSE INCDIR(.\myinc) DEBUG OBJECTEXTEND PRINT(.\Listings\GPIO.lst) TABS (2) OBJECT(.\Objects\GPIO.obj)

Binary file not shown.

1
Objects/PWM.__i Normal file
View File

@ -0,0 +1 @@
"mycode\PWM.C" OPTIMIZE (8,SPEED) BROWSE INCDIR(.\myinc) DEBUG OBJECTEXTEND PRINT(.\Listings\PWM.lst) TABS (2) OBJECT(.\Objects\PWM.obj)

BIN
Objects/PWM.obj Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -23,12 +23,10 @@ Project File Date: 04/10/2023
<h2>Output:</h2>
Build target 'Target 1'
compiling Exti.c...
compiling GPIO.c...
compiling main.c...
compiling timer.c...
compiling PWM.C...
linking...
Program Size: data=18.0 xdata=0 code=2183
Program Size: data=79.0 xdata=0 code=3749
creating hex file from ".\Objects\kill_control"...
".\Objects\kill_control" - 0 Error(s), 0 Warning(s).
Build Time Elapsed: 00:00:00

View File

@ -1,163 +1,264 @@
:030000000207767E
:0C077600787FE4F6D8FD7581100207BD05
:0300030002006692
:10006600C0E030B20CE510700BB290B291B2928043
:0700760003751032D0E032E7
:0300130002000ADE
:03000000020D0EE0
:0C0D0E00787FE4F6D8FD75814D020D558C
:03000300020EA446
:100EA400C0E030B20CE54C700BB290B291B29280BB
:070EB40003754C32D0E0325F
:03001300020006E2
:0100060032C7
:03005300020007A1
:0100070032C6
:03005B0002000898
:0100080032C5
:030083000200096F
:0100090032C4
:100B3D00EFD394047480948040037F0122EF7061A1
:100B4D00C289900002120C7E64017004D2A880024A
:100B5D00C2A8900001120C7EFED394037480948081
:100B6D0040037F0222EEFD7C00700553B7FEC2B834
:100B7D00ED64014C700553B7FED2B8ED64024C70B4
:100B8D000543B701C2B8ED64034C700543B701D2FC
:100B9D00B8120C6564017004D2888002C2887F008F
:100BAD0022EF64017061C28B900002120C7E640111
:100BBD007004D2AA8002C2AA900001120C7EFED34C
:100BCD0094037480948040037F0222EEFD7C0070BC
:100BDD000553B7FBC2BAED64014C700553B7FBD298
:100BED00BAED64024C700543B704C2BAED64034C10
:100BFD00700543B704D2BA120C6564017004D28A31
:100C0D008002C28A7F0022EF6402701590000212EA
:100C1D000C7E64017005438F108003538FEF7F00AE
:100C2D0022EF64037015900002120C7E64017005B2
:100C3D00438F208003538FDF7F0022EF64047015F4
:100C4D00900002120C7E64017005438F40800353A7
:080C5D008FBF7F00227F0222FD
:10008600750A01E4F508F509FB7A007908FF020B09
:010096003D2C
:1008C600EFD394077480948040037F0122120C6555
:1008D600FED394037480948040037F0222EF704419
:1008E600EE700B900001120C7EF452935294120C8F
:1008F600656401700B900001120C7E4293F45294D1
:10090600120C65FE6402700A900001120C7E42937E
:100916004294EE6403700D900001120C7EFEF452B8
:1009260093EE4294EF64017046120C65FE700B90D4
:100936000001120C7EF452915292EE6401700B90FB
:100946000001120C7E4291F45292120C6564027000
:100956000A900001120C7E42914292120C656403C9
:10096600700D900001120C7EFEF45291EE4292EF51
:1009760064027046120C65FE700B900001120C7E2C
:10098600F452955296EE6401700B900001120C7EA3
:100996004295F45296120C656402700A9000011298
:1009A6000C7E42954296120C656403700D90000110
:1009B600120C7EFEF45295EE4296EF6403704612D8
:1009C6000C65FE700B900001120C7EF452B152B20F
:1009D600EE6401700B900001120C7E42B1F452B22B
:1009E600120C656402700A900001120C7E42B1423C
:1009F600B2120C656403700D900001120C7EFEF4B9
:100A060052B1EE42B2EF64047046120C65FE700BF2
:100A1600900001120C7EF452B352B4EE6401700BD6
:100A2600900001120C7E42B3F452B4120C656402BB
:100A3600700A900001120C7E42B342B4120C656437
:100A460003700D900001120C7EFEF452B3EE42B418
:100A5600EF64057046120C65FE700B900001120CD7
:100A66007EF452C952CAEE6401700B900001120C5A
:100A76007E42C9F452CA120C656402700A900001E3
:100A8600120C7E42C942CA120C656403700D9000B6
:100A960001120C7EFEF452C9EE42CAEF640670469D
:100AA600120C65FE700B900001120C7EF452CB52B4
:100AB600CCEE6401700B900001120C7E42CBF45216
:100AC600CC120C656402700A900001120C7E42CBB7
:100AD60042CC120C656403700D900001120C7EFE70
:100AE600F452CBEE42CCEF64077049120C65FF7EE0
:100AF60000700B900001120C7EF452E152E2EF649A
:100B0600014E700B900001120C7E42E1F452E2128B
:100B16000C656402700A900001120C7E42E142E20A
:100B2600120C656403700D900001120C7EFFF452E6
:070B3600E1EF42E27F002223
:100E6400750904E4F508FB7A0079087F031208C6C3
:100E74007509077508037F011208C6C290C291C2A2
:010E840092DB
:010E8500224A
:10006600120E64120086120E8612001ED2AF7B009C
:0B0076007A00793C7F02120D9A80F3A3
:060EBB00014C00014D0096
:03000B00020E1FC3
:100E1F00C0E0C0D0E54C6002154C20922DE54D602E
:100E2F00160545E54570020544C394DCE544940579
:100E3F00401E754D008019E545154570021544E5B6
:100E4F00454544700B754D0180067544057545DCAD
:050E5F00D0D0D0E0320C
:03001B0002000AD6
:01000A0032C3
:0300530002000E9A
:0300630002000E8A
:01000E0032BF
:03005B0002000F91
:03009B0002000F51
:01000F0032BE
:0300830002001068
:0300A30002001048
:0100100032BD
:10064E00EFD394047480948040037F0122EF706195
:10065E00C28990000212081B64017004D2A88002A5
:10066E00C2A890000112081BFED3940374809480DC
:10067E0040037F0222EEFD7C00700553B7FEC2B828
:10068E00ED64014C700553B7FED2B8ED64024C70A8
:10069E000543B701C2B8ED64034C700543B701D2F0
:1006AE00B812080264017004D2888002C2887F00EA
:1006BE0022EF64017061C28B90000212081B64016C
:1006CE007004D2AA8002C2AA90000112081BFED3A7
:1006DE0094037480948040037F0222EEFD7C0070B0
:1006EE000553B7FBC2BAED64014C700553B7FBD28C
:1006FE00BAED64024C700543B704C2BAED64034C04
:10070E00700543B704D2BA12080264017004D28A8B
:10071E008002C28A7F0022EF6402701590000212DE
:10072E00081B64017005438F108003538FEF7F0009
:10073E0022EF6403701590000212081B640170050D
:10074E00438F208003538FDF7F0022EF64047015E8
:10075E0090000212081B64017005438F4080035302
:08076E008FBF7F00227F0222F1
:10004000750A01E4F508F509FB7A007908FF020654
:010050004E61
:1003D700EFD394077480948040037F0122120802B0
:1003E700FED394037480948040037F0222EF70440D
:1003F700EE700B90000112081BF4529352941208EE
:10040700026401700B90000112081B4293F452948E
:10041700120802FE6402700A90000112081B429340
:100427004294EE6403700D90000112081BFEF45213
:1004370093EE4294EF64017046120802FE700B902F
:10044700000112081BF452915292EE6401700B9056
:10045700000112081B4291F45292120802640270C2
:100467000A90000112081B4291429212080264038B
:10047700700D90000112081BFEF45291EE4292EFAC
:1004870064027046120802FE700B90000112081BEE
:10049700F452955296EE6401700B90000112081BFE
:1004A7004295F452961208026402700A90000112F3
:1004B700081B429542961208026403700D900001D2
:1004C70012081BFEF45295EE4296EF640370461233
:1004D7000802FE700B90000112081BF452B152B2D1
:1004E700EE6401700B90000112081B42B1F452B286
:1004F7001208026402700A90000112081B42B142FE
:10050700B21208026403700D90000112081BFEF47A
:1005170052B1EE42B2EF64047046120802FE700B4D
:1005270090000112081BF452B352B4EE6401700B31
:1005370090000112081B42B3F452B412080264027D
:10054700700A90000112081B42B342B412080264F9
:1005570003700D90000112081BFEF452B3EE42B473
:10056700EF64057046120802FE700B900001120836
:100577001BF452C952CAEE6401700B9000011208B5
:100587001B42C9F452CA1208026402700A900001A1
:1005970012081B42C942CA1208026403700D900078
:1005A7000112081BFEF452C9EE42CAEF64067046F8
:1005B700120802FE700B90000112081BF452CB5276
:1005C700CCEE6401700B90000112081B42CBF45271
:1005D700CC1208026402700A90000112081B42CB79
:1005E70042CC1208026403700D90000112081BFE32
:1005F700F452CBEE42CCEF64077049120802FF7E3B
:1006070000700B90000112081BF452E152E2EF64F4
:10061700014E700B90000112081B42E1F452E212E6
:1006270008026402700A90000112081B42E142E2CC
:100637001208026403700D90000112081BFFF452A8
:07064700E1EF42E27F002217
:10001E00750904E4F508FB7A0079087F031203D70B
:10002E007509077508037F011203D7C290C291C2EA
:01003E00922F
:01003F00229E
:0D00860012001E120040120880D2AF80FE52
:03000600011000E6
:03000B0002089E4A
:0B089E00C0E0E51060021510D0E03251
:03001B00020011CF
:0100110032BC
:0300630002001286
:0100120032BB
:03009B000200164A
:0100160032B7
:0300A30002001741
:0100170032B6
:1000A600AD07EDD394047480948040037F0122ED64
:1000B600600302017BC28C90000212081B6401706F
:1000C60004D2A98002C2A990000112081BFED39493
:1000D600037480948040037F0222EEFF7E00700549
:1000E60053B7FDC2B9EF64014E700553B7FDD2B9DF
:1000F600EF64024E700543B702C2B9EF64034E7057
:100106000543B702D2B9120802FEC3940374809461
:100116008040037F0222E58954FC4EF58990000356
:1001260012081BFF7E0064017003538E7FEF4E7032
:1001360003438E80EF64024E7005438904800353A7
:1001460089FB90000412081B64017005438F01802F
:1001560003538FFE900005120848E5F0F58C9000D9
:1001660005120848F58A90000712081B6401700200
:10017600D28C7F0022ED64016003020248C28E9099
:10018600000212081B64017004D2AB8002C2AB905D
:10019600000112081BFED394037480948040037FF1
:1001A6000222EEFF7E00700553B7F7C2BBEF640173
:1001B6004E700553B7F7D2BBEF64024E700543B7D6
:1001C60008C2BBEF64034E700543B708D2BB1208E2
:1001D60002FEC394037480948040037F0222EEC41F
:1001E60054F0FFE58954CF4FF58990000312081BA0
:1001F600FF7E0064017003538EBFEF4E7003438E83
:1002060040EF64024E700543894080035389BF90D6
:10021600000412081B64017005438F028003538F8C
:10022600FD900005120848E5F0F58D9000051208CE
:1002360048F58B90000712081B64017002D28E7F6E
:100246000022ED6402707C538EEF90000212081BB0
:100256006401700543AF04800353AFFB90000312A3
:10026600081BFED394027480948040037F0222EE22
:10027600FF7E0064017003538EFBEF4E7003438EC6
:1002860004EF64024E7005438E088003538EF79088
:10029600000412081B64017005438F048003538F0A
:1002A600FB900005120848E5F0F5D6900005120807
:1002B60048F5D790000712081B64017003438E109F
:1002C6007F0022ED6403707C53D1F7900002120880
:1002D6001B6401700543AF20800353AFDF9000031A
:1002E60012081BFED394027480948040037F02227E
:1002F600EEFF7E006401700353D1FDEF4E700343A1
:10030600D102EF64024E700543D104800353D1FB42
:1003160090000412081B6401700543D10180035349
:10032600D1FE900005120848E5F0F5D490000512BC
:100336000848F5D590000712081B6401700343D1E5
:10034600087F0022ED640460030203D453D17F903A
:10035600000212081B6401700543AF40800353AFCF
:10036600BF90000312081BFD7C00D3940274809496
:100376008040037F0222ED64014C700353D1DF906D
:10038600000312081B700343D12090000312081BC0
:100396006402700543D140800353D1BF900004121C
:1003A600081B6401700543D110800353D1EF900000
:1003B60005120848FDACF0ECF5D2AF058FD39000DE
:1003C6000712081B6401700343D1807F00227F025D
:0103D6002204
:10088000E4F508F509750A01F50BF50C750DD4753D
:0E0890000ECD750F01FB7A007908FF0200A65D
:10078200020086E493A3F8E493A34003F68001F207
:1007920008DFF48029E493A3F85407240CC8C33378
:1007A200C4540F4420C8834004F456800146F6DF47
:1007B200E4800B0102040810204080900006E47ED1
:1007C200019360BCA3FF543F30E509541FFEE4933C
:1007D200A360010ECF54C025E060A840B8E493A303
:1007E200FAE493A3F8E493A3C8C582C8CAC583CA2E
:1007F200F0A3C8C582C8CAC583CADFE9DEE780BEE6
:0100090000F6
:10080200BB010689828A83E0225002E722BBFE02F4
:09081200E32289828A83E4932227
:10081B00BB010CE58229F582E5833AF583E0225092
:10082B0006E92582F8E622BBFE06E92582F8E222DC
:0D083B00E58229F582E5833AF583E49322F6
:10084800BB0110E58229F582E5833AF583E0F5F0EE
:10085800A3E0225009E92582F886F008E622BBFECB
:100868000AE92582F8E2F5F008E222E5832AF58311
:08087800E993F5F0A3E99322D6
:10059500AD07EDD394047480948040037F0122ED70
:1005A500600302066AC28C900002120C7E64017020
:1005B50004D2A98002C2A9900001120C7EFED39438
:1005C500037480948040037F0222EEFF7E00700555
:1005D50053B7FDC2B9EF64014E700553B7FDD2B9EB
:1005E500EF64024E700543B702C2B9EF64034E7063
:1005F5000543B702D2B9120C65FEC3940374809407
:100605008040037F0222E58954FC4EF58990000362
:10061500120C7EFF7E0064017003538E7FEF4E70D7
:1006250003438E80EF64024E7005438904800353B3
:1006350089FB900004120C7E64017005438F0180D4
:1006450003538FFE900005120CD6E5F0F58C900053
:1006550005120CD6F58A900007120C7E6401700213
:10066500D28C7F0022ED64016003020737C28E90B1
:100675000002120C7E64017004D2AB8002C2AB9002
:100685000001120C7EFED394037480948040037F96
:100695000222EEFF7E00700553B7F7C2BBEF64017F
:1006A5004E700553B7F7D2BBEF64024E700543B7E2
:1006B50008C2BBEF64034E700543B708D2BB120CEA
:1006C50065FEC394037480948040037F0222EEC4C8
:1006D50054F0FFE58954CF4FF589900003120C7E45
:1006E500FF7E0064017003538EBFEF4E7003438E8F
:1006F50040EF64024E700543894080035389BF90E3
:100705000004120C7E64017005438F028003538F31
:10071500FD900005120CD6E5F0F58D900005120C44
:10072500D6F58B900007120C7E64017002D28E7F85
:100735000022ED6402707C538EEF900002120C7E55
:100745006401700543AF04800353AFFB90000312AF
:100755000C7EFED394027480948040037F0222EEC7
:10076500FF7E0064017003538EFBEF4E7003438ED2
:1007750004EF64024E7005438E088003538EF79094
:100785000004120C7E64017005438F048003538FAF
:10079500FB900005120CD6E5F0F5D6900005120C7D
:1007A500D6F5D7900007120C7E64017003438E10B6
:1007B5007F0022ED6403707C53D1F7900002120C88
:1007C5007E6401700543AF20800353AFDF900003C3
:1007D500120C7EFED394027480948040037F022223
:1007E500EEFF7E006401700353D1FDEF4E700343AD
:1007F500D102EF64024E700543D104800353D1FB4F
:10080500900004120C7E6401700543D101800353EE
:10081500D1FE900005120CD6E5F0F5D49000051236
:100825000CD6F5D5900007120C7E6401700343D1F8
:10083500087F0022ED640460030208C353D17F9052
:100845000002120C7E6401700543AF40800353AF74
:10085500BF900003120C7EFD7C00D394027480943B
:100865008040037F0222ED64014C700353D1DF9079
:100875000003120C7E700343D120900003120C7EFE
:100885006402700543D140800353D1BF9000041228
:100895000C7E6401700543D110800353D1EF9000A5
:1008A50005120CD6FDACF0ECF5D2AF058FD3900058
:1008B50007120C7E6401700343D1807F00227F0202
:0108C5002210
:100E8600E4F508F509750A01F50BF50C750DD47531
:0E0E96000ECD750F01FB7A007908FF0205955D
:1000A600EF640160030203A643BA80900029120C94
:1000B6007EFD7C00D3940374809480502DED7006F1
:1000C60053B6FB53B5FBED64014C700653B6FB43C8
:1000D600B504ED64024C700643B60453B5FBED64FB
:1000E600034C700643B60443B50490002A120C7EF6
:1000F600FD7C00D3940374809480502DED700653DC
:10010600B6F753B5F7ED64014C700653B6F743B531
:1001160008ED64024C700643B60853B5F7ED640368
:100126004C700643B60843B50890002B120C7EFDB2
:100136007C00D3940374809480502DED700653EEAA
:10014600EF53DFEFED64014C700653EEEF43DF1023
:10015600ED64024C700643EE1053DFEFED64034C82
:10016600700643EE1043DF1090002C120C7EFD7CCF
:1001760000D3940374809480502DED700653EEDF07
:1001860053DFDFED64014C700653EEDF43DF20EDF5
:1001960064024C700643EE2053DFDFED64034C70BF
:1001A6000643EE2043DF2090FECCE4F0A3F0120CD1
:1001B60065FE90FEC8E0548F4EF0900001120C7E52
:1001C600FE90FEC9E0548F4EF0900002120C7EFEA7
:1001D60090FECAE0548F4EF0900003120C7EFE9003
:1001E600FECBE0548F4EF0900027120C7E640190F7
:1001F600FEC87006E04408F08004E054F7F0900072
:1002060028120C7E640190FEC87006E04404F0805B
:1002160004E054FBF090001B120C7E640190FECCAF
:100226007006E04401F08004E054FEF090001C12D9
:100236000C7E640190FECC7006E04404F08004E07D
:1002460054FBF090001D120C7E640190FECC7006EB
:10025600E04410F08004E054EFF090001E120C7E93
:10026600640190FECC7006E04440F08004E054BF88
:10027600F090001F120C7E640190FECD7006E044E3
:1002860001F08004E054FEF0900020120C7E640120
:1002960090FECD7006E04404F08004E054FBF0903C
:1002A6000021120C7E640190FECD7006E04410F031
:1002B6008004E054EFF0900022120C7E640190FE60
:1002C600CD7006E04440F08004E054BFF090000892
:1002D600120CD6FD90FED2E5F0F0A3EDF090000AE8
:1002E600120CD6FD90FED5E5F0F0A3EDF090000CD3
:1002F600120CD6FD90FED7E5F0F0A3EDF090000EBF
:10030600120CD6FD90FED9E5F0F0A3EDF0900010AA
:10031600120CD6FD90FEDBE5F0F0A3EDF090002F79
:10032600120C7E90FEC17007E054FEFEF08005E0E0
:100336004401FEF090FEC1EEF0900030120C7E906B
:10034600FEB2F090002E120C7E90FEB1F090001AD4
:10035600120C7E90FEDEF0900032120C7E6401904C
:10036600FEDD7006E04410F08004E054EFF09000EB
:1003760033120C7E640190FEDD7006E04480F0804E
:1003860004E0547FF0900031120C7E640190FEC0B0
:100396007007E04401F002058CE054FEF002058C83
:1003A600EF6402600302059243BA8090002D120C9E
:1003B6007EFF7E00D3940374809480502DEF7006E8
:1003C60053EEBF53DFBFEF64014E700653EEBF43DB
:1003D600DF40EF64024E700643EE4053DFBFEF642A
:1003E600034E700643EE4043DF4090FEECE4F0A37C
:1003F600F0900004120C7EFF90FEE8E0548F4FF060
:10040600900005120C7EFF90FEE9E0548F4FF090AD
:100416000006120C7EFF90FEEAE0548F4FF090002B
:1004260007120C7EFF90FEEBE0548F4FF0900027F2
:10043600120C7E640190FEE87006E04408F0800429
:10044600E054F7F0900028120C7E640190FEE870EC
:1004560006E04404F08004E054FBF0900023120C04
:100466007E640190FEEC7006E04401F08004E054E6
:10047600FEF0900024120C7E640190FEEC7006E003
:100486004410F08004E054EFF0900025120C7E64D6
:100496000190FEED7006E04401F08004E054FEF0A9
:1004A600900026120C7E640190FEED7006E044106A
:1004B600F08004E054EFF0900008120CD6FF90FE96
:1004C600F2E5F0F0A3EFF0900012120CD6FF90FECA
:1004D600F5E5F0F0A3EFF0900014120CD6FF90FEB5
:1004E600F7E5F0F0A3EFF0900016120CD6FF90FEA1
:1004F600F9E5F0F0A3EFF0900018120CD6FF90FE8D
:10050600FBE5F0F0A3EFF090002F120C7E90FEC1F9
:100516007007E054FEFFF08005E04401FFF090FE16
:10052600C1EFF0900030120C7E90FEB6F090002ED7
:10053600120C7E90FEB5F090001A120C7E90FEFE14
:10054600F0900032120C7E640190FEFD7006E044CD
:1005560010F08004E054EFF0900033120C7E64013A
:1005660090FEFD7006E04480F08004E0547FF09039
:100576000031120C7E640190FEE07006E04401F04A
:0F0586008004E054FEF053BA7F7F00227F0222F0
:100D9A0043BA80EF64017039120CABFF90FED5E5BF
:100DAA00F0F0A3EFF0900002120CD6FF90FED7E508
:100DBA00F0F0A3EFF0900004120CD6FF90FED9E5F4
:100DCA00F0F0A3EFF0900006120CD6FF90FEDB8045
:100DDA003A900008120CD6FF90FEF5E5F0F0A3EF6A
:100DEA00F090000A120CD6FF90FEF7E5F0F0A3EFA0
:100DFA00F090000C120CD6FF90FEF9E5F0F0A3EF8C
:100E0A00F090000E120CD6FF90FEFBE5F0F0A3EF77
:050E1A00F053BA7F2235
:10001E00750C60E4F5357510057511DC85441A858F
:10002E00451BF522753601753801752B01753B019F
:10003E00753901FB7A0079087F021200A675440516
:03004E007545DC19
:01005100228C
:100D1A00020066E493A3F8E493A34003F68001F289
:100D2A0008DFF48029E493A3F85407240CC8C333DA
:100D3A00C4540F4420C8834004F456800146F6DFA9
:100D4A00E4800B0102040810204080900EBBE47E70
:100D5A00019360BCA3FF543F30E509541FFEE4939E
:100D6A00A360010ECF54C025E060A840B8E493A365
:100D7A00FAE493A3F8E493A3C8C582C8CAC583CA90
:100D8A00F0A3C8C582C8CAC583CADFE9DEE780BE48
:010EC1000030
:100C6500BB010689828A83E0225002E722BBFE028D
:090C7500E32289828A83E49322C0
:100C7E00BB010CE58229F582E5833AF583E022502B
:100C8E0006E92582F8E622BBFE06E92582F8E22275
:0D0C9E00E58229F582E5833AF583E493228F
:100CAB00BB010A89828A83E0F5F0A3E02250068714
:100CBB00F009E71922BBFE07E3F5F009E3192289D6
:0B0CCB00828A83E493F5F07401932209
:100CD600BB0110E58229F582E5833AF583E0F5F05C
:100CE600A3E0225009E92582F886F008E622BBFE39
:100CF6000AE92582F8E2F5F008E222E5832AF5837F
:080D0600E993F5F0A3E9932243
:00000001FF

View File

@ -2,6 +2,7 @@
".\Objects\Exti.obj",
".\Objects\GPIO.obj",
".\Objects\main.obj",
".\Objects\timer.obj"
".\Objects\timer.obj",
".\Objects\PWM.obj"
TO ".\Objects\kill_control"
PRINT(".\Listings\kill_control.m51") RAMSIZE(256)

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -236,6 +236,18 @@
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>6</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>.\mycode\PWM.C</PathWithFileName>
<FilenameWithoutPath>PWM.C</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>
</ProjectOpt>

View File

@ -406,6 +406,11 @@
<FileType>1</FileType>
<FilePath>.\mycode\timer.c</FilePath>
</File>
<File>
<FileName>PWM.C</FileName>
<FileType>1</FileType>
<FilePath>.\mycode\PWM.C</FilePath>
</File>
</Files>
</Group>
</Groups>

217
mycode/PWM.C Normal file
View File

@ -0,0 +1,217 @@
/*---------------------------------------------------------------------*/
/* --- STC MCU Limited ------------------------------------------------*/
/* --- STC 1T Series MCU Demo Programme -------------------------------*/
/* --- Mobile: (86)13922805190 ----------------------------------------*/
/* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/
/* --- Tel: 86-0513-55012928,55012929,55012966 ------------------------*/
/* --- Web: www.STCMCU.com --------------------------------------------*/
/* --- Web: www.STCMCUDATA.com ---------------------------------------*/
/* --- QQ: 800003751 -------------------------------------------------*/
/* 如果要在程序中使用此代码,请在程序中注明使用了STC的资料及程序 */
/*---------------------------------------------------------------------*/
#include "PWM.h"
PWMx_Duty PWMB_Duty;
u8 PWM_Configuration(u8 PWM, PWMx_InitDefine *PWMx)
{
if (PWM == PWMA)
{
EAXSFR(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展SFR(XSFR) */
if (PWMx->PWM1_SetPriority <= Priority_3)
PWM1_Priority(PWMx->PWM1_SetPriority); // 指定中断优先级(低到高) Priority_0,Priority_1,Priority_2,Priority_3
if (PWMx->PWM2_SetPriority <= Priority_3)
PWM2_Priority(PWMx->PWM2_SetPriority); // 指定中断优先级(低到高) Priority_0,Priority_1,Priority_2,Priority_3
if (PWMx->PWM3_SetPriority <= Priority_3)
PWM3_Priority(PWMx->PWM3_SetPriority); // 指定中断优先级(低到高) Priority_0,Priority_1,Priority_2,Priority_3
if (PWMx->PWM4_SetPriority <= Priority_3)
PWM4_Priority(PWMx->PWM4_SetPriority); // 指定中断优先级(低到高) Priority_0,Priority_1,Priority_2,Priority_3
PWMA_CCER1_Disable(); // 关闭所有输入捕获/比较输出
PWMA_CCER2_Disable(); // 关闭所有输入捕获/比较输出
PWMA_OC1ModeSet(PWMx->PWM1_Mode); // 设置输出比较模式
PWMA_OC2ModeSet(PWMx->PWM2_Mode); // 设置输出比较模式
PWMA_OC3ModeSet(PWMx->PWM3_Mode); // 设置输出比较模式
PWMA_OC4ModeSet(PWMx->PWM4_Mode); // 设置输出比较模式
if (PWMx->PWM_Reload == ENABLE)
PWMA_OC1_ReloadEnable(); // 输出比较的预装载使能
else
PWMA_OC1_RelosdDisable(); // 禁止输出比较的预装载
if (PWMx->PWM_Fast == ENABLE)
PWMA_OC1_FastEnable(); // 输出比较快速功能使能
else
PWMA_OC1_FastDisable(); // 禁止输出比较快速功能
if (PWMx->PWM_CC1Enable == ENABLE)
PWMA_CC1E_Enable(); // 开启输入捕获/比较输出
else
PWMA_CC1E_Disable(); // 关闭输入捕获/比较输出
if (PWMx->PWM_CC1NEnable == ENABLE)
PWMA_CC1NE_Enable(); // 开启输入捕获/比较输出
else
PWMA_CC1NE_Disable(); // 关闭输入捕获/比较输出
if (PWMx->PWM_CC2Enable == ENABLE)
PWMA_CC2E_Enable(); // 开启输入捕获/比较输出
else
PWMA_CC2E_Disable(); // 关闭输入捕获/比较输出
if (PWMx->PWM_CC2NEnable == ENABLE)
PWMA_CC2NE_Enable(); // 开启输入捕获/比较输出
else
PWMA_CC2NE_Disable(); // 关闭输入捕获/比较输出
if (PWMx->PWM_CC3Enable == ENABLE)
PWMA_CC3E_Enable(); // 开启输入捕获/比较输出
else
PWMA_CC3E_Disable(); // 关闭输入捕获/比较输出
if (PWMx->PWM_CC3NEnable == ENABLE)
PWMA_CC3NE_Enable(); // 开启输入捕获/比较输出
else
PWMA_CC3NE_Disable(); // 关闭输入捕获/比较输出
if (PWMx->PWM_CC4Enable == ENABLE)
PWMA_CC4E_Enable(); // 开启输入捕获/比较输出
else
PWMA_CC4E_Disable(); // 关闭输入捕获/比较输出
if (PWMx->PWM_CC4NEnable == ENABLE)
PWMA_CC4NE_Enable(); // 开启输入捕获/比较输出
else
PWMA_CC4NE_Disable(); // 关闭输入捕获/比较输出
PWMA_AutoReload(PWMx->PWM_Period);
PWMA_Duty1(PWMx->PWM1_Duty);
PWMA_Duty2(PWMx->PWM2_Duty);
PWMA_Duty3(PWMx->PWM3_Duty);
PWMA_Duty4(PWMx->PWM4_Duty);
PWMA_CCPCAPreloaded(PWMx->PWM_PreLoad); // 捕获/比较预装载控制位(该位只对具有互补输出的通道起作用)
PWMA_PS = PWMx->PWM_PS_SW; // 切换IO
PWMA_ENO = PWMx->PWM_EnoSelect; // 输出通道选择
PWMA_DeadTime(PWMx->PWM_DeadTime); // 死区发生器设置
if (PWMx->PWM_BrakeEnable == ENABLE)
PWMA_BrakeEnable(); // 开启刹车输入
else
PWMA_BrakeDisable(); // 禁止刹车输入
if (PWMx->PWM_MainOutEnable == ENABLE)
PWMA_BrakeOutputEnable(); // 主输出使能
else
PWMA_BrakeOutputDisable(); // 主输出禁止
if (PWMx->PWM_CEN_Enable == ENABLE)
PWMA_CEN_Enable(); // 使能计数器
else
PWMA_CEN_Disable(); // 禁止计数器
EAXRAM(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展RAM(XRAM) */
return 0;
}
if (PWM == PWMB)
{
EAXSFR(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展SFR(XSFR) */
if (PWMx->PWM5_SetPriority <= Priority_3)
PWM5_Priority(PWMx->PWM5_SetPriority); // 指定中断优先级(低到高) Priority_0,Priority_1,Priority_2,Priority_3
PWMB_CCER1_Disable(); // 关闭所有输入捕获/比较输出
PWMB_CCER2_Disable(); // 关闭所有输入捕获/比较输出
PWMB_OC5ModeSet(PWMx->PWM5_Mode); // 设置输出比较模式
PWMB_OC6ModeSet(PWMx->PWM6_Mode); // 设置输出比较模式
PWMB_OC7ModeSet(PWMx->PWM7_Mode); // 设置输出比较模式
PWMB_OC8ModeSet(PWMx->PWM8_Mode); // 设置输出比较模式
if (PWMx->PWM_Reload == ENABLE)
PWMB_OC5_ReloadEnable(); // 输出比较的预装载使能
else
PWMB_OC5_RelosdDisable(); // 禁止输出比较的预装载
if (PWMx->PWM_Fast == ENABLE)
PWMB_OC5_FastEnable(); // 输出比较快速功能使能
else
PWMB_OC5_FastDisable(); // 禁止输出比较快速功能
if (PWMx->PWM_CC5Enable == ENABLE)
PWMB_CC5E_Enable(); // 开启输入捕获/比较输出
else
PWMB_CC5E_Disable(); // 关闭输入捕获/比较输出
if (PWMx->PWM_CC6Enable == ENABLE)
PWMB_CC6E_Enable(); // 开启输入捕获/比较输出
else
PWMB_CC6E_Disable(); // 关闭输入捕获/比较输出
if (PWMx->PWM_CC7Enable == ENABLE)
PWMB_CC7E_Enable(); // 开启输入捕获/比较输出
else
PWMB_CC7E_Disable(); // 关闭输入捕获/比较输出
if (PWMx->PWM_CC8Enable == ENABLE)
PWMB_CC8E_Enable(); // 开启输入捕获/比较输出
else
PWMB_CC8E_Disable(); // 关闭输入捕获/比较输出
PWMB_AutoReload(PWMx->PWM_Period);
PWMB_Duty5(PWMx->PWM5_Duty);
PWMB_Duty6(PWMx->PWM6_Duty);
PWMB_Duty7(PWMx->PWM7_Duty);
PWMB_Duty8(PWMx->PWM8_Duty);
PWMB_CCPCBPreloaded(PWMx->PWM_PreLoad); // 捕获/比较预装载控制位(该位只对具有互补输出的通道起作用)
PWMB_PS = PWMx->PWM_PS_SW; // 切换IO
PWMB_ENO = PWMx->PWM_EnoSelect; // 输出通道选择
PWMB_DeadTime(PWMx->PWM_DeadTime); // 死区发生器设置
if (PWMx->PWM_BrakeEnable == ENABLE)
PWMB_BrakeEnable(); // 开启刹车输入
else
PWMB_BrakeDisable(); // 禁止刹车输入
if (PWMx->PWM_MainOutEnable == ENABLE)
PWMB_BrakeOutputEnable(); // 主输出使能
else
PWMB_BrakeOutputDisable(); // 主输出禁止
if (PWMx->PWM_CEN_Enable == ENABLE)
PWMB_CEN_Enable(); // 使能计数器
else
PWMB_CEN_Disable(); // 禁止计数器
EAXRAM(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展RAM(XRAM) */
return 0;
}
return 2; // 错误
}
/*********************************************************/
/******************* PWM 占空比设置函数 *******************/
void UpdatePwm(u8 PWM, PWMx_Duty *PWMx)
{
EAXSFR(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展SFR(XSFR) */
if (PWM == PWMA)
{
PWMA_Duty1(PWMx->PWM1_Duty);
PWMA_Duty2(PWMx->PWM2_Duty);
PWMA_Duty3(PWMx->PWM3_Duty);
PWMA_Duty4(PWMx->PWM4_Duty);
}
else
{
PWMB_Duty5(PWMx->PWM5_Duty);
PWMB_Duty6(PWMx->PWM6_Duty);
PWMB_Duty7(PWMx->PWM7_Duty);
PWMB_Duty8(PWMx->PWM8_Duty);
}
EAXRAM(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展RAM(XRAM) */
}
/*********************************************************/
void PWM_config(void)
{
PWMx_InitDefine PWMx_InitStructure;
PWMx_InitStructure.PWM5_Mode = CCMRn_PWM_MODE1;
PWMx_InitStructure.PWM5_SetPriority = Priority_0;
PWMx_InitStructure.PWM_Period = 1500;
PWMx_InitStructure.PWM5_Duty = PWMB_Duty.PWM5_Duty;
PWMx_InitStructure.PWM_DeadTime = 0;
PWMx_InitStructure.PWM_EnoSelect = ENO5P;
PWMx_InitStructure.PWM_PS_SW = PWM5_SW_P17;
PWMx_InitStructure.PWM_CC5Enable = ENABLE;
PWMx_InitStructure.PWM_MainOutEnable = ENABLE; // ?÷????????, ENABLE,DISABLE
PWMx_InitStructure.PWM_CEN_Enable = ENABLE; // ?????????÷, ENABLE,DISABLE
PWM_Configuration(PWMB, &PWMx_InitStructure); // ??????PWM, PWMA,PWMB
PWMB_Duty.PWM5_Duty = 1500;
}

View File

@ -14,15 +14,17 @@
#include "GPIO.h"
#include "Exti.h"
#include "timer.h"
#include "PWM.h"
/******************** 主函数***********************/
void main(void)
{
GPIO_config();
Exti_config();
Timer_config();
PWM_config();
EA = 1;
while (1)
{
UpdatePwm(PWMB, &PWMB_Duty);
}
}

View File

@ -16,42 +16,58 @@
******************************************/
#include "timer.h"
#include "timer.h"
#include "PWM.h"
#include "GPIO.h"
u8 KILL_time = 0;
u8 pwm_direction = 0;
/********************* Timer0中断函数************************/
void timer0_int (void) interrupt TIMER0_VECTOR
void timer0_int(void) interrupt TIMER0_VECTOR
{
if (KILL_time)
KILL_time--;
if (!power3_gpio)
{
KILL_time--;
if (pwm_direction)
{
PWMB_Duty.PWM5_Duty++;
if (PWMB_Duty.PWM5_Duty >= 1500)
pwm_direction = 0;
}
else
{
PWMB_Duty.PWM5_Duty--;
if (!PWMB_Duty.PWM5_Duty)
pwm_direction = 1;
}
}
else
{
PWMB_Duty.PWM5_Duty = 1500;
}
}
/********************* Timer1中断函数************************/
void timer1_int (void) interrupt TIMER1_VECTOR
void timer1_int(void) interrupt TIMER1_VECTOR
{
}
/********************* Timer2中断函数************************/
void timer2_int (void) interrupt TIMER2_VECTOR
void timer2_int(void) interrupt TIMER2_VECTOR
{
}
/********************* Timer3中断函数************************/
void timer3_int (void) interrupt TIMER3_VECTOR
void timer3_int(void) interrupt TIMER3_VECTOR
{
}
/********************* Timer4中断函数************************/
void timer4_int (void) interrupt TIMER4_VECTOR
void timer4_int(void) interrupt TIMER4_VECTOR
{
}
//========================================================================
// 函数: u8 Timer_Inilize(u8 TIM, TIM_InitTypeDef *TIMx)
// 描述: 定时器初始化程序.
@ -59,118 +75,171 @@ void timer4_int (void) interrupt TIMER4_VECTOR
// 返回: 成功返回0, 空操作返回1,错误返回2.
// 版本: V1.0, 2012-10-22
//========================================================================
u8 Timer_Inilize(u8 TIM, TIM_InitTypeDef *TIMx)
u8 Timer_Inilize(u8 TIM, TIM_InitTypeDef *TIMx)
{
if(TIM > Timer4) return 1; //空操作
if (TIM > Timer4)
return 1; // 空操作
if(TIM == Timer0)
{
Timer0_Stop(); //停止计数
if(TIMx->TIM_Interrupt == ENABLE) Timer0_InterruptEnable(); //允许中断
else Timer0_InterruptDisable(); //禁止中断
if(TIMx->TIM_Priority > Priority_3) return 2; //错误
Timer0_Priority(TIMx->TIM_Priority); //指定中断优先级(低到高) Priority_0,Priority_1,Priority_2,Priority_3
if (TIM == Timer0)
{
Timer0_Stop(); // 停止计数
if (TIMx->TIM_Interrupt == ENABLE)
Timer0_InterruptEnable(); // 允许中断
else
Timer0_InterruptDisable(); // 禁止中断
if (TIMx->TIM_Priority > Priority_3)
return 2; // 错误
Timer0_Priority(TIMx->TIM_Priority); // 指定中断优先级(低到高) Priority_0,Priority_1,Priority_2,Priority_3
if(TIMx->TIM_Mode >= TIM_16BitAutoReloadNoMask) return 2; //错误
TMOD = (TMOD & ~0x03) | TIMx->TIM_Mode; //工作模式,0: 16位自动重装, 1: 16位定时/计数, 2: 8位自动重装, 3: 不可屏蔽16位自动重装
if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer0_12T(); //12T
if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer0_1T(); //1T
if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer0_AsCounter(); //对外计数或分频
else Timer0_AsTimer(); //定时
if(TIMx->TIM_ClkOut == ENABLE) Timer0_CLKO_Enable(); //输出时钟
else Timer0_CLKO_Disable(); //不输出时钟
T0_Load(TIMx->TIM_Value);
if(TIMx->TIM_Run == ENABLE) Timer0_Run(); //开始运行
return 0; //成功
}
if (TIMx->TIM_Mode >= TIM_16BitAutoReloadNoMask)
return 2; // 错误
TMOD = (TMOD & ~0x03) | TIMx->TIM_Mode; // 工作模式,0: 16位自动重装, 1: 16位定时/计数, 2: 8位自动重装, 3: 不可屏蔽16位自动重装
if (TIMx->TIM_ClkSource == TIM_CLOCK_12T)
Timer0_12T(); // 12T
if (TIMx->TIM_ClkSource == TIM_CLOCK_1T)
Timer0_1T(); // 1T
if (TIMx->TIM_ClkSource == TIM_CLOCK_Ext)
Timer0_AsCounter(); // 对外计数或分频
else
Timer0_AsTimer(); // 定时
if (TIMx->TIM_ClkOut == ENABLE)
Timer0_CLKO_Enable(); // 输出时钟
else
Timer0_CLKO_Disable(); // 不输出时钟
if(TIM == Timer1)
{
Timer1_Stop(); //停止计数
if(TIMx->TIM_Interrupt == ENABLE) Timer1_InterruptEnable(); //允许中断
else Timer1_InterruptDisable(); //禁止中断
if(TIMx->TIM_Priority > Priority_3) return 2; //错误
Timer1_Priority(TIMx->TIM_Priority); //指定中断优先级(低到高) Priority_0,Priority_1,Priority_2,Priority_3
if(TIMx->TIM_Mode >= TIM_16BitAutoReloadNoMask) return 2; //错误
TMOD = (TMOD & ~0x30) | (TIMx->TIM_Mode<<4); //工作模式,0: 16位自动重装, 1: 16位定时/计数, 2: 8位自动重装, 3: 停止工作
if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer1_12T(); //12T
if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer1_1T(); //1T
if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer1_AsCounter(); //对外计数或分频
else Timer1_AsTimer(); //定时
if(TIMx->TIM_ClkOut == ENABLE) Timer1_CLKO_Enable(); //输出时钟
else Timer1_CLKO_Disable(); //不输出时钟
T1_Load(TIMx->TIM_Value);
if(TIMx->TIM_Run == ENABLE) Timer1_Run(); //开始运行
return 0; //成功
}
T0_Load(TIMx->TIM_Value);
if (TIMx->TIM_Run == ENABLE)
Timer0_Run(); // 开始运行
return 0; // 成功
}
if(TIM == Timer2) //Timer2,固定为16位自动重装, 中断无优先级
{
Timer2_Stop(); //停止计数
if(TIMx->TIM_Interrupt == ENABLE) Timer2_InterruptEnable(); //允许中断
else Timer2_InterruptDisable(); //禁止中断
if(TIMx->TIM_ClkSource > TIM_CLOCK_Ext) return 2;
if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer2_12T(); //12T
if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer2_1T(); //1T
if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer2_AsCounter(); //对外计数或分频
else Timer2_AsTimer(); //定时
if(TIMx->TIM_ClkOut == ENABLE) Timer2_CLKO_Enable(); //输出时钟
else Timer2_CLKO_Disable(); //不输出时钟
if (TIM == Timer1)
{
Timer1_Stop(); // 停止计数
if (TIMx->TIM_Interrupt == ENABLE)
Timer1_InterruptEnable(); // 允许中断
else
Timer1_InterruptDisable(); // 禁止中断
if (TIMx->TIM_Priority > Priority_3)
return 2; // 错误
Timer1_Priority(TIMx->TIM_Priority); // 指定中断优先级(低到高) Priority_0,Priority_1,Priority_2,Priority_3
if (TIMx->TIM_Mode >= TIM_16BitAutoReloadNoMask)
return 2; // 错误
TMOD = (TMOD & ~0x30) | (TIMx->TIM_Mode << 4); // 工作模式,0: 16位自动重装, 1: 16位定时/计数, 2: 8位自动重装, 3: 停止工作
if (TIMx->TIM_ClkSource == TIM_CLOCK_12T)
Timer1_12T(); // 12T
if (TIMx->TIM_ClkSource == TIM_CLOCK_1T)
Timer1_1T(); // 1T
if (TIMx->TIM_ClkSource == TIM_CLOCK_Ext)
Timer1_AsCounter(); // 对外计数或分频
else
Timer1_AsTimer(); // 定时
if (TIMx->TIM_ClkOut == ENABLE)
Timer1_CLKO_Enable(); // 输出时钟
else
Timer1_CLKO_Disable(); // 不输出时钟
T2_Load(TIMx->TIM_Value);
if(TIMx->TIM_Run == ENABLE) Timer2_Run(); //开始运行
return 0; //成功
}
T1_Load(TIMx->TIM_Value);
if (TIMx->TIM_Run == ENABLE)
Timer1_Run(); // 开始运行
return 0; // 成功
}
if(TIM == Timer3) //Timer3,固定为16位自动重装, 中断无优先级
{
Timer3_Stop(); //停止计数
if(TIMx->TIM_Interrupt == ENABLE) Timer3_InterruptEnable(); //允许中断
else Timer3_InterruptDisable(); //禁止中断
if(TIMx->TIM_ClkSource > TIM_CLOCK_Ext) return 2;
if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer3_12T(); //12T
if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer3_1T(); //1T
if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer3_AsCounter(); //对外计数或分频
else Timer3_AsTimer(); //定时
if(TIMx->TIM_ClkOut == ENABLE) Timer3_CLKO_Enable(); //输出时钟
else Timer3_CLKO_Disable(); //不输出时钟
if (TIM == Timer2) // Timer2,固定为16位自动重装, 中断无优先级
{
Timer2_Stop(); // 停止计数
if (TIMx->TIM_Interrupt == ENABLE)
Timer2_InterruptEnable(); // 允许中断
else
Timer2_InterruptDisable(); // 禁止中断
if (TIMx->TIM_ClkSource > TIM_CLOCK_Ext)
return 2;
if (TIMx->TIM_ClkSource == TIM_CLOCK_12T)
Timer2_12T(); // 12T
if (TIMx->TIM_ClkSource == TIM_CLOCK_1T)
Timer2_1T(); // 1T
if (TIMx->TIM_ClkSource == TIM_CLOCK_Ext)
Timer2_AsCounter(); // 对外计数或分频
else
Timer2_AsTimer(); // 定时
if (TIMx->TIM_ClkOut == ENABLE)
Timer2_CLKO_Enable(); // 输出时钟
else
Timer2_CLKO_Disable(); // 不输出时钟
T3_Load(TIMx->TIM_Value);
if(TIMx->TIM_Run == ENABLE) Timer3_Run(); //开始运行
return 0; //成功
}
T2_Load(TIMx->TIM_Value);
if (TIMx->TIM_Run == ENABLE)
Timer2_Run(); // 开始运行
return 0; // 成功
}
if(TIM == Timer4) //Timer3,固定为16位自动重装, 中断无优先级
{
Timer4_Stop(); //停止计数
if(TIMx->TIM_Interrupt == ENABLE) Timer4_InterruptEnable(); //允许中断
else Timer4_InterruptDisable(); //禁止中断
if(TIMx->TIM_ClkSource > TIM_CLOCK_Ext) return 2;
if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer4_12T(); //12T
if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer4_1T(); //1T
if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer4_AsCounter(); //对外计数或分频
else Timer4_AsTimer(); //定时
if(TIMx->TIM_ClkOut == ENABLE) Timer4_CLKO_Enable(); //输出时钟
else Timer4_CLKO_Disable(); //不输出时钟
if (TIM == Timer3) // Timer3,固定为16位自动重装, 中断无优先级
{
Timer3_Stop(); // 停止计数
if (TIMx->TIM_Interrupt == ENABLE)
Timer3_InterruptEnable(); // 允许中断
else
Timer3_InterruptDisable(); // 禁止中断
if (TIMx->TIM_ClkSource > TIM_CLOCK_Ext)
return 2;
if (TIMx->TIM_ClkSource == TIM_CLOCK_12T)
Timer3_12T(); // 12T
if (TIMx->TIM_ClkSource == TIM_CLOCK_1T)
Timer3_1T(); // 1T
if (TIMx->TIM_ClkSource == TIM_CLOCK_Ext)
Timer3_AsCounter(); // 对外计数或分频
else
Timer3_AsTimer(); // 定时
if (TIMx->TIM_ClkOut == ENABLE)
Timer3_CLKO_Enable(); // 输出时钟
else
Timer3_CLKO_Disable(); // 不输出时钟
T4_Load(TIMx->TIM_Value);
if(TIMx->TIM_Run == ENABLE) Timer4_Run(); //开始运行
return 0; //成功
}
return 2; //错误
T3_Load(TIMx->TIM_Value);
if (TIMx->TIM_Run == ENABLE)
Timer3_Run(); // 开始运行
return 0; // 成功
}
if (TIM == Timer4) // Timer3,固定为16位自动重装, 中断无优先级
{
Timer4_Stop(); // 停止计数
if (TIMx->TIM_Interrupt == ENABLE)
Timer4_InterruptEnable(); // 允许中断
else
Timer4_InterruptDisable(); // 禁止中断
if (TIMx->TIM_ClkSource > TIM_CLOCK_Ext)
return 2;
if (TIMx->TIM_ClkSource == TIM_CLOCK_12T)
Timer4_12T(); // 12T
if (TIMx->TIM_ClkSource == TIM_CLOCK_1T)
Timer4_1T(); // 1T
if (TIMx->TIM_ClkSource == TIM_CLOCK_Ext)
Timer4_AsCounter(); // 对外计数或分频
else
Timer4_AsTimer(); // 定时
if (TIMx->TIM_ClkOut == ENABLE)
Timer4_CLKO_Enable(); // 输出时钟
else
Timer4_CLKO_Disable(); // 不输出时钟
T4_Load(TIMx->TIM_Value);
if (TIMx->TIM_Run == ENABLE)
Timer4_Run(); // 开始运行
return 0; // 成功
}
return 2; // 错误
}
/************************ ?¨?±?÷???? ****************************/
void Timer_config(void)
void Timer_config(void)
{
TIM_InitTypeDef TIM_InitStructure;
TIM_InitStructure.TIM_Mode = TIM_16BitAutoReload;
TIM_InitStructure.TIM_Priority = Priority_0;
TIM_InitStructure.TIM_Interrupt = ENABLE;
TIM_InitStructure.TIM_ClkSource = TIM_CLOCK_1T;
TIM_InitStructure.TIM_ClkOut = DISABLE;
TIM_InitStructure.TIM_Value = 65536UL - (MAIN_Fosc / 1000UL);
TIM_InitStructure.TIM_Run = ENABLE;
Timer_Inilize(Timer0,&TIM_InitStructure);
TIM_InitTypeDef TIM_InitStructure;
TIM_InitStructure.TIM_Mode = TIM_16BitAutoReload;
TIM_InitStructure.TIM_Priority = Priority_0;
TIM_InitStructure.TIM_Interrupt = ENABLE;
TIM_InitStructure.TIM_ClkSource = TIM_CLOCK_1T;
TIM_InitStructure.TIM_ClkOut = DISABLE;
TIM_InitStructure.TIM_Value = 65536UL - (MAIN_Fosc / 1000UL);
TIM_InitStructure.TIM_Run = ENABLE;
Timer_Inilize(Timer0, &TIM_InitStructure);
}

View File

@ -42,6 +42,7 @@
#define power1_gpio P10
#define power2_gpio P11
#define power3_gpio P12
#define led P17
typedef struct
{
u8 Mode; //IOģʽ, GPIO_PullUp,GPIO_HighZ,GPIO_OUT_OD,GPIO_OUT_PP

140
myinc/PWM.h Normal file
View File

@ -0,0 +1,140 @@
/*---------------------------------------------------------------------*/
/* --- STC MCU Limited ------------------------------------------------*/
/* --- STC 1T Series MCU Demo Programme -------------------------------*/
/* --- Mobile: (86)13922805190 ----------------------------------------*/
/* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/
/* --- Tel: 86-0513-55012928,55012929,55012966 ------------------------*/
/* --- Web: www.STCMCU.com --------------------------------------------*/
/* --- Web: www.STCMCUDATA.com ---------------------------------------*/
/* --- QQ: 800003751 -------------------------------------------------*/
/* <20><><EFBFBD>Ҫ<EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ô˴<C3B4><CBB4><EFBFBD>,<2C><><EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>STC<54><43><EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD><EFBFBD><EFBFBD> */
/*---------------------------------------------------------------------*/
#ifndef __PWM_H
#define __PWM_H
#include "config.h"
#define ENO1P 0x01
#define ENO1N 0x02
#define ENO2P 0x04
#define ENO2N 0x08
#define ENO3P 0x10
#define ENO3N 0x20
#define ENO4P 0x40
#define ENO4N 0x80
#define ENO5P 0x01
#define ENO6P 0x04
#define ENO7P 0x10
#define ENO8P 0x40
#define PWMA 1
#define PWMB 2
#define PWM1_SW_P10_P11 0
#define PWM1_SW_P20_P21 1
#define PWM1_SW_P60_P61 2
#define PWM2_SW_P12_P13 0
#define PWM2_SW_P22_P23 (1 << 2)
#define PWM2_SW_P62_P63 (2 << 2)
#define PWM3_SW_P14_P15 0
#define PWM3_SW_P24_P25 (1 << 4)
#define PWM3_SW_P64_P65 (2 << 4)
#define PWM4_SW_P16_P17 0
#define PWM4_SW_P26_P27 (1 << 6)
#define PWM4_SW_P66_P67 (2 << 6)
#define PWM4_SW_P34_P33 (3 << 6)
#define PWM5_SW_P20 0
#define PWM5_SW_P17 1
#define PWM5_SW_P00 2
#define PWM5_SW_P74 3
#define PWM6_SW_P21 0
#define PWM6_SW_P54 (1 << 2)
#define PWM6_SW_P01 (2 << 2)
#define PWM6_SW_P75 (3 << 2)
#define PWM7_SW_P22 0
#define PWM7_SW_P33 (1 << 4)
#define PWM7_SW_P02 (2 << 4)
#define PWM7_SW_P76 (3 << 4)
#define PWM8_SW_P23 0
#define PWM8_SW_P34 (1 << 6)
#define PWM8_SW_P03 (2 << 6)
#define PWM8_SW_P77 (3 << 6)
typedef struct
{
u8 PWM1_Mode; // ģʽ, CCMRn_FREEZE,CCMRn_MATCH_VALID,CCMRn_MATCH_INVALID,CCMRn_ROLLOVER,CCMRn_FORCE_INVALID,CCMRn_FORCE_VALID,CCMRn_PWM_MODE1,CCMRn_PWM_MODE2
u8 PWM2_Mode; // ģʽ, CCMRn_FREEZE,CCMRn_MATCH_VALID,CCMRn_MATCH_INVALID,CCMRn_ROLLOVER,CCMRn_FORCE_INVALID,CCMRn_FORCE_VALID,CCMRn_PWM_MODE1,CCMRn_PWM_MODE2
u8 PWM3_Mode; // ģʽ, CCMRn_FREEZE,CCMRn_MATCH_VALID,CCMRn_MATCH_INVALID,CCMRn_ROLLOVER,CCMRn_FORCE_INVALID,CCMRn_FORCE_VALID,CCMRn_PWM_MODE1,CCMRn_PWM_MODE2
u8 PWM4_Mode; // ģʽ, CCMRn_FREEZE,CCMRn_MATCH_VALID,CCMRn_MATCH_INVALID,CCMRn_ROLLOVER,CCMRn_FORCE_INVALID,CCMRn_FORCE_VALID,CCMRn_PWM_MODE1,CCMRn_PWM_MODE2
u8 PWM5_Mode; // ģʽ, CCMRn_FREEZE,CCMRn_MATCH_VALID,CCMRn_MATCH_INVALID,CCMRn_ROLLOVER,CCMRn_FORCE_INVALID,CCMRn_FORCE_VALID,CCMRn_PWM_MODE1,CCMRn_PWM_MODE2
u8 PWM6_Mode; // ģʽ, CCMRn_FREEZE,CCMRn_MATCH_VALID,CCMRn_MATCH_INVALID,CCMRn_ROLLOVER,CCMRn_FORCE_INVALID,CCMRn_FORCE_VALID,CCMRn_PWM_MODE1,CCMRn_PWM_MODE2
u8 PWM7_Mode; // ģʽ, CCMRn_FREEZE,CCMRn_MATCH_VALID,CCMRn_MATCH_INVALID,CCMRn_ROLLOVER,CCMRn_FORCE_INVALID,CCMRn_FORCE_VALID,CCMRn_PWM_MODE1,CCMRn_PWM_MODE2
u8 PWM8_Mode; // ģʽ, CCMRn_FREEZE,CCMRn_MATCH_VALID,CCMRn_MATCH_INVALID,CCMRn_ROLLOVER,CCMRn_FORCE_INVALID,CCMRn_FORCE_VALID,CCMRn_PWM_MODE1,CCMRn_PWM_MODE2
u16 PWM_Period; // <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>, 0~65535
u16 PWM1_Duty; // PWM1ռ<31>ձ<EFBFBD>ʱ<EFBFBD><CAB1>, 0~Period
u16 PWM2_Duty; // PWM2ռ<32>ձ<EFBFBD>ʱ<EFBFBD><CAB1>, 0~Period
u16 PWM3_Duty; // PWM3ռ<33>ձ<EFBFBD>ʱ<EFBFBD><CAB1>, 0~Period
u16 PWM4_Duty; // PWM4ռ<34>ձ<EFBFBD>ʱ<EFBFBD><CAB1>, 0~Period
u16 PWM5_Duty; // PWM5ռ<35>ձ<EFBFBD>ʱ<EFBFBD><CAB1>, 0~Period
u16 PWM6_Duty; // PWM6ռ<36>ձ<EFBFBD>ʱ<EFBFBD><CAB1>, 0~Period
u16 PWM7_Duty; // PWM7ռ<37>ձ<EFBFBD>ʱ<EFBFBD><CAB1>, 0~Period
u16 PWM8_Duty; // PWM8ռ<38>ձ<EFBFBD>ʱ<EFBFBD><CAB1>, 0~Period
u8 PWM_DeadTime; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 0~255
u8 PWM_CC1Enable; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB2B6>/<2F>Ƚ<EFBFBD><C8BD><EFBFBD><EFBFBD>, ENABLE,DISABLE
u8 PWM_CC1NEnable; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB2B6>/<2F>Ƚ<EFBFBD><C8BD><EFBFBD><EFBFBD>, ENABLE,DISABLE
u8 PWM_CC2Enable; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB2B6>/<2F>Ƚ<EFBFBD><C8BD><EFBFBD><EFBFBD>, ENABLE,DISABLE
u8 PWM_CC2NEnable; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB2B6>/<2F>Ƚ<EFBFBD><C8BD><EFBFBD><EFBFBD>, ENABLE,DISABLE
u8 PWM_CC3Enable; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB2B6>/<2F>Ƚ<EFBFBD><C8BD><EFBFBD><EFBFBD>, ENABLE,DISABLE
u8 PWM_CC3NEnable; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB2B6>/<2F>Ƚ<EFBFBD><C8BD><EFBFBD><EFBFBD>, ENABLE,DISABLE
u8 PWM_CC4Enable; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB2B6>/<2F>Ƚ<EFBFBD><C8BD><EFBFBD><EFBFBD>, ENABLE,DISABLE
u8 PWM_CC4NEnable; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB2B6>/<2F>Ƚ<EFBFBD><C8BD><EFBFBD><EFBFBD>, ENABLE,DISABLE
u8 PWM_CC5Enable; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB2B6>/<2F>Ƚ<EFBFBD><C8BD><EFBFBD><EFBFBD>, ENABLE,DISABLE
u8 PWM_CC6Enable; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB2B6>/<2F>Ƚ<EFBFBD><C8BD><EFBFBD><EFBFBD>, ENABLE,DISABLE
u8 PWM_CC7Enable; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB2B6>/<2F>Ƚ<EFBFBD><C8BD><EFBFBD><EFBFBD>, ENABLE,DISABLE
u8 PWM_CC8Enable; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB2B6>/<2F>Ƚ<EFBFBD><C8BD><EFBFBD><EFBFBD>, ENABLE,DISABLE
u8 PWM_Reload; // <20><><EFBFBD><EFBFBD>Ƚϵ<C8BD>Ԥװ<D4A4><D7B0>ʹ<EFBFBD><CAB9>, ENABLE,DISABLE
u8 PWM_Fast; // <20><><EFBFBD><EFBFBD>ȽϿ<C8BD><CFBF>ٹ<EFBFBD><D9B9><EFBFBD>ʹ<EFBFBD><CAB9>, ENABLE,DISABLE
u8 PWM1_SetPriority; // <20><><EFBFBD><EFBFBD>PWM1<4D><31><EFBFBD>ȼ<EFBFBD>, Priority_0,Priority_1,Priority_2,Priority_3
u8 PWM2_SetPriority; // <20><><EFBFBD><EFBFBD>PWM2<4D><32><EFBFBD>ȼ<EFBFBD>, Priority_0,Priority_1,Priority_2,Priority_3
u8 PWM3_SetPriority; // <20><><EFBFBD><EFBFBD>PWM3<4D><33><EFBFBD>ȼ<EFBFBD>, Priority_0,Priority_1,Priority_2,Priority_3
u8 PWM4_SetPriority; // <20><><EFBFBD><EFBFBD>PWM4<4D><34><EFBFBD>ȼ<EFBFBD>, Priority_0,Priority_1,Priority_2,Priority_3
u8 PWM5_SetPriority; // <20><><EFBFBD><EFBFBD>PWM4<4D><34><EFBFBD>ȼ<EFBFBD>, Priority_0,Priority_1,Priority_2,Priority_3
u8 PWM_EnoSelect; // <20><><EFBFBD>ͨ<EFBFBD><CDA8>ѡ<EFBFBD><D1A1>, ENO1P,ENO1N,ENO2P,ENO2N,ENO3P,ENO3N,ENO4P,ENO4N / ENO5P,ENO6P,ENO7P,ENO8P
u8 PWM_PreLoad; // Ԥװ<D4A4><D7B0>, ENABLE,DISABLE
u8 PWM_PS_SW; // <20>л<EFBFBD><D0BB>˿<EFBFBD>, PWM1_SW_P10_P11,PWM1_SW_P20_P21,PWM1_SW_P60_P61
u8 PWM_CEN_Enable; // ʹ<>ܼ<EFBFBD><DCBC><EFBFBD><EFBFBD><EFBFBD>, ENABLE,DISABLE
u8 PWM_BrakeEnable; // ɲ<><C9B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, ENABLE,DISABLE
u8 PWM_MainOutEnable; // <20><><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, ENABLE,DISABLE
} PWMx_InitDefine;
typedef struct
{
u16 PWM1_Duty; // PWM1ռ<31>ձ<EFBFBD>ʱ<EFBFBD><CAB1>, 0~Period
u16 PWM2_Duty; // PWM2ռ<32>ձ<EFBFBD>ʱ<EFBFBD><CAB1>, 0~Period
u16 PWM3_Duty; // PWM3ռ<33>ձ<EFBFBD>ʱ<EFBFBD><CAB1>, 0~Period
u16 PWM4_Duty; // PWM4ռ<34>ձ<EFBFBD>ʱ<EFBFBD><CAB1>, 0~Period
u16 PWM5_Duty; // PWM5ռ<35>ձ<EFBFBD>ʱ<EFBFBD><CAB1>, 0~Period
u16 PWM6_Duty; // PWM6ռ<36>ձ<EFBFBD>ʱ<EFBFBD><CAB1>, 0~Period
u16 PWM7_Duty; // PWM7ռ<37>ձ<EFBFBD>ʱ<EFBFBD><CAB1>, 0~Period
u16 PWM8_Duty; // PWM8ռ<38>ձ<EFBFBD>ʱ<EFBFBD><CAB1>, 0~Period
} PWMx_Duty;
extern PWMx_Duty PWMB_Duty;
u8 PWM_Configuration(u8 PWM, PWMx_InitDefine *PWMx);
void UpdatePwm(u8 PWM, PWMx_Duty *PWMx);
void PWM_config(void);
#endif