forked from arocketman/stm32f3-discovery-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1)Led-turning-on-Manual.c
51 lines (46 loc) · 1.23 KB
/
1)Led-turning-on-Manual.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
/*
* Turns on the Led lights one by one and does a spinning wheel.
*/
#include <stm32f30x.h>
void waitMe();
void setAndWait(uint32_t);
int main(void)
{
//I want to set the bit 21. The LEDs are activated through GPIOE which is enabled through bit 21. Pag. 116 ref. Manual
RCC->AHBENR |= 0x00200000;
//We want to set the GPIOE peripheral to output mode, which is 10.
//The LEDs are on port 8-15
//PORTS 8-15 -> BIT 16-31
GPIOE->MODER |= 0x55550000;
int j;
for(j = 0; j < 10 ; j++){
setAndWait(0x0000FFFF); //Ports from 8-15 to 1 (With ODR Bits = ports)
setAndWait(0x00000000); //all off
setAndWait(0x00008000); //Port 15
setAndWait(0x00004000); //Port 14
setAndWait(0x00002000); //Port 13
setAndWait(0x00001000); //Port 12
setAndWait(0x00000800); //Port 11
setAndWait(0x00000400); //Port 10
setAndWait(0x00000200); //Port 9
setAndWait(0x00000100); //Port 8
}
//Turn them all off.
setAndWait(0x00000000);
return 0;
}
/**
*Typical 'sleep' function.
*/
void waitMe(){
int i = 0;
for(i = 0; i < 500000; i++){}
}
/**
*Sets the GPIOE ODR register to a certain value.
*@param regValue hex Value for the registry.
*/
void setAndWait(uint32_t regValue){
GPIOE->ODR = regValue;
waitMe();
}