-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSTM32F4xx_SPL_Test.c
104 lines (88 loc) · 2.88 KB
/
STM32F4xx_SPL_Test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_usart.h"
#include "stm32f4xx_rcc.h"
void setup_GPIOs();
void check_LEDs();
void main()
{
unsigned char s = 0;
setup_GPIOs();
check_LEDs();
while(1)
{
if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0))
{
while(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) == 1);
s++;
}
if(s >= 6)
{
s = 0;
}
switch(s)
{
case 1:
{
GPIO_SetBits(GPIOD, GPIO_Pin_12);
break;
}
case 2:
{
GPIO_SetBits(GPIOD, GPIO_Pin_13);
break;
}
case 3:
{
GPIO_SetBits(GPIOD, GPIO_Pin_14);
break;
}
case 4:
{
GPIO_SetBits(GPIOD, GPIO_Pin_15);
break;
}
case 5:
{
GPIO_SetBits(GPIOD, GPIO_Pin_12);
GPIO_SetBits(GPIOD, GPIO_Pin_13);
GPIO_SetBits(GPIOD, GPIO_Pin_14);
GPIO_SetBits(GPIOD, GPIO_Pin_15);
break;
}
default:
{
break;
}
}
Delay_ms(90);
GPIO_ResetBits(GPIOD, GPIO_Pin_12);
GPIO_ResetBits(GPIOD, GPIO_Pin_13);
GPIO_ResetBits(GPIOD, GPIO_Pin_14);
GPIO_ResetBits(GPIOD, GPIO_Pin_15);
Delay_ms(90);
}
}
void setup_GPIOs()
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOD, &GPIO_InitStructure);
}
void check_LEDs()
{
GPIO_SetBits(GPIOD, (GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15));
Delay_ms(900);
GPIO_ResetBits(GPIOD, (GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15));
}