ATY_LIB
V2_102_230218
ATY_LIB for general devices or ALGO
Loading...
Searching...
No Matches
gpio_input_stc8g1k08a.c
Go to the documentation of this file.
1
// Copyright 2022 IOsetting <iosetting(at)outlook.com>
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
/***
16
* Demo: STC8G1K08A GPIO Input
17
*
18
* Pin connection:
19
*
20
* ___
21
* GND <- 1KR <- Key -> P5.4 -| |- P3.3 <-- LED --> 4.7KR -> GND
22
* 3.3V -> VCC -| |- P3.2 <-- LED --> 4.7KR -> GND
23
* P5.5 -| |- TX
24
* GND -> GND -|___|- RX
25
*
26
*
27
* test-board: Minimum System; test-MCU: STC8G1K08A
28
*/
29
30
#include "
fw_hal.h
"
31
32
void
GPIO_Init
(
void
)
33
{
34
// P3.2, P3.3
35
GPIO_P3_SetMode
(
GPIO_Pin_2
|
GPIO_Pin_3
,
GPIO_Mode_Output_PP
);
36
// P5.4, pullup
37
GPIO_P5_SetMode
(
GPIO_Pin_4
,
GPIO_Mode_Input_HIP
);
38
GPIO_SetPullUp
(
GPIO_Port_5
,
GPIO_Pin_4
,
HAL_State_ON
);
39
}
40
41
int
main
(
void
)
42
{
43
GPIO_Init
();
44
/* Turn LED1 on, LED2 off */
45
P32 =
SET
;
46
P33 =
RESET
;
47
48
while
(1)
49
{
50
/* Check if P5.4 is low (Key pressed) */
51
if
(P54 ==
RESET
)
52
{
53
/* Switch */
54
P3 = P3 & 0xF3 | 0x08;
55
SYS_Delay
(300);
56
/* Restore */
57
P3 = P3 & 0xF3 | 0x04;
58
}
59
}
60
}
GPIO_P5_SetMode
#define GPIO_P5_SetMode(__PINS__, __MODE__)
Definition:
fw_gpio.h:99
GPIO_P3_SetMode
#define GPIO_P3_SetMode(__PINS__, __MODE__)
Definition:
fw_gpio.h:89
GPIO_Pin_2
@ GPIO_Pin_2
Definition:
fw_gpio.h:47
GPIO_Pin_4
@ GPIO_Pin_4
Definition:
fw_gpio.h:49
GPIO_Pin_3
@ GPIO_Pin_3
Definition:
fw_gpio.h:48
GPIO_SetPullUp
#define GPIO_SetPullUp(__PORT__, __PINS__, __STATE__)
Definition:
fw_gpio.h:116
GPIO_Port_5
@ GPIO_Port_5
Definition:
fw_gpio.h:36
GPIO_Mode_Input_HIP
@ GPIO_Mode_Input_HIP
Definition:
fw_gpio.h:25
GPIO_Mode_Output_PP
@ GPIO_Mode_Output_PP
Definition:
fw_gpio.h:24
fw_hal.h
SYS_Delay
void SYS_Delay(uint16_t t)
Definition:
fw_sys.c:65
HAL_State_ON
@ HAL_State_ON
Definition:
fw_types.h:71
RESET
@ RESET
Definition:
fw_types.h:84
SET
@ SET
Definition:
fw_types.h:85
main
int main(void)
Definition:
gpio_input_stc8g1k08a.c:41
GPIO_Init
void GPIO_Init(void)
Definition:
gpio_input_stc8g1k08a.c:32
ATY_LIB
FwLib_STC8
demo
gpio
gpio_input
gpio_input_stc8g1k08a.c
Generated by
1.9.6