This repository was archived by the owner on Oct 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject6.cpp
More file actions
38 lines (28 loc) · 1.31 KB
/
project6.cpp
File metadata and controls
38 lines (28 loc) · 1.31 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
#include <stm32f30x.h>
void main() {
short int flag = 0; // Variabile si segnalazione on/off
RCC -> AHBENR |= RCC_AHBENR_GPIOEEN; // Abilitazione clock su PE
RCC -> AHBENR |= RCC_APB1ENR_TIM2EN; // Abilitazione clock su TIM2
GPIOE -> MODER = 0x55550000; // OUTPUT per tutti i LED
TIM2 -> CR1 |= TIM_CR1_CEN; // Abilitazione conteggio
TIM2 -> ARR = 4000000; // 8 MHz / 2 --> 4 MHz ogni 0.5 secondi
TIM2 -> CNT = 0; // Ripristinio counter
while(1) {
/**
* Se TIM2_CNT raggiunge quota 4.000.000 grazie all TIM2_ARR viene emmesso un
* evento che abilita TIM2_SR ad 1...
*/
// ... e se la variabile flag è uguale a 0 (LED spenti)
if ((TIM2 -> SR & TIM_SR_UIF) == TIM_SR_UIF && !flag) {
GPIOE -> ODR = 0x0000FF00; // Vengono accessi tutti i LED
TIM2 -> SR &= ~TIM_SR_UIF; // Viene ripristinato TIM2_SR a 0
flag = 1; // Viene memorizzato lo stato
}
// ... e se la variabile flag è uguale ad 1 (LED accesi)
if ((TIM2 -> SR & TIM_SR_UIF) == TIM_SR_UIF && flag) {
GPIOE -> ODR = 0; // Vengono spenti tutti i LEd
TIM2 -> SR &= ~TIM_SR_UIF; // Viene riassegnato TIM2_SR a 0
flag = 0; // Viene memorizzato lo stato
}
}
} // main()