8051-ELL库  beta 1.1.6
8051-ELL library API Document Center
STC8x_COMP.h
浏览该文件的文档.
1 /*-----------------------------------------------------------------------
2 | FILE DESCRIPTION |
3 -----------------------------------------------------------------------*/
4 /*----------------------------------------------------------------------
5  - File name : STC8Ax_COMP.h
6  - Author : zeweni
7  - Update date : 2020.04.23
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 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 __STC8Ax_COMP_H_
33 #define __STC8Ax_COMP_H_
34 
35 /*--------------------------------------------------------
36 | @Description: ELL library core |
37 --------------------------------------------------------*/
38 #include "ELL_CORE.h"
39 
40 /*--------------------------------------------------------
41 | @Description: STC8x MCU Register |
42 --------------------------------------------------------*/
43 
44 #if (PER_LIB_MCU_MUODEL == STC8Ax)
45  #include "STC8Ax_REG.h"
46 #elif (PER_LIB_MCU_MUODEL == STC8Cx)
47  #include "STC8Cx_REG.h"
48 #elif (PER_LIB_MCU_MUODEL == STC8Fx)
49  #include "STC8Fx_REG.h"
50 #elif (PER_LIB_MCU_MUODEL == STC8Gx)
51  #include "STC8Gx_REG.h"
52 #elif (PER_LIB_MCU_MUODEL == STC8Hx)
53  #include "STC8Hx_REG.h"
54 #endif
55 
56 /*-----------------------------------------------------------------------
57 | DATA |
58 -----------------------------------------------------------------------*/
59 
62 #ifndef PER_LIB_MCU_MUODEL
63  #define PER_LIB_MCU_MUODEL STC8Ax
64 #endif
65 
68 #ifndef PER_LIB_COMP_CTRL
69  #define PER_LIB_COMP_CTRL 1
70 #endif
71 
74 #ifndef PER_LIB_COMP_INIT_CTRL
75  #define PER_LIB_COMP_INIT_CTRL 1
76 #endif
77 
80 #ifndef PER_LIB_COMP_NVIC_CTRL
81  #define PER_LIB_COMP_NVIC_CTRL 1
82 #endif
83 
86 #ifndef PER_LIB_COMP_WORK_CTRL
87  #define PER_LIB_COMP_WORK_CTRL 1
88 #endif
89 
90 
91 //** 正极引脚P37。PEPin. */
92 #define COMP_PE_P37 0xF7
93 
94 /* STC8Ax */
95 #define COMP_PE_P10_8Ax 0x00
96 #define COMP_PE_P11_8Ax 0x01
97 #define COMP_PE_P12_8Ax 0x02
98 #define COMP_PE_P13_8Ax 0x03
99 #define COMP_PE_P14_8Ax 0x04
100 #define COMP_PE_P15_8Ax 0x05
101 #define COMP_PE_P16_8Ax 0x06
102 #define COMP_PE_P17_8Ax 0x07
103 #define COMP_PE_P00_8Ax 0x08
104 #define COMP_PE_P01_8Ax 0x09
105 #define COMP_PE_P02_8Ax 0x0A
106 #define COMP_PE_P03_8Ax 0x0B
107 #define COMP_PE_P04_8Ax 0x0C
108 #define COMP_PE_P05_8Ax 0x0D
109 #define COMP_PE_P06_8Ax 0x0E
111 /* STC8G1K08A 8Pin */
112 #define COMP_PE_P30_8G1K08A 0x00
113 #define COMP_PE_P31_8G1K08A 0x01
114 #define COMP_PE_P32_8G1K08A 0x02
115 #define COMP_PE_P33_8G1K08A 0x03
116 #define COMP_PE_P54_8G1K08A 0x04
117 #define COMP_PE_P55_8G1K08A 0x05
119 /* STC8G1K08 16Pin and 20Pin / STC8G1K08T 20Pin */
120 #define COMP_PE_P10_8G1K08_T 0x00
121 #define COMP_PE_P11_8G1K08_T 0x01
122 #define COMP_PE_P12_8G1K08_T 0x02
123 #define COMP_PE_P13_8G1K08_T 0x03
124 #define COMP_PE_P14_8G1K08_T 0x04
125 #define COMP_PE_P15_8G1K08_T 0x05
126 #define COMP_PE_P16_8G1K08_T 0x06
127 #define COMP_PE_P17_8G1K08_T 0x07
128 #define COMP_PE_P30_8G1K08_T 0x08
129 #define COMP_PE_P31_8G1K08_T 0x09
130 #define COMP_PE_P32_8G1K08_T 0x0A
131 #define COMP_PE_P33_8G1K08_T 0x0B
132 #define COMP_PE_P34_8G1K08_T 0x0C
133 #define COMP_PE_P35_8G1K08_T 0x0D
134 #define COMP_PE_P36_8G1K08_T 0x0E
136 /* STC8G2K64S4 16Pin / STC8G2K64S2 */
137 #define COMP_PE_P10_8G2K64S2_S4 0x00
138 #define COMP_PE_P11_8G2K64S2_S4 0x01
139 #define COMP_PE_P12_8G2K64S2_S4 0x02
140 #define COMP_PE_P13_8G2K64S2_S4 0x03
141 #define COMP_PE_P14_8G2K64S2_S4 0x04
142 #define COMP_PE_P15_8G2K64S2_S4 0x05
143 #define COMP_PE_P16_8G2K64S2_S4 0x06
144 #define COMP_PE_P17_8G2K64S2_S4 0x07
145 #define COMP_PE_P00_8G2K64S2_S4 0x08
146 #define COMP_PE_P01_8G2K64S2_S4 0x09
147 #define COMP_PE_P02_8G2K64S2_S4 0x0A
148 #define COMP_PE_P03_8G2K64S2_S4 0x0B
149 #define COMP_PE_P04_8G2K64S2_S4 0x0C
150 #define COMP_PE_P05_8G2K64S2_S4 0x0D
151 #define COMP_PE_P06_8G2K64S2_S4 0x0E
153 /* STC8H1K28 */
154 #define COMP_PE_P10_8H1K28 0x00
155 #define COMP_PE_P11_8H1K28 0x01
156 #define COMP_PE_P12_8H1K28 0x02
157 #define COMP_PE_P13_8H1K28 0x03
158 #define COMP_PE_P14_8H1K28 0x04
159 #define COMP_PE_P15_8H1K28 0x05
160 #define COMP_PE_P16_8H1K28 0x06
161 #define COMP_PE_P17_8H1K28 0x07
162 #define COMP_PE_P00_8H1K28 0x08
163 #define COMP_PE_P01_8H1K28 0x09
164 #define COMP_PE_P02_8H1K28 0x0A
165 #define COMP_PE_P03_8H1K28 0x0B
167 /* STC8H1K08 */
168 #define COMP_PE_P10_8H1K08 0x00
169 #define COMP_PE_P11_8H1K08 0x01
170 #define COMP_PE_P30_8H1K08 0x08
171 #define COMP_PE_P31_8H1K08 0x09
172 #define COMP_PE_P32_8H1K08 0x0A
173 #define COMP_PE_P33_8H1K08 0x0B
174 #define COMP_PE_P34_8H1K08 0x0C
175 #define COMP_PE_P35_8H1K08 0x0D
176 #define COMP_PE_P36_8H1K08 0x0E
178 /* STC8H3K64S2 / STC8H3K64S4 */
179 #define COMP_PE_P10_8H3K64S2_S4 0x00
180 #define COMP_PE_P11_8H3K64S2_S4 0x01
181 #define COMP_PE_P12_8H3K64S2_S4 0x02
182 #define COMP_PE_P16_8H3K64S2_S4 0x06
183 #define COMP_PE_P17_8H3K64S2_S4 0x07
184 #define COMP_PE_P00_8H3K64S2_S4 0x08
185 #define COMP_PE_P01_8H3K64S2_S4 0x09
186 #define COMP_PE_P02_8H3K64S2_S4 0x0A
187 #define COMP_PE_P03_8H3K64S2_S4 0x0B
188 #define COMP_PE_P04_8H3K64S2_S4 0x0C
189 #define COMP_PE_P05_8H3K64S2_S4 0x0D
190 #define COMP_PE_P06_8H3K64S2_S4 0x0E
192 /* STC8H8K64U / STC8H2K64T */
193 #define COMP_PE_P10_8H8K64U_2K64T 0x00
194 #define COMP_PE_P11_8H8K64U_2K64T 0x01
195 #define COMP_PE_P54_8H8K64U_2K64T 0x02
196 #define COMP_PE_P13_8H8K64U_2K64T 0x03
197 #define COMP_PE_P14_8H8K64U_2K64T 0x04
198 #define COMP_PE_P15_8H8K64U_2K64T 0x05
199 #define COMP_PE_P16_8H8K64U_2K64T 0x06
200 #define COMP_PE_P17_8H8K64U_2K64T 0x07
201 #define COMP_PE_P00_8H8K64U_2K64T 0x08
202 #define COMP_PE_P01_8H8K64U_2K64T 0x09
203 #define COMP_PE_P02_8H8K64U_2K64T 0x0A
204 #define COMP_PE_P03_8H8K64U_2K64T 0x0B
205 #define COMP_PE_P04_8H8K64U_2K64T 0x0C
206 #define COMP_PE_P05_8H8K64U_2K64T 0x0D
207 #define COMP_PE_P06_8H8K64U_2K64T 0x0E
210 #define COMP_NE_P36 0x10
211 
213 #define COMP_IN_REV 0x0F
214 
215 
220 typedef enum
221 {
222  COMP_DIR_Forward = 0x00,
225  COMP_DIR_Reverse = 0x01
229 
230 
235 typedef enum
236 {
237  COMP_Tri_Null = 0x00,
240  COMP_Tri_Falling = 0x10,
243  COMP_Tri_Rising = 0x20,
246  COMP_Tri_Edge = 0x30
250 
256 typedef struct
257 {
265 } COMP_InitType;
266 
267 /*-----------------------------------------------------------------------
268 | API FUNCTION |
269 -----------------------------------------------------------------------*/
270 #if (PER_LIB_COMP_CTRL == 1)
271 
272  #if (PER_LIB_COMP_INIT_CTRL == 1)
273 
285 
286  #endif
287 
288 
289  #if (PER_LIB_COMP_NVIC_CTRL == 1)
290 
300 
301 
307  #define NVIC_COMP_CTRL(run) do{CMPCR1 = (CMPCR1 & 0xCF)|(run << 4);}while(0)
308 
309 
315  #define COMP_NVIC_PRI(pri) \
316  do{ \
317  IP2H = (IP2H & 0xEF) | ((pri & 0x02) << 3); \
318  IP2 = (IP2 & 0xEF) | ((pri & 0x01) << 4); \
319  }while(0)
320 
321  #endif
322 
323 
324  #if (PER_LIB_COMP_WORK_CTRL == 1)
325 
332  #define COMP_GET_FLAG() (CMPCR1 & 0x40)
333 
334 
340  #define COMP_CLEAR_FLAG() do{CMPCR1 &= 0xBF;}while(0)
341 
342 
351 
357  #define COMP_GET_RESULT() (CMPCR1 & 0x01)
358 
359  #endif
360 
361 #endif
362 /*-----------------------------------------------------------------------
363 | END OF FLIE. (C) COPYRIGHT zeweni |
364 -----------------------------------------------------------------------*/
365 #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
unsigned char uint8_t
Definition: ELL_TYPE.h:72
FSCSTATE GPIO_COMP_SWPort(GPIOSWPort_Type port)
COMP切换复用IO函数。
COMPDIRPut_Type
COMP输出方向枚举体。
Definition: STC8x_COMP.h:221
@ COMP_DIR_Forward
Definition: STC8x_COMP.h:222
@ COMP_DIR_Reverse
Definition: STC8x_COMP.h:225
FSCSTATE COMP_Init(const COMP_InitType *compx)
COMP初始化函数。
COMPTri_Type
COMP中断触发方式枚举体。
Definition: STC8x_COMP.h:236
@ COMP_Tri_Rising
Definition: STC8x_COMP.h:243
@ COMP_Tri_Null
Definition: STC8x_COMP.h:237
@ COMP_Tri_Edge
Definition: STC8x_COMP.h:246
@ COMP_Tri_Falling
Definition: STC8x_COMP.h:240
FSCSTATE NVIC_COMP_Init(NVICPri_Type pri, COMPTri_Type triMode)
COMP中断初始化函数。
COMP初始化结构体句柄,初始化时请定义该句柄,并用其地址来传参。
Definition: STC8x_COMP.h:257
BOOL Output
Definition: STC8x_COMP.h:263
BOOL AC_FTW
Definition: STC8x_COMP.h:260
uint8_t NEPin
Definition: STC8x_COMP.h:259
BOOL Run
Definition: STC8x_COMP.h:264
COMPDIRPut_Type DIRPut
Definition: STC8x_COMP.h:262
uint8_t PEPin
Definition: STC8x_COMP.h:258
uint16_t DC_FTW
Definition: STC8x_COMP.h:261