-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
78 lines (64 loc) · 1.88 KB
/
main.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
/*
******************************************************************************
MIKROCOMPUTER LABOR - HOME-STATION
Maximilian Vieweg, 11806443
In diesem Projekt gilt:
*=============================================================================
* SYSCLK(Hz) | 64000000
*-----------------------------------------------------------------------------
* AHB Prescaler | 1
*-----------------------------------------------------------------------------
* APB2 Prescaler | 1
*-----------------------------------------------------------------------------
* APB1 Prescaler | 2
*=============================================================================
******************************************************************************
*/
#include "stm32f30x_conf.h"
#include "stm32f30x_adc.h"
#include "stm32f30x_usart.h"
#include "stm32f30x_tim.h"
#include "gpio.h"
#include "tim.h"
#include "LCD.h"
#include "adc.h"
field_t field;
const long MAX_ADC_RESOLUTION = 4095;
int main(void)
{
init_GPIO();
init_TIM();
init_LCD();
init_ADC();
field = initGame();
drawGame(field);
while (1)
{
}
}
void TIM2_IRQHandler()
{
ADC_StartConversion(ADC1);
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
}
void ADC1_2_IRQHandler()
{
double y = ADC_GetConversionValue(ADC1);
if (y / MAX_ADC_RESOLUTION > 0.53)
{
field = game_logic(field, 1);
drawGame(field);
}
else if (y / MAX_ADC_RESOLUTION < 0.47)
{
field = game_logic(field, -1);
drawGame(field);
}
else
{
field = game_logic(field, 0);
drawGame(field);
}
ADC_ClearITPendingBit(ADC1, ADC_IT_EOC); // Clear ADC End of Conversion Flag
ADC_ClearITPendingBit(ADC1, ADC_IT_EOS); // Clear ADC End of Sequence Flag
}