Guest User

main.c

a guest
Apr 18th, 2014
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.36 KB | None | 0 0
  1. #include "stm32f4xx.h"
  2. #include "stm32f4xx_conf.h"
  3. //#include "stm32f4xx_it.h"
  4.  
  5.  
  6. static void LED_Init (void);
  7. static void TIM_Config(void);
  8. static void EnableTimer3Interrupt(void);
  9.  
  10.  
  11. TIM_TimeBaseInitTypeDef timerInitStructure;
  12.  
  13.  
  14. void TIM3_IRQHandler(void)
  15.  {
  16.  if(TIM_GetITStatus(TIM3, TIM_IT_CC1) != RESET)
  17.  {
  18.  TIM_ClearITPendingBit(TIM3, TIM_IT_CC1);
  19.     GPIO_ToggleBits(GPIOG, GPIO_Pin_14);
  20.  }
  21.  }
  22.  
  23.  
  24.  
  25. int main(void){
  26.    
  27.  
  28.     TIM_Config();
  29.     EnableTimer3Interrupt();
  30.     LED_Init();
  31.  
  32.     GPIO_SetBits(GPIOG, GPIO_Pin_13);
  33.    
  34.     while(1){
  35.  
  36.     //GPIO_SetBits(GPIOG, GPIO_Pin_13);
  37.  
  38.  
  39.     }      
  40.        
  41. }
  42.  
  43.  
  44. /*--------------------------------------------------*/
  45.  
  46. void LED_Init (void) {
  47.  GPIO_InitTypeDef GPIO_InitStructure; // LED Port Info
  48.  
  49.  // Enable the port clock
  50.  RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOG, ENABLE);
  51.  
  52.  // Prepare the port info
  53.  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14; // Line 12
  54.  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; // As Output
  55.  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; // Push-pull
  56.  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz; // At 100MHz
  57.  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; // Without pull-up-down
  58.    
  59.     // Initialize the port
  60.  GPIO_Init (GPIOG, &GPIO_InitStructure); }
  61.  
  62.  
  63.  /*-------------------------------------------*/
  64.  
  65.  void EnableTimer3Interrupt(void)
  66.  {
  67.  NVIC_InitTypeDef NVIC_InitStructure;
  68.  
  69.      
  70.  /* Enable the TIM3 global Interrupt */
  71.  NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
  72.  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  73.  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  74.  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  75.  NVIC_Init(&NVIC_InitStructure);
  76.  }
  77.  
  78.  
  79.  /*--------------------------------------------------*/
  80.  
  81.  
  82.  void TIM_Config(void)
  83.  {
  84. /* TIM2 clock enable */  
  85. RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
  86. /* Time base configuration */
  87.     timerInitStructure.TIM_Prescaler = 40000;
  88.     timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
  89.     timerInitStructure.TIM_Period =500;
  90.     timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  91.     timerInitStructure.TIM_RepetitionCounter = 0;
  92.     TIM_TimeBaseInit(TIM3, &timerInitStructure);
  93.      
  94.          /* TIM Interrupts enable */
  95.      TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE);
  96.      /* TIM2 enable counter */
  97.     TIM_Cmd(TIM3, ENABLE);
  98.      
  99.  }
  100.  
  101.  
  102.  //end file
Advertisement
Add Comment
Please, Sign In to add comment