Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stm32f4xx_tim.h"
- #include "stm32f4xx_gpio.h"
- #include "stm32f4xx_rcc.h"
- #include "stm32f4xx_conf.h"
- //zad1
- int main(void)
- {
- SystemInit();
- /* GPIOD Periph clock enable */
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
- GPIO_InitTypeDef GPIO_InitStructure;
- /* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2| GPIO_Pin_3;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- //kanał wyjciowy GPIO
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_TIM5);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_TIM5);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_TIM5);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- //TIM5
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- TIM_TimeBaseStructure.TIM_Period = 99;
- TIM_TimeBaseStructure.TIM_Prescaler = 839;
- TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
- TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
- TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure);
- TIM_Cmd(TIM5, ENABLE);
- //PWM
- TIM_OCInitTypeDef TIM_OCInitStructure;
- /* PWM1 Mode configuration: */
- TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
- TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
- TIM_OCInitStructure.TIM_Pulse = 1000;
- TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
- TIM_OC1Init(TIM5, &TIM_OCInitStructure);
- TIM_OC1PreloadConfig(TIM5, TIM_OCPreload_Enable);
- TIM_OC2Init(TIM5, &TIM_OCInitStructure);
- TIM_OC2PreloadConfig(TIM5, TIM_OCPreload_Enable);
- TIM_OC3Init(TIM5, &TIM_OCInitStructure);
- TIM_OC3PreloadConfig(TIM5, TIM_OCPreload_Enable);
- TIM4->CCR1 = 9;
- TIM4->CCR2 = 49;
- TIM4->CCR3 = 74;
- for(;;)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement