8051-ELL库  beta 1.1.6
8051-ELL library API Document Center
STC8x_I2C.h
浏览该文件的文档.
1 /*-----------------------------------------------------------------------
2 | FILE DESCRIPTION |
3 -----------------------------------------------------------------------*/
4 /*----------------------------------------------------------------------
5  - File name : STC8x_I2C.h
6  - Author : zeweni
7  - Update date : 2020.02.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 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_I2C_H_
33 #define __STC8x_I2C_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 
60 
61 #ifndef PER_LIB_MCU_MUODEL
64  #define PER_LIB_MCU_MUODEL STC8Ax
65 #endif
66 
67 
68 #ifndef PER_LIB_I2C_CTRL
71  #define PER_LIB_I2C_CTRL 1
72 #endif
73 
74 
75 #ifndef PER_LIB_I2C_INIT_CTRL
78  #define PER_LIB_I2C_INIT_CTRL 1
79 #endif
80 
81 
82 #ifndef PER_LIB_I2C_NVIC_CTRL
85  #define PER_LIB_I2C_NVIC_CTRL 1
86 #endif
87 
88 
89 #ifndef PER_LIB_I2C_WORK_CTRL
92  #define PER_LIB_I2C_WORK_CTRL 1
93 #endif
94 
95 
100 typedef enum
101 {
102  I2C_Type_Host = 0x01,
103  I2C_Type_Slave = 0x00
105 
106 
107 /*--------------------------------------------------------
108 | @Description: I2C slave interrupt Trigger enum |
109 --------------------------------------------------------*/
110 
115 typedef enum
116 {
120  I2C_STri_RevStop_Done = 0x80
122 
123 /*-----------------------------------------------------------------------
124 | API FUNCTION |
125 -----------------------------------------------------------------------*/
126 #if (PER_LIB_I2C_CTRL == 1)
127 
128  #if (PER_LIB_I2C_INIT_CTRL == 1)
129 
140 
141  #endif
142 
143  #if (PER_LIB_I2C_NVIC_CTRL == 1)
144 
154 
155 
167 
168 
174  #define NVIC_I2C_HOST_CTRL(run) \
175  { \
176  EAXFR_ENABLE(); \
177  I2CMSCR = run << 7; \
178  EAXFR_DISABLE(); \
179  }
180 
186  #define NVIC_I2C_SLAVE_CTRL(run) \
187  { \
188  EAXFR_ENABLE(); \
189  I2CSLCR &= (I2CSLCR & 0x01 ) | \
190  (run << 6) | (run << 5) | \
191  (run << 4) | (run << 3) ; \
192  EAXFR_DISABLE(); \
193  }
194 
195 
201  #define NVIC_I2C_PRI(pri) \
202  do{ \
203  IP2H = (IP2H & 0xBF) | ((pri & 0x02) << 5); \
204  IP2 = (IP2 & 0xBF) | ((pri & 0x01) << 6); \
205  }while(0)
206 
207 
213  #define I2C_GET_HOST_FLAG() (I2CMSST & 0x40)
214 
215 
222  #define I2C_GET_HOST_BUSY_STATE() (I2CMSST & 0x80)
223 
224 
229  #define I2C_CLEAR_HOST_MASTER_FLAG() {I2CMSST &= 0xBF;}
230 
231 
238  #define I2C_GET_SLAVE_BUSY_STATE() (I2CMSST & 0x80)
239 
240 
247  #define I2C_GET_SLAVE_REVSTART_FLAG() (I2CSLST & 0x40)
248 
249 
256  #define I2C_GET_SLAVE_REVDATA_FLAG() (I2CSLST & 0x20)
257 
258 
265  #define I2C_GET_SLAVE_SENDATA_FLAG() (I2CSLST & 0x10)
266 
267 
274  #define I2C_GET_SLAVE_REVSTOP_FLAG() (I2CSLST & 0x08)
275 
276 
283  #define I2C_CLEAR_SLAVE_REVSTART_FLAG() {I2CSLST &= 0xBF;}
284 
285 
292  #define I2C_CLEAR_SLAVE_REVDATA_FLAG() {I2CSLST &= 0xDF;}
293 
294 
301  #define I2C_CLEAR_SLAVE_SENDATA_FLAG() {I2CSLST &= 0xEF;}
302 
303 
310  #define I2C_CLEAR_SLAVE_REVSTOP_FLAG() {I2CSLST &= 0xF7;}
311 
312  #endif
313 
314  #if (PER_LIB_I2C_WORK_CTRL == 1)
315 
324 
333 
334 
343 
344 
353 
354 
363 
364 
373 
374 
382 
383 
392 
393  #endif
394 
395 #endif
396 /*-----------------------------------------------------------------------
397 | END OF FLIE. (C) COPYRIGHT zeweni |
398 -----------------------------------------------------------------------*/
399 #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 char uint8_t
Definition: ELL_TYPE.h:72
FSCSTATE I2C_Read_ACK(void)
I2C读取ACK信号函数。
I2CType_Type
I2C工作类型枚举体。
Definition: STC8x_I2C.h:101
@ I2C_Type_Host
Definition: STC8x_I2C.h:102
@ I2C_Type_Slave
Definition: STC8x_I2C.h:103
FSCSTATE I2C_Send_NACK(void)
I2C发送NACK信号函数。
FSCSTATE I2C_Send_Btye(uint8_t dat)
I2C发送一个字节函数。
FSCSTATE NVCI_I2C_Master_Init(NVICPri_Type pri, BOOL run)
I2C主机中断初始化函数。
I2CSTri_Type
I2C从机中断触发方式枚举体。
Definition: STC8x_I2C.h:116
@ I2C_STri_RevStart_Done
Definition: STC8x_I2C.h:117
@ I2C_STri_RevStop_Done
Definition: STC8x_I2C.h:120
@ I2C_STri_SendData_Done
Definition: STC8x_I2C.h:119
@ I2C_STri_RevData_Done
Definition: STC8x_I2C.h:118
FSCSTATE I2C_Send_ACK(void)
I2C发送ACK信号函数。
FSCSTATE I2C_Send_Start(void)
I2C发送开始信号函数。
FSCSTATE I2C_Init(I2CType_Type type, uint8_t wTime, BOOL state)
I2C初始化函数。
uint8_t I2C_Read_Byte(void)
I2C读取一个字节函数。
FSCSTATE GPIO_I2C_SWPort(GPIOSWPort_Type port)
I2C切换复用IO函数。
FSCSTATE I2C_Send_Stop(void)
I2C发送停止信号函数。
FSCSTATE NVCI_I2C_Slave_Init(NVICPri_Type pri, I2CSTri_Type triMode)
I2C从机中断初始化函数。