-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLED.c
More file actions
90 lines (73 loc) · 3.62 KB
/
LED.c
File metadata and controls
90 lines (73 loc) · 3.62 KB
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
#include "LED.h"
//******************************************************************************************
// User LEDs:
// LD4 Red = PB2 LD5 Green = PE8
// Note: The Green LED is yellow on my board.
// PE8 is also the TIM1_CH1N for ADC Triggers.
//******************************************************************************************
void LED_Init(void){
// Enable the peripheral clock of GPIO Port
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOBEN | RCC_AHB2ENR_GPIOEEN;
///////////////////////////////////////////////////////////////////////////////////////////////
// LD4 Red = PB2
///////////////////////////////////////////////////////////////////////////////////////////////
// GPIO Mode: Input(00), Output(01), AlterFunc(10), Analog(11, reset)
GPIOB->MODER = ~(3U<<(2*2));
GPIOB->MODER |= 1U<<(2*2); // Output(01)
// GPIO Speed: Low speed (00), Medium speed (01), Fast speed (10), High speed (11)
GPIOB->OSPEEDR &= ~(3U<<(2*2));
GPIOB->OSPEEDR |= 3U<<(2*2); // High speed
// GPIO Output Type: Output push-pull (0, reset), Output open drain (1)
GPIOB->OTYPER &= ~(1U<<2); // Push-pull
// GPIO Push-Pull: No pull-up, pull-down (00), Pull-up (01), Pull-down (10), Reserved (11)
GPIOB->PUPDR &= ~(3U<<(2*2)); // No pull-up, no pull-down
///////////////////////////////////////////////////////////////////////////////////////////////
// LD5 Green = PE8
///////////////////////////////////////////////////////////////////////////////////////////////
// GPIO Mode: Input(00), Output(01), AlterFunc(10), Analog(11, reset)
GPIOE->MODER = ~(3U<<(2*8));
GPIOE->MODER |= 1U<<(2*8); // Output(01)
// GPIO Speed: Low speed (00), Medium speed (01), Fast speed (10), High speed (11)
GPIOE->OSPEEDR &= ~(3U<<(2*8));
GPIOE->OSPEEDR |= 3U<<(2*8); // High speed
// GPIO Output Type: Output push-pull (0, reset), Output open drain (1)
GPIOE->OTYPER &= ~(1U<<8); // Push-pull
// GPIO Push-Pull: No pull-up, pull-down (00), Pull-up (01), Pull-down (10), Reserved (11)
GPIOE->PUPDR &= ~(3U<<(2*8)); // No pull-up, no pull-down
}
//******************************************************************************************
// Turn Red LED On
//******************************************************************************************
void Red_LED_On(void){
GPIOB->ODR |= GPIO_ODR_ODR_2;
}
//******************************************************************************************
// Turn Red LED Off
//******************************************************************************************
void Red_LED_Off(void){
GPIOB->ODR &= ~GPIO_ODR_ODR_2;
}
//******************************************************************************************
// Toggle Red LED
//******************************************************************************************
void Red_LED_Toggle(void){
GPIOB->ODR ^= GPIO_ODR_ODR_2;
}
//******************************************************************************************
// Turn Green LED On
//******************************************************************************************
void Green_LED_On(void){
GPIOE->ODR |= GPIO_ODR_ODR_8;
}
//******************************************************************************************
// Turn Green LED Off
//******************************************************************************************
void Green_LED_Off(void){
GPIOE->ODR &= ~GPIO_ODR_ODR_8;
}
//******************************************************************************************
// Toggle Green LED
//******************************************************************************************
void Green_LED_Toggle(void){
GPIOE->ODR ^= GPIO_ODR_ODR_8;
}