-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.c
72 lines (60 loc) · 1.68 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
#include <stdio.h>
#include <stm32f10x_exti.h>
#include "utils.h"
#include "usart.h"
#include "one_wire.h"
#include "ds18b20.h"
void BTN_Interrupts() {
// Enable clock and its interrupts
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0);
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
EXTI_InitTypeDef EXTI_InitStructure;
EXTI_InitStructure.EXTI_Line = EXTI_Line0;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
int main(void)
{
USART1_Init(921600);
BTN_Init();
BTN_Interrupts();
LED_Init();
// Tick every 1 ms
if (SysTick_Config(SystemCoreClock / 1000)) while (1);
printf("Hello, World!\r\n");
ds18b20_init(GPIOC, GPIO_Pin_6, TIM2);
while(1)
{
ds18b20_read_temperature_all();
ds18b20_wait_for_conversion();
printf("%d---\r\n", ds18b20_get_precission());
ds18b20_convert_temperature_all();
}
}
void SysTick_Handler(void)
{
delay_decrement();
}
void EXTI0_IRQHandler(void)
{
static u8 i = 0;
if (EXTI_GetITStatus(EXTI_Line0) != RESET)
{
unsigned int j = 0;
while (j != 200000) ++j;
if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) != Bit_RESET) {
return;
}
i = (i + 1) % 4;
ds18b20_set_precission(i);
EXTI_ClearITPendingBit(EXTI_Line0);
}
}