Facebook
From Thundering Crane, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 245
  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.  
  16. int main(void)
  17. {
  18.  
  19.         RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  20. //      RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
  21.         RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  22.         RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
  23.  
  24.         GPIO_InitTypeDef GPIO_InitStructure;
  25.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 |GPIO_Pin_15;
  26.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  27.         GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  28.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  29.         GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  30.         GPIO_Init(GPIOD, &GPIO_InitStructure);
  31.  
  32.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3  | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
  33.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  34.         GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  35.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  36.         GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  37.         GPIO_Init(GPIOA, &GPIO_InitStructure);
  38.  
  39.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
  40.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  41.         GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  42.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  43.         GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  44.         GPIO_Init(GPIOC, &GPIO_InitStructure);
  45.  
  46.  
  47.         TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
  48.         /* Time base configuration 20ms */
  49.         TIM_TimeBaseStructure.TIM_Period = 4999;
  50.         TIM_TimeBaseStructure.TIM_Prescaler = 8399;
  51.         TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  52.         TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  53.         TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
  54.        
  55.        
  56.         TIM_OCInitTypeDef TIM_OCInitStructure;
  57.         /* PWM1 Mode configuration: */
  58.         TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
  59.         TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  60.         TIM_OCInitStructure.TIM_Pulse = 0;
  61.         TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
  62.  
  63.         TIM_Cmd(TIM3, ENABLE);
  64.  
  65.         //GPIO_ResetBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 |GPIO_Pin_15);
  66.         int check=0;
  67.         GPIO_SetBits(GPIOD, GPIO_Pin_12);
  68.         for(;;) {
  69.  
  70.  
  71.  
  72.  
  73.  
  74.                 if(TIM_GetFlagStatus(TIM3, TIM_FLAG_Update)) {
  75.  
  76.                         if(check==0)
  77.                         {
  78.                                 GPIO_ResetBits(GPIOD, GPIO_Pin_12);// | GPIO_Pin_2  | GPIO_Pin_3  | GPIO_Pin_4  | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7);
  79.                                 //GPIO_SetBits(GPIOD, GPIO_Pin_12);// | GPIO_Pin_2  | GPIO_Pin_3  | GPIO_Pin_4  | GPIO_Pin_5 | GPIO_Pin_6);
  80.                                 check=1;
  81.                         }
  82.                         else if(check==1)
  83.                         {
  84.                                 //GPIO_ResetBits(GPIOD, GPIO_Pin_12); // | GPIO_Pin_2  | GPIO_Pin_3  | GPIO_Pin_4  | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7);
  85.                                 GPIO_SetBits(GPIOD, GPIO_Pin_12);//, GPIO_Pin_1 | GPIO_Pin_2);
  86.                                 check=0;
  87.                         }
  88.                         TIM_ClearFlag(TIM3, TIM_FLAG_Update);
  89.  
  90.  
  91.                 }
  92.         }
  93.  
  94.  
  95. }
  96.