8051-ELL库  beta 1.1.6
8051-ELL library API Document Center
STC8x_SPI.h
浏览该文件的文档.
1 /*-----------------------------------------------------------------------
2 | FILE DESCRIPTION |
3 -----------------------------------------------------------------------*/
4 /*----------------------------------------------------------------------
5  - File name : STC8x_SPI.h
6  - Author : zeweni
7  - Update date : 2020.01.29
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_SPI_H_
33 #define __STC8x_SPI_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 
66 
69 #ifndef PER_LIB_SPI_CTRL
70  #define PER_LIB_SPI_CTRL 1
71 #endif
72 
73 
76 #ifndef PER_LIB_SPI_INIT_CTRL
77  #define PER_LIB_SPI_INIT_CTRL 1
78 #endif
79 
80 
83 #ifndef PER_LIB_SPI_NVIC_CTRL
84  #define PER_LIB_SPI_NVIC_CTRL 1
85 #endif
86 
87 
90 #ifndef PER_LIB_SPI_WORK_CTRL
91  #define PER_LIB_SPI_WORK_CTRL 1
92 #endif
93 
94 
99 typedef enum
100 {
103  SPI_Type_Slave = 0x80,
104 } SPIType_Type;
105 
106 
111 typedef enum
112 {
113  SPI_SCLK_DIV_4 = 0x00,
114  SPI_SCLK_DIV_8 = 0x01,
116  SPI_SCLK_DIV_32 = 0x03
118 
119 
124 typedef enum
125 {
126  SPI_Tran_MSB = 0x00,
128  SPI_Tran_LSB = 0x01
131 
132 
137 typedef enum
138 {
139  SPI_Mode_0 = 0x00,
140  SPI_Mode_1 = 0x01,
141  SPI_Mode_2 = 0x02,
142  SPI_Mode_3 = 0x03
144 
145 
151 typedef struct
152 {
158 } SPIInit_Type;
159 
160 
161 /*-----------------------------------------------------------------------
162 | API FUNCTION |
163 -----------------------------------------------------------------------*/
164 #if (PER_LIB_SPI_CTRL == 1)
165 
166  #if (PER_LIB_SPI_INIT_CTRL == 1)
167 
178 
179  #endif
180 
181  #if (PER_LIB_SPI_NVIC_CTRL == 1)
182 
192 
193 
199  #define NVIC_SPI_CTRL(run) do{ IE2 = (IE2 & 0xFD) | (run << 1); }while(0)
200 
206  #define NVIC_SPI_PRI(pri) \
207  do{ \
208  IP2H = (IP2H & 0xFD) | (pri & 0x02); \
209  IP2 = (IP2 & 0xFD) | ((pri & 0x01) << 1); \
210  }while(0)
211 
212 
217  #define SPI_GET_FLAG() (SPSTAT & 0x80)
218 
223  #define SPI_CLEAR_FLAG() do{SPSTAT = 0xC0;}while(0)
224 
225  #endif
226 
227  #if (PER_LIB_SPI_WORK_CTRL == 1)
228 
237 
238 
246 
247 
256 
257  #endif
258 
259 #endif
260 /*-----------------------------------------------------------------------
261 | END OF FLIE. (C) COPYRIGHT zeweni |
262 -----------------------------------------------------------------------*/
263 #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 NVIC_SPI_Init(NVICPri_Type pri, BOOL run)
SPI中断初始化函数。
SPIType_Type
SPI工作类型枚举体。
Definition: STC8x_SPI.h:100
@ SPI_Type_Master_Slave
Definition: STC8x_SPI.h:101
@ SPI_Type_Master
Definition: STC8x_SPI.h:102
@ SPI_Type_Slave
Definition: STC8x_SPI.h:103
FSCSTATE SPI_Init(const SPIInit_Type *spix)
SPI初始化函数。
uint8_t SPI_Receive_Data(void)
SPI接收数据(一个字节)函数。
SPIMode_Type
SPI模式枚举体。
Definition: STC8x_SPI.h:138
@ SPI_Mode_3
Definition: STC8x_SPI.h:142
@ SPI_Mode_1
Definition: STC8x_SPI.h:140
@ SPI_Mode_2
Definition: STC8x_SPI.h:141
@ SPI_Mode_0
Definition: STC8x_SPI.h:139
FSCSTATE GPIO_SPI_SWPort(GPIOSWPort_Type port)
SPI切换复用IO函数。
SPITran_Type
SPI传输类型枚举体。
Definition: STC8x_SPI.h:125
@ SPI_Tran_LSB
Definition: STC8x_SPI.h:128
@ SPI_Tran_MSB
Definition: STC8x_SPI.h:126
FSCSTATE SPI_Send_Data(uint8_t dat)
SPI发送数据(一个字节)函数。
SPIClkSrc_Type
SPI时钟源选择枚举体。
Definition: STC8x_SPI.h:112
@ SPI_SCLK_DIV_16
Definition: STC8x_SPI.h:115
@ SPI_SCLK_DIV_8
Definition: STC8x_SPI.h:114
@ SPI_SCLK_DIV_4
Definition: STC8x_SPI.h:113
@ SPI_SCLK_DIV_32
Definition: STC8x_SPI.h:116
SPI初始化枚举体,需要你定义它,并用它的地址来传参给初始化函数。
Definition: STC8x_SPI.h:152
SPIMode_Type Mode
Definition: STC8x_SPI.h:155
SPIType_Type Type
Definition: STC8x_SPI.h:153
SPITran_Type Tran
Definition: STC8x_SPI.h:156
BOOL Run
Definition: STC8x_SPI.h:157
SPIClkSrc_Type ClkSrc
Definition: STC8x_SPI.h:154