- /**
- ******************************************************************************
- * @file main.c
- * @author Ac6
- * @version V1.0
- * @date 01-December-2013
- * @brief Default main function.
- ******************************************************************************
- */
- #include "stm32f4xx.h"
- #include "stm32f4_discovery.h"
- int p = 0 ;
- void TIM4_IRQHandler(void)
- {
- GPIO_SetBits(GPIOD, GPIO_Pin_8| GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14);
- if(TIM_GetITStatus(TIM4, TIM_IT_Update) != RESET)
- {
- GPIO_SetBits(GPIOD, GPIO_Pin_15);
- switch(p)
- {
- case 0:
- {
- p++;
- GPIO_ResetBits(GPIOD, GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14);
- break;
- }
- case 1:
- {
- p++;
- GPIO_ResetBits(GPIOD, GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14);
- break;
- }
- case 2:
- {
- p++;
- GPIO_ResetBits(GPIOD, GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14);
- break;
- }
- case 3:
- {
- p++;
- GPIO_ResetBits(GPIOD, GPIO_Pin_13| GPIO_Pin_14);
- break;
- }
- case 4:
- {
- p++;
- GPIO_ResetBits(GPIOD, GPIO_Pin_8|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12 | GPIO_Pin_13);
- break;
- }
- case 5:
- {
- p++;
- GPIO_ResetBits(GPIOD, GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14);
- break;
- }
- case 6:
- {
- p++;
- GPIO_ResetBits(GPIOD, GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14);
- break;
- }
- case 7:
- {
- p++;
- GPIO_ResetBits(GPIOD, GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14);
- break;
- }
- case 8:
- {
- p++;
- GPIO_ResetBits(GPIOD, GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14);
- break;
- }
- case 9:
- {
- p++;
- GPIO_ResetBits(GPIOD, GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14);
- break;
- }
- case 10:
- {
- p=0;
- }
- }
- TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
- }
- }
- int main(void)
- {
- /* GPIOD Periph clock enable */
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
- GPIO_InitTypeDef GPIO_InitStructure;
- /* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15;
- 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(GPIOD, &GPIO_InitStructure);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- TIM_OCInitTypeDef TIM_OCInitStructure12;
- /* PWM1 Mode configuration: */
- TIM_OCInitStructure12.TIM_OCMode = TIM_OCMode_PWM1;
- TIM_OCInitStructure12.TIM_OutputState = TIM_OutputState_Enable;
- TIM_OCInitStructure12.TIM_Pulse = 0;
- TIM_OCInitStructure12.TIM_OCPolarity = TIM_OCPolarity_High;
- TIM_OCInitTypeDef TIM_OCInitStructure13;
- /* Time base configuration */
- TIM_TimeBaseStructure.TIM_Period = 1049;
- TIM_TimeBaseStructure.TIM_Prescaler = 9999;
- TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
- TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
- TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
- TIM_OC1Init(TIM4, &TIM_OCInitStructure12);
- TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Enable);
- NVIC_InitTypeDef NVIC_InitStructure;
- // numer przerwania
- NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
- // priorytet główny
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
- // subpriorytet
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
- // uruchom dany kanał
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- // zapisz wypełnioną strukturę do rejestrów
- NVIC_Init(&NVIC_InitStructure);
- TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
- // zezwolenie na przerwania od przepełnienia dla timera 3
- TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
- // TIM4->CCR1 = 5;
- // TIM4->CCR2 = 2;
- // TIM4->CCR3 = 4;
- // TIM4->CCR4 = 7;
- TIM_Cmd(TIM4, ENABLE);
- for(;;);
- }