Advertisement
Guest User

Untitled

a guest
Oct 25th, 2018
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Eiffel 2.01 KB | None | 0 0
  1. #include "stm32f10x.h"
  2.  
  3. void TIM2_IRQHandler()
  4. {
  5.  if (TIM_GetITStatus(TIM2, TIM_IT_Update) == SET)
  6.  {
  7.  TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
  8.  
  9.  if (GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_5))
  10.  GPIO_ResetBits(GPIOA, GPIO_Pin_5);
  11.  else
  12.  GPIO_SetBits(GPIOA, GPIO_Pin_5);
  13.  
  14.  // zapal wszystkie diody
  15.  GPIO_SetBits(GPIOC, GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3);
  16.  }
  17.  
  18.  if (TIM_GetITStatus(TIM2, TIM_IT_CC1) == SET)
  19.  {
  20.  TIM_ClearITPendingBit(TIM2, TIM_IT_CC1);
  21.  GPIO_ResetBits(GPIOC, GPIO_Pin_0);
  22.  }
  23.  if (TIM_GetITStatus(TIM2, TIM_IT_CC2) == SET)
  24.  {
  25.  TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);
  26.  GPIO_ResetBits(GPIOC, GPIO_Pin_1);
  27.  }
  28.  if (TIM_GetITStatus(TIM2, TIM_IT_CC3) == SET)
  29.  {
  30.  TIM_ClearITPendingBit(TIM2, TIM_IT_CC3);
  31.  GPIO_ResetBits(GPIOC, GPIO_Pin_2);
  32.  }
  33.  if (TIM_GetITStatus(TIM2, TIM_IT_CC4) == SET)
  34.  {
  35.  TIM_ClearITPendingBit(TIM2, TIM_IT_CC4);
  36.  GPIO_ResetBits(GPIOC, GPIO_Pin_3);
  37.  }
  38. }
  39.  
  40. int main(void)
  41. {
  42.  GPIO_InitTypeDef gpio;
  43.  TIM_TimeBaseInitTypeDef tim;
  44.  NVIC_InitTypeDef nvic;
  45.  
  46.  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);
  47.  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
  48.  
  49.  GPIO_StructInit(&gpio);
  50.  gpio.GPIO_Pin = GPIO_Pin_5;
  51.  gpio.GPIO_Mode = GPIO_Mode_Out_PP;
  52.  GPIO_Init(GPIOA, &gpio);
  53.  
  54.  gpio.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3;
  55.  GPIO_Init(GPIOC, &gpio);
  56.  
  57.  TIM_TimeBaseStructInit(&tim);
  58.  tim.TIM_CounterMode = TIM_CounterMode_Up;
  59.  tim.TIM_Prescaler = 64000 - 1;
  60.  tim.TIM_Period = 1000 - 1;
  61.  TIM_TimeBaseInit(TIM2, &tim);
  62.  
  63.  TIM_ITConfig(TIM2, TIM_IT_Update|TIM_IT_CC1|TIM_IT_CC2|TIM_IT_CC3|TIM_IT_CC4, ENABLE);
  64.  TIM_Cmd(TIM2, ENABLE);
  65.  
  66.  TIM_SetCompare1(TIM2, 100);
  67.  TIM_SetCompare2(TIM2, 200);
  68.  TIM_SetCompare3(TIM2, 500);
  69.  TIM_SetCompare4(TIM2, 900);
  70.  
  71.  nvic.NVIC_IRQChannel = TIM2_IRQn;
  72.  nvic.NVIC_IRQChannelPreemptionPriority = 0;
  73.  nvic.NVIC_IRQChannelSubPriority = 0;
  74.  nvic.NVIC_IRQChannelCmd = ENABLE;
  75.  NVIC_Init(&nvic);
  76.  
  77.  while (1) {
  78.  }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement