ATY_LIB
V2_102_230218
ATY_LIB for general devices or ALGO
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
// Copyright 2021 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: 28BYJ-48 Stepper Motor with ULN2003 Driver
17
*
18
* Pin connection:
19
* MCU ULN2003 External Power Supply
20
* P10 => IN1
21
* P11 => IN2
22
* P12 => IN3
23
* P13 => IN4
24
* VCC => 5V ~ 12V
25
* GND => GND
26
*
27
* test-board: Minimum System; test-MCU: STC8H1K08,STC8H3K64S2
28
*/
29
30
#include "
fw_hal.h
"
31
32
// Clockwise, 8 steps
33
uint8_t
cw
[8]={
34
0B00001001,
35
0B00000001,
36
0B00000011,
37
0B00000010,
38
0B00000110,
39
0B00000100,
40
0B00001100,
41
0B00001000
42
};
43
44
void
GPIO_Init
(
void
)
45
{
46
// P10, P11, P12, P13
47
GPIO_P1_SetMode
(
GPIO_Pin_0
|
GPIO_Pin_1
|
GPIO_Pin_2
|
GPIO_Pin_3
,
GPIO_Mode_Output_PP
);
48
}
49
50
int
main
(
void
)
51
{
52
uint8_t
step;
53
uint16_t
pos
;
54
SYS_SetClock
();
55
GPIO_Init
();
56
57
while
(1)
58
{
59
for
(
pos
= 0;
pos
< 640;
pos
++)
60
{
61
step = 8;
62
while
(step--)
63
{
64
P1 = P1 & 0xF0 |
cw
[7 - step];
65
SYS_Delay
(5);
66
}
67
}
68
SYS_Delay
(500);
69
for
(
pos
= 0;
pos
< 640;
pos
++)
70
{
71
step = 8;
72
while
(step--)
73
{
74
P1 = P1 & 0xF0 |
cw
[step];
75
SYS_Delay
(5);
76
}
77
}
78
SYS_Delay
(500);
79
}
80
}
pos
uint8_t pos
Definition:
adc_interrupt_2ch.c:32
GPIO_Pin_2
@ GPIO_Pin_2
Definition:
fw_gpio.h:47
GPIO_Pin_0
@ GPIO_Pin_0
Definition:
fw_gpio.h:45
GPIO_Pin_3
@ GPIO_Pin_3
Definition:
fw_gpio.h:48
GPIO_Pin_1
@ GPIO_Pin_1
Definition:
fw_gpio.h:46
GPIO_P1_SetMode
#define GPIO_P1_SetMode(__PINS__, __MODE__)
Definition:
fw_gpio.h:79
GPIO_Mode_Output_PP
@ GPIO_Mode_Output_PP
Definition:
fw_gpio.h:24
fw_hal.h
SYS_SetClock
void SYS_SetClock(void)
Definition:
fw_sys.c:40
SYS_Delay
void SYS_Delay(uint16_t t)
Definition:
fw_sys.c:65
uint16_t
unsigned short uint16_t
Definition:
fw_types.h:19
uint8_t
unsigned char uint8_t
Definition:
fw_types.h:18
main
int main(void)
Definition:
main.c:45
GPIO_Init
void GPIO_Init(void)
Definition:
main.c:39
cw
uint8_t cw[8]
Definition:
main.c:33
ATY_LIB
FwLib_STC8
demo
gpio
uln2003
main.c
Generated by
1.9.6