Facebook
From Filip, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 281
  1. /**
  2.   ******************************************************************************
  3.   * @file    main.c
  4.   * @author  Ac6
  5.   * @version V1.0
  6.   * @date    01-December-2013
  7.   * @brief   Default main function.
  8.   ******************************************************************************
  9. */
  10.  
  11.  
  12. #include "stm32f4xx.h"
  13. #include "stm32f4_discovery.h"
  14.  
  15. int p = 0 ;
  16.     void TIM4_IRQHandler(void)
  17.  
  18.     {
  19.         GPIO_SetBits(GPIOD, GPIO_Pin_8| GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14);
  20.                  if(TIM_GetITStatus(TIM4, TIM_IT_Update) != RESET)
  21.  
  22.                  {
  23.  
  24.                      GPIO_SetBits(GPIOD, GPIO_Pin_15);
  25.  
  26.                      switch(p)
  27.                      {
  28.                      case 0:
  29.                      {
  30.                          p++;
  31.                          GPIO_ResetBits(GPIOD,  GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14);
  32.                          break;
  33.                      }
  34.                      case 1:
  35.                      {
  36.                          p++;
  37.  
  38.                          GPIO_ResetBits(GPIOD,  GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14);
  39.                          break;
  40.                      }
  41.                      case 2:
  42.                                           {
  43.                                                   p++;
  44.  
  45.                                                                          GPIO_ResetBits(GPIOD,  GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14);
  46.  
  47.                                                  break;
  48.                                           }
  49.                      case 3:
  50.                                           {
  51.                                                   p++;
  52.  
  53.                                                                          GPIO_ResetBits(GPIOD,  GPIO_Pin_13| GPIO_Pin_14);
  54.  
  55.                                                  break;
  56.                                           }
  57.                      case 4:
  58.                                           {
  59.                                                   p++;
  60.  
  61.                                                                          GPIO_ResetBits(GPIOD,  GPIO_Pin_8|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12 | GPIO_Pin_13);
  62.  
  63.                                                  break;
  64.                                           }
  65.                      case 5:
  66.                                           {
  67.                                                   p++;
  68.  
  69.                                                                          GPIO_ResetBits(GPIOD,  GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14);
  70.  
  71.                                                  break;
  72.                                           }
  73.                      case 6:
  74.                                           {
  75.                                                   p++;
  76.  
  77.                                                                          GPIO_ResetBits(GPIOD,  GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14);
  78.  
  79.                                                  break;
  80.                                           }
  81.                      case 7:
  82.                                           {
  83.                                                   p++;
  84.  
  85.                                                                          GPIO_ResetBits(GPIOD,  GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14);
  86.  
  87.                                                  break;
  88.                                           }
  89.                      case 8:
  90.                      {
  91.                          p++;
  92.  
  93.                                                  GPIO_ResetBits(GPIOD,  GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14);
  94.  
  95.                          break;
  96.                      }
  97.                      case 9:
  98.                                           {
  99.                                                   p++;
  100.  
  101.                                                                          GPIO_ResetBits(GPIOD,  GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14);
  102.  
  103.                                               break;
  104.                                           }
  105.  
  106.                      case 10:
  107.                      {
  108.                          p=0;
  109.                      }
  110.                      }
  111.                         TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
  112.  
  113.  
  114.                  }
  115.  
  116.     }
  117.  
  118. int main(void)
  119. {
  120.  
  121.          /* GPIOD Periph clock enable */
  122.             RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  123.  
  124.  
  125.  
  126.  
  127.  
  128.     GPIO_InitTypeDef  GPIO_InitStructure;
  129.     /* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */
  130.     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;
  131.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  132.     GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  133.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  134.     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  135.     GPIO_Init(GPIOD, &GPIO_InitStructure);
  136.  
  137.     RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
  138.    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
  139.  
  140.     TIM_OCInitTypeDef TIM_OCInitStructure12;
  141.  
  142.             /* PWM1 Mode configuration: */
  143.  
  144.             TIM_OCInitStructure12.TIM_OCMode = TIM_OCMode_PWM1;
  145.  
  146.             TIM_OCInitStructure12.TIM_OutputState = TIM_OutputState_Enable;
  147.  
  148.             TIM_OCInitStructure12.TIM_Pulse = 0;
  149.  
  150.             TIM_OCInitStructure12.TIM_OCPolarity = TIM_OCPolarity_High;
  151.  
  152.             TIM_OCInitTypeDef TIM_OCInitStructure13;
  153.  
  154.         /* Time base configuration */
  155.  
  156.         TIM_TimeBaseStructure.TIM_Period = 1049;
  157.  
  158.         TIM_TimeBaseStructure.TIM_Prescaler = 9999;
  159.  
  160.         TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  161.  
  162.         TIM_TimeBaseStructure.TIM_CounterMode =  TIM_CounterMode_Up;
  163.  
  164.         TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
  165.  
  166.     TIM_OC1Init(TIM4, &TIM_OCInitStructure12);
  167.     TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Enable);
  168.  
  169.     NVIC_InitTypeDef NVIC_InitStructure;
  170.  
  171.     // numer przerwania
  172.  
  173.     NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
  174.  
  175.     // priorytet główny
  176.  
  177.     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
  178.  
  179.     // subpriorytet
  180.  
  181.     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
  182.  
  183.     // uruchom dany kanał
  184.  
  185.     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  186.  
  187.     // zapisz wypełnioną strukturę do rejestrów
  188.  
  189.     NVIC_Init(&NVIC_InitStructure);
  190.  
  191.     TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
  192.  
  193.     // zezwolenie na przerwania od przepełnienia dla timera 3
  194.     TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203. //    TIM4->CCR1 = 5;
  204. //    TIM4->CCR2 = 2;
  205. //    TIM4->CCR3 = 4;
  206. //    TIM4->CCR4 = 7;
  207.  
  208.     TIM_Cmd(TIM4, ENABLE);
  209.  
  210.     for(;;);
  211.  
  212.  
  213.  
  214. }
  215.