1 | #include "stm32f4xx.h"
|
2 | #include "stm32f4xx_gpio.h"
|
3 | #include "stm32f4xx_rcc.h"
|
4 | #include "stm32f4xx_tim.h"
|
5 |
|
6 | int main(void)
|
7 | {
|
8 |
|
9 | SystemInit();
|
10 |
|
11 | // LED Pin
|
12 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
|
13 | GPIO_InitTypeDef GPIO_InitStructure;
|
14 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
|
15 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
16 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
17 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
18 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
19 | GPIO_Init(GPIOD, &GPIO_InitStructure);
|
20 | // LED Pin END
|
21 |
|
22 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
|
23 | GPIO_InitTypeDef GPIO_InitStructure2;
|
24 | GPIO_InitStructure2.GPIO_Pin=GPIO_Pin_8;
|
25 | GPIO_InitStructure2.GPIO_Mode=GPIO_Mode_AF;
|
26 | GPIO_InitStructure2.GPIO_OType=GPIO_OType_PP;
|
27 | GPIO_InitStructure2.GPIO_Speed=GPIO_Speed_100MHz;
|
28 | GPIO_InitStructure2.GPIO_PuPd=GPIO_PuPd_UP;
|
29 | GPIO_Init(GPIOA,&GPIO_InitStructure2);
|
30 | GPIO_PinAFConfig(GPIOA,GPIO_PinSource8,GPIO_AF_TIM1);
|
31 |
|
32 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
|
33 | GPIO_InitTypeDef GPIO_InitStructure3;
|
34 | GPIO_InitStructure3.GPIO_Pin=GPIO_Pin_13;
|
35 | GPIO_InitStructure3.GPIO_Mode=GPIO_Mode_AF;
|
36 | GPIO_InitStructure3.GPIO_OType=GPIO_OType_PP;
|
37 | GPIO_InitStructure3.GPIO_Speed=GPIO_Speed_100MHz;
|
38 | GPIO_InitStructure3.GPIO_PuPd=GPIO_PuPd_UP;
|
39 | GPIO_Init(GPIOB,&GPIO_InitStructure3);
|
40 | GPIO_PinAFConfig(GPIOB,GPIO_PinSource13,GPIO_AF_TIM1);
|
41 |
|
42 | RCC_APB1PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
|
43 | TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
44 | TIM_OCInitTypeDef TIM_OCInitStructure;
|
45 | TIM_TimeBaseStructure.TIM_Period=400;
|
46 | TIM_TimeBaseStructure.TIM_Prescaler=21;
|
47 | TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
|
48 | TIM_TimeBaseStructure.TIM_ClockDivision=0;
|
49 | TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure);
|
50 |
|
51 | TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;
|
52 | TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
|
53 | TIM_OCInitStructure.TIM_Pulse=200;
|
54 | TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
|
55 | TIM_OC1Init(TIM1,&TIM_OCInitStructure);
|
56 | TIM_OC1PreloadConfig(TIM1,TIM_OCPreload_Enable);
|
57 |
|
58 | TIM_ARRPreloadConfig(TIM1,ENABLE);
|
59 | TIM_Cmd(TIM1,ENABLE);
|
60 |
|
61 | unsigned int test = 0;
|
62 | unsigned int i = 0;
|
63 | unsigned int e = 0;
|
64 | while(1)
|
65 | {
|
66 | //LED-Blinker
|
67 | GPIO_SetBits(GPIOD, GPIO_Pin_13);
|
68 | for(i = 0; i<50000 ; i++)
|
69 | {
|
70 | for(e = 0; e<100 ; e++)
|
71 | {
|
72 | test++;
|
73 | }
|
74 | }
|
75 | test = 0;
|
76 | GPIO_ResetBits(GPIOD, GPIO_Pin_13);
|
77 | for(i = 0; i<50000 ; i++)
|
78 | {
|
79 | for(e = 0; e<100 ; e++)
|
80 | {
|
81 | test++;
|
82 | }
|
83 | }
|
84 | test = 0;
|
85 | //LED-Blinker END
|
86 | }
|
87 | }
|