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
|
#include "at32f403a_407_board.h"
#include "at32f403a_407_clock.h"
int main(void)
{
/* config nvic priority group */
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
system_clock_config();
/* peripheral clocks configuration */
crm_configuration();
/* nvic Configuration */
nvic_irq_enable(TMR2_GLOBAL_IRQn, 0, 0);
/* gpio configuration */
gpio_configuration();
/* compute the prescaler value */
prescaler_value = (uint16_t)(system_core_clock / 12000000) - 1;
/* tmr2 time base configuration */
tmr_base_init(TMR2, 65535, prescaler_value);
tmr_cnt_dir_set(TMR2, TMR_COUNT_UP);
tmr_clock_source_div_set(TMR2, TMR_CLOCK_DIV1);
tmr_output_default_para_init(&tmr_oc_init_structure);
tmr_oc_init_structure.oc_mode = TMR_OUTPUT_CONTROL_OFF;
tmr_oc_init_structure.oc_idle_state = FALSE;
tmr_oc_init_structure.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_oc_init_structure.oc_output_state = TRUE;
tmr_output_channel_config(TMR2, TMR_SELECT_CHANNEL_1, &tmr_oc_init_structure);
tmr_channel_value_set(TMR2, TMR_SELECT_CHANNEL_1, ccr1_val);
tmr_output_channel_config(TMR2, TMR_SELECT_CHANNEL_2, &tmr_oc_init_structure);
tmr_channel_value_set(TMR2, TMR_SELECT_CHANNEL_2, ccr2_val);
tmr_output_channel_config(TMR2, TMR_SELECT_CHANNEL_3, &tmr_oc_init_structure);
tmr_channel_value_set(TMR2, TMR_SELECT_CHANNEL_3, ccr3_val);
tmr_output_channel_config(TMR2, TMR_SELECT_CHANNEL_4, &tmr_oc_init_structure);
tmr_channel_value_set(TMR2, TMR_SELECT_CHANNEL_4, ccr4_val);
/* tmr2 int enable */
tmr_interrupt_enable(TMR2, TMR_C1_INT | TMR_C2_INT | TMR_C3_INT | TMR_C4_INT, TRUE);
/* tmr enable counter */
tmr_counter_enable(TMR2, TRUE);
while(1)
{
}
}
|