8051-ELL库  beta 1.1.6
8051-ELL library API Document Center
STC8x_PWM.h
浏览该文件的文档.
1 /*-----------------------------------------------------------------------
2 | FILE DESCRIPTION |
3 -----------------------------------------------------------------------*/
4 /*----------------------------------------------------------------------
5  - File name : STC8Ax_PWM.h
6  - Author : zeweni
7  - Update date : 2020.05.06
8  - Copyright(C) : 2020-2021 zeweni. All rights reserved.
9 -----------------------------------------------------------------------*/
10 /*------------------------------------------------------------------------
11 | COPYRIGHT NOTICE |
12 ------------------------------------------------------------------------*/
13 /*
14  * Copyright (C) 2021, zeweni (17870070675@163.com)
15 
16  * This file is part of 8051 ELL low-layer libraries.
17 
18  * 8051 ELL low-layer libraries is free software: you can redistribute
19  * it and/or modify it under the terms of the Apache-2.0 License.
20 
21  * 8051 ELL low-layer libraries is distributed in the hope that it will
22  * be useful,but WITHOUT ANY WARRANTY; without even the implied warranty
23  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * Apache-2.0 License License for more details.
25 
26  * You should have received a copy of the Apache-2.0 License.8051 ELL
27  * low-layer libraries. If not, see <http://www.apache.org/licenses/>.
28 **/
29 /*-----------------------------------------------------------------------
30 | INCLUDES |
31 -----------------------------------------------------------------------*/
32 #ifndef __STC8x_PWM_H_
33 #define __STC8x_PWM_H_
34 
35 /*--------------------------------------------------------
36 | @Description: STC8x core |
37 --------------------------------------------------------*/
38 #include "ELL_CORE.h"
39 
40 /*--------------------------------------------------------
41 | @Description: STC8x MCU Register |
42 --------------------------------------------------------*/
43 
44 #if (PER_LIB_MCU_MUODEL == STC8Ax)
45 
46  #include "STC8Ax_REG.h"
47 
48 #endif
49 
50 /*-----------------------------------------------------------------------
51 | DATA |
52 -----------------------------------------------------------------------*/
53 
54 #ifndef PER_LIB_MCU_MUODEL
57  #define PER_LIB_MCU_MUODEL STC8Ax
58 #endif
59 
60 
61 #ifndef PER_LIB_PWM_CTRL
64  #define PER_LIB_PWM_CTRL 1
65 #endif
66 
67 
68 #ifndef PER_LIB_PWM_INIT_CTRL
71  #define PER_LIB_PWM_INIT_CTRL 1
72 #endif
73 
74 
75 #ifndef PER_LIB_PWM_NVIC_CTRL
78  #define PER_LIB_PWM_NVIC_CTRL 1
79 #endif
80 
81 
82 #ifndef PER_LIB_PWM_WORK_CTRL
85  #define PER_LIB_PWM_WORK_CTRL 1
86 #endif
87 
88 
89 
90 /*--------------------------------------------------------
91 | @Description: PWM clock source enum |
92 --------------------------------------------------------*/
93 
98 typedef enum
99 {
116  PWM_TIMER2_PULSE = 0x1F
118 
119 /*--------------------------------------------------------
120 | @Description: PWM road start level configure enum |
121 --------------------------------------------------------*/
122 
123 typedef enum
124 {
126  PWM_Start_High_Level = 0x01
128 
129 /*--------------------------------------------------------
130 | @Description: PWM Abnormal detection selection enum |
131 --------------------------------------------------------*/
132 
133 typedef enum
134 {
135  PWM_ABD_P35 = 0x02,
136  PWM_ABD_COMP = 0x04
138 
139 /*--------------------------------------------------------
140 | @Description: PWM Abnormal signal processing enum |
141 --------------------------------------------------------*/
142 
143 typedef enum
144 {
148  PWM_P35_High_To_Low = 0x40
150 
151 /*--------------------------------------------------------
152 | @Description: PWM level hold configure enum |
153 --------------------------------------------------------*/
154 
155 typedef enum
156 {
161 
162 /*--------------------------------------------------------
163 | @Description: PWM road interrupt flip enum |
164 --------------------------------------------------------*/
165 
166 typedef enum
167 {
168  PWM_Flip_Null = 0x00 ,
169  PWM_Flip_First = 0x05 ,
171  PWM_Flip_Both = 0x07
173 
174 
175 /*-----------------------------------------------------------------------
176 | API FUNCTION |
177 -----------------------------------------------------------------------*/
178 
179  #if (PER_LIB_MCU_MUODEL == STC8Ax)
180 
181 
182 
183 
184  FSCSTATE PWM_CNT_Init(PWMCLKSrc_Type clkSrc,uint16_t period,BOOL run);
185 
186 
187 
188  FSCSTATE PWM0_Init(PWMStartLevel_Type level,uint16_t fValue,uint16_t sValue,BOOL run);
189  FSCSTATE PWM1_Init(PWMStartLevel_Type level,uint16_t fValue,uint16_t sValue,BOOL run);
190  FSCSTATE PWM2_Init(PWMStartLevel_Type level,uint16_t fValue,uint16_t sValue,BOOL run);
191  FSCSTATE PWM3_Init(PWMStartLevel_Type level,uint16_t fValue,uint16_t sValue,BOOL run);
192  FSCSTATE PWM4_Init(PWMStartLevel_Type level,uint16_t fValue,uint16_t sValue,BOOL run);
193  FSCSTATE PWM5_Init(PWMStartLevel_Type level,uint16_t fValue,uint16_t sValue,BOOL run);
194  FSCSTATE PWM6_Init(PWMStartLevel_Type level,uint16_t fValue,uint16_t sValue,BOOL run);
195  FSCSTATE PWM7_Init(PWMStartLevel_Type level,uint16_t fValue,uint16_t sValue,BOOL run);
196 
197 
198 
200 
201 
202 
203  FSCSTATE PWM_ETADC_Init(uint16_t tValue,BOOL run);
204 
205  #define PWM_CNT_RTZ_GET_FLAG() (PWMCFG & 0x80)
206  #define PWM_ABD_GET_FLAG() (PWMFDCR & 0x01)
207 
208  #define PWM0_GET_FLAG() (PWMIF & 0x01)
209  #define PWM1_GET_FLAG() (PWMIF & 0x02)
210  #define PWM2_GET_FLAG() (PWMIF & 0x04)
211  #define PWM3_GET_FLAG() (PWMIF & 0x08)
212  #define PWM4_GET_FLAG() (PWMIF & 0x10)
213  #define PWM5_GET_FLAG() (PWMIF & 0x20)
214  #define PWM6_GET_FLAG() (PWMIF & 0x40)
215  #define PWM7_GET_FLAG() (PWMIF & 0x80)
216 
217  #define PWM_CNT_RTZ_CLEAR_FLAG() PWMCFG &= 0x7F
218  #define PWM_ABD_CLEAR_FLAG() PWMFDCR &= 0xFE
219 
220  #define PWM0_CLEAR_FLAG() PWMIF &= 0xFE
221  #define PWM1_CLEAR_FLAG() PWMIF &= 0xFD
222  #define PWM2_CLEAR_FLAG() PWMIF &= 0xFB
223  #define PWM3_CLEAR_FLAG() PWMIF &= 0xF7
224  #define PWM4_CLEAR_FLAG() PWMIF &= 0xEF
225  #define PWM5_CLEAR_FLAG() PWMIF &= 0xDF
226  #define PWM6_CLEAR_FLAG() PWMIF &= 0xBF
227  #define PWM7_CLEAR_FLAG() PWMIF &= 0x7F
228 
231 
232 
245 
246 
259 
260 
273 
274 
287 
288 
301 
302 
315 
316 
329 
330 
343 
344 
345  #define NVIC_PWM_CNT_PRI(pri) \
346  do{ \
347  IP2H = (IP2H & 0xFB) | ((pri & 0x02) << 1); \
348  IP2 = (IP2 & 0xFB) | ((pri & 0x01) << 2); \
349  }while(0)
350 
351 
352  #define NVIC_PWM_ABD_PRI(pri) \
353  do{ \
354  IP2H = (IP2H & 0xF7) | ((pri & 0x02) << 2); \
355  IP2 = (IP2 & 0xF7) | ((pri & 0x01) << 3); \
356  }while(0)
357 
358  #define NVIC_PWM_CNT_CTRL(run) do{ PWMCR = (PWMCR & 0xBF) | (run << 6); }while(0)
359  #define NVIC_PWM_ABD_CTRL(run) do{ PWMFDCR = (PWMFDCR & 0xF7) | (run << 3); }while(0)
360  #define NVIC_PWM0_CTRL(run) do{ EAXFR_ENABLE(); PWMxCR(PWM0CR_ADDRESS) = (PWMxCR(PWM0CR_ADDRESS) & 0xF8) | (run); EAXFR_DISABLE(); }while(0)
361  #define NVIC_PWM1_CTRL(run) do{ EAXFR_ENABLE(); PWMxCR(PWM1CR_ADDRESS) = (PWMxCR(PWM1CR_ADDRESS) & 0xF8) | (run); EAXFR_DISABLE(); }while(0)
362  #define NVIC_PWM2_CTRL(run) do{ EAXFR_ENABLE(); PWMxCR(PWM2CR_ADDRESS) = (PWMxCR(PWM2CR_ADDRESS) & 0xF8) | (run); EAXFR_DISABLE(); }while(0)
363  #define NVIC_PWM3_CTRL(run) do{ EAXFR_ENABLE(); PWMxCR(PWM3CR_ADDRESS) = (PWMxCR(PWM3CR_ADDRESS) & 0xF8) | (run); EAXFR_DISABLE(); }while(0)
364  #define NVIC_PWM4_CTRL(run) do{ EAXFR_ENABLE(); PWMxCR(PWM4CR_ADDRESS) = (PWMxCR(PWM4CR_ADDRESS) & 0xF8) | (run); EAXFR_DISABLE(); }while(0)
365  #define NVIC_PWM5_CTRL(run) do{ EAXFR_ENABLE(); PWMxCR(PWM5CR_ADDRESS) = (PWMxCR(PWM5CR_ADDRESS) & 0xF8) | (run); EAXFR_DISABLE(); }while(0)
366  #define NVIC_PWM6_CTRL(run) do{ EAXFR_ENABLE(); PWMxCR(PWM6CR_ADDRESS) = (PWMxCR(PWM6CR_ADDRESS) & 0xF8) | (run); EAXFR_DISABLE(); }while(0)
367  #define NVIC_PWM6_CTRL(run) do{ EAXFR_ENABLE(); PWMxCR(PWM6CR_ADDRESS) = (PWMxCR(PWM6CR_ADDRESS) & 0xF8) | (run); EAXFR_DISABLE(); }while(0)
368  #define NVIC_PWM7_CTRL(run) do{ EAXFR_ENABLE(); PWMxCR(PWM7CR_ADDRESS) = (PWMxCR(PWM7CR_ADDRESS) & 0xF8) | (run); EAXFR_DISABLE(); }while(0)
369 
370 
371 
372  #define PWM0_DUTY_CTRL(fValue,sValue) do{PWMxT1(PWM0T1_ADDRESS) = fValue; PWMxT2(PWM0T2_ADDRESS) = sValue;}while(0)
373  #define PWM1_DUTY_CTRL(fValue,sValue) do{PWMxT1(PWM1T1_ADDRESS) = fValue; PWMxT2(PWM1T2_ADDRESS) = sValue;}while(0)
374  #define PWM2_DUTY_CTRL(fValue,sValue) do{PWMxT1(PWM2T1_ADDRESS) = fValue; PWMxT2(PWM2T2_ADDRESS) = sValue;}while(0)
375  #define PWM3_DUTY_CTRL(fValue,sValue) do{PWMxT1(PWM3T1_ADDRESS) = fValue; PWMxT2(PWM3T2_ADDRESS) = sValue;}while(0)
376  #define PWM4_DUTY_CTRL(fValue,sValue) do{PWMxT1(PWM4T1_ADDRESS) = fValue; PWMxT2(PWM4T2_ADDRESS) = sValue;}while(0)
377  #define PWM5_DUTY_CTRL(fValue,sValue) do{PWMxT1(PWM5T1_ADDRESS) = fValue; PWMxT2(PWM5T2_ADDRESS) = sValue;}while(0)
378  #define PWM6_DUTY_CTRL(fValue,sValue) do{PWMxT1(PWM6T1_ADDRESS) = fValue; PWMxT2(PWM6T2_ADDRESS) = sValue;}while(0)
379  #define PWM7_DUTY_CTRL(fValue,sValue) do{PWMxT1(PWM7T1_ADDRESS) = fValue; PWMxT2(PWM7T2_ADDRESS) = sValue;}while(0)
380 
381 
390 
391 
400 
401 
410 
411 
420 
421 
430 
431 
440 
441 
450 
451 
460 
461  #endif
462 
463 
464 /*-----------------------------------------------------------------------
465 | END OF FLIE. (C) COPYRIGHT zeweni |
466 -----------------------------------------------------------------------*/
467 #endif
NVICPri_Type
Definition: ELL_CORE.h:99
BOOL
Definition: ELL_CORE.h:50
FSCSTATE
Definition: ELL_CORE.h:65
GPIOSWPort_Type
Definition: ELL_CORE.h:81
unsigned int uint16_t
Definition: ELL_TYPE.h:73
FSCSTATE PWM4_Init(PWMStartLevel_Type level, uint16_t fValue, uint16_t sValue, BOOL run)
PWM4通道初始化函数,它必须在PWM计数器初始化函数之前调用。
Definition: STC8x_PWM.c:184
FSCSTATE GPIO_PWM1_SWPort(GPIOSWPort_Type port)
PWM1切换复用IO函数。
Definition: STC8x_PWM.c:537
PWMABDSignal_Type
Definition: STC8x_PWM.h:134
@ PWM_ABD_P35
Definition: STC8x_PWM.h:135
@ PWM_ABD_COMP
Definition: STC8x_PWM.h:136
FSCSTATE NVIC_PWM6_Init(PWMFlip_Type flipPoint)
PWM6中断初始化函数,设置触发中断的电平翻转点。
Definition: STC8x_PWM.c:480
FSCSTATE PWM_ETADC_Init(uint16_t tValue, BOOL run)
PWM触发ADC函数。
Definition: STC8x_PWM.c:302
FSCSTATE GPIO_PWM0_SWPort(GPIOSWPort_Type port)
PWM0切换复用IO函数。
Definition: STC8x_PWM.c:516
PWMFlip_Type
Definition: STC8x_PWM.h:167
@ PWM_Flip_Null
Definition: STC8x_PWM.h:168
@ PWM_Flip_First
Definition: STC8x_PWM.h:169
@ PWM_Flip_Second
Definition: STC8x_PWM.h:170
@ PWM_Flip_Both
Definition: STC8x_PWM.h:171
FSCSTATE PWM7_Init(PWMStartLevel_Type level, uint16_t fValue, uint16_t sValue, BOOL run)
PWM7通道初始化函数,它必须在PWM计数器初始化函数之前调用。
Definition: STC8x_PWM.c:259
FSCSTATE PWM2_Init(PWMStartLevel_Type level, uint16_t fValue, uint16_t sValue, BOOL run)
PWM2通道初始化函数,它必须在PWM计数器初始化函数之前调用。
Definition: STC8x_PWM.c:134
FSCSTATE NVIC_PWM7_Init(PWMFlip_Type flipPoint)
PWM7中断初始化函数,设置触发中断的电平翻转点。
Definition: STC8x_PWM.c:500
FSCSTATE NVIC_PWM_CNT_Init(NVICPri_Type pri, BOOL run)
PWM计数器中断初始化函数。
Definition: STC8x_PWM.c:323
FSCSTATE NVIC_PWM_ABD_Init(NVICPri_Type pri, BOOL run)
PWM异常检测中断初始化函数。
Definition: STC8x_PWM.c:339
PWMCLKSrc_Type
RST复位方式选择枚举体。
Definition: STC8x_PWM.h:99
@ PWM_SCLK_DIV_11
Definition: STC8x_PWM.h:110
@ PWM_SCLK_DIV_9
Definition: STC8x_PWM.h:108
@ PWM_SCLK_DIV_8
Definition: STC8x_PWM.h:107
@ PWM_SCLK_DIV_6
Definition: STC8x_PWM.h:105
@ PWM_SCLK_DIV_5
Definition: STC8x_PWM.h:104
@ PWM_SCLK_DIV_7
Definition: STC8x_PWM.h:106
@ PWM_SCLK_DIV_10
Definition: STC8x_PWM.h:109
@ PWM_SCLK_DIV_3
Definition: STC8x_PWM.h:102
@ PWM_SCLK_DIV_1
Definition: STC8x_PWM.h:100
@ PWM_SCLK_DIV_16
Definition: STC8x_PWM.h:115
@ PWM_SCLK_DIV_13
Definition: STC8x_PWM.h:112
@ PWM_SCLK_DIV_2
Definition: STC8x_PWM.h:101
@ PWM_SCLK_DIV_15
Definition: STC8x_PWM.h:114
@ PWM_TIMER2_PULSE
Definition: STC8x_PWM.h:116
@ PWM_SCLK_DIV_14
Definition: STC8x_PWM.h:113
@ PWM_SCLK_DIV_4
Definition: STC8x_PWM.h:103
@ PWM_SCLK_DIV_12
Definition: STC8x_PWM.h:111
FSCSTATE NVIC_PWM5_Init(PWMFlip_Type flipPoint)
PWM5中断初始化函数,设置触发中断的电平翻转点。
Definition: STC8x_PWM.c:460
FSCSTATE PWM5_Init(PWMStartLevel_Type level, uint16_t fValue, uint16_t sValue, BOOL run)
PWM5通道初始化函数,它必须在PWM计数器初始化函数之前调用。
Definition: STC8x_PWM.c:209
PWMABDMode_Type
Definition: STC8x_PWM.h:144
@ PWM_COMP_High_To_Low
Definition: STC8x_PWM.h:146
@ PWM_P35_High_To_Low
Definition: STC8x_PWM.h:148
@ PWM_P35_Low_To_High
Definition: STC8x_PWM.h:147
@ PWM_COMP_Low_To_High
Definition: STC8x_PWM.h:145
FSCSTATE PWM_CNT_Init(PWMCLKSrc_Type clkSrc, uint16_t period, BOOL run)
PWM计数器初始化,必须在所有PWM初始化函数的后面调用。
Definition: STC8x_PWM.c:60
FSCSTATE PWM_ABD_Init(PWMABDSignal_Type sigSrc, PWMABDMode_Type mode, BOOL run)
PWM异常检测初始化函数。
Definition: STC8x_PWM.c:283
FSCSTATE PWM3_Init(PWMStartLevel_Type level, uint16_t fValue, uint16_t sValue, BOOL run)
PWM3通道初始化函数,它必须在PWM计数器初始化函数之前调用。
Definition: STC8x_PWM.c:159
FSCSTATE NVIC_PWM2_Init(PWMFlip_Type flipPoint)
PWM2中断初始化函数,设置触发中断的电平翻转点。
Definition: STC8x_PWM.c:400
FSCSTATE GPIO_PWM4_SWPort(GPIOSWPort_Type port)
PWM4切换复用IO函数。
Definition: STC8x_PWM.c:597
FSCSTATE NVIC_PWM3_Init(PWMFlip_Type flipPoint)
PWM3中断初始化函数,设置触发中断的电平翻转点。
Definition: STC8x_PWM.c:420
FSCSTATE GPIO_PWM5_SWPort(GPIOSWPort_Type port)
PWM5切换复用IO函数。
Definition: STC8x_PWM.c:617
FSCSTATE GPIO_PWM7_SWPort(GPIOSWPort_Type port)
PWM7切换复用IO函数。
Definition: STC8x_PWM.c:657
FSCSTATE PWM0_Init(PWMStartLevel_Type level, uint16_t fValue, uint16_t sValue, BOOL run)
PWM0通道初始化函数,它必须在PWM计数器初始化函数之前调用。
Definition: STC8x_PWM.c:84
PWMStartLevel_Type
Definition: STC8x_PWM.h:124
@ PWM_Start_High_Level
Definition: STC8x_PWM.h:126
@ PWM_Start_Low_Level
Definition: STC8x_PWM.h:125
FSCSTATE GPIO_PWM6_SWPort(GPIOSWPort_Type port)
PWM6切换复用IO函数。
Definition: STC8x_PWM.c:637
PWMHoldLevel_Type
Definition: STC8x_PWM.h:156
@ PWM_Hold_Low_Level
Definition: STC8x_PWM.h:158
@ PWM_Hold_Normal_Level
Definition: STC8x_PWM.h:157
@ PWM_Hold_High_Level
Definition: STC8x_PWM.h:159
FSCSTATE PWM1_Init(PWMStartLevel_Type level, uint16_t fValue, uint16_t sValue, BOOL run)
PWM1通道初始化函数,它必须在PWM计数器初始化函数之前调用。
Definition: STC8x_PWM.c:109
FSCSTATE NVIC_PWM1_Init(PWMFlip_Type flipPoint)
PWM1中断初始化函数,设置触发中断的电平翻转点。
Definition: STC8x_PWM.c:380
FSCSTATE GPIO_PWM3_SWPort(GPIOSWPort_Type port)
PWM3切换复用IO函数。
Definition: STC8x_PWM.c:577
FSCSTATE PWM6_Init(PWMStartLevel_Type level, uint16_t fValue, uint16_t sValue, BOOL run)
PWM6通道初始化函数,它必须在PWM计数器初始化函数之前调用。
Definition: STC8x_PWM.c:234
FSCSTATE NVIC_PWM0_Init(PWMFlip_Type flipPoint)
PWM0中断初始化函数,设置触发中断的电平翻转点。
Definition: STC8x_PWM.c:360
FSCSTATE GPIO_PWM2_SWPort(GPIOSWPort_Type port)
PWM2切换复用IO函数。
Definition: STC8x_PWM.c:557
FSCSTATE NVIC_PWM4_Init(PWMFlip_Type flipPoint)
PWM4中断初始化函数,设置触发中断的电平翻转点。
Definition: STC8x_PWM.c:440