1 | // SystemCoreClock = 120Mhz
|
2 |
|
3 | void TIM2_IRQHandler(void)
|
4 | {
|
5 | TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
|
6 | if(GPIO_ReadOutputDataBit(GPIOE, GPIO_Pin_0))
|
7 | {
|
8 | GPIO_WriteBit(GPIOE, GPIO_Pin_0, RESET);
|
9 | }
|
10 | else
|
11 | {
|
12 | GPIO_WriteBit(GPIOE, GPIO_Pin_0, SET);
|
13 | }
|
14 | }
|
15 |
|
16 |
|
17 | void TIMER2_Init(void)
|
18 | {
|
19 | GPIO_InitTypeDef GPIO_InitStructure;
|
20 | NVIC_InitTypeDef NVIC_TIM2InitStructure;
|
21 | TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
22 |
|
23 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
|
24 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
|
25 |
|
26 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
|
27 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
28 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
29 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
30 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
31 | GPIO_Init(GPIOE, &GPIO_InitStructure);
|
32 |
|
33 | TIM_TimeBaseStructure.TIM_Period = 3-1;
|
34 | TIM_TimeBaseStructure.TIM_Prescaler = 10-1;
|
35 | TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
|
36 | TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Down;
|
37 | TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
|
38 |
|
39 | TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
|
40 |
|
41 | NVIC_TIM2InitStructure.NVIC_IRQChannel = TIM2_IRQn;
|
42 | NVIC_TIM2InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
|
43 | NVIC_TIM2InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
|
44 | NVIC_TIM2InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
45 | NVIC_Init(&NVIC_TIM2InitStructure);
|
46 |
|
47 | TIM_Cmd(TIM2, ENABLE);
|
48 | }
|