Advertisement
Guest User

Untitled

a guest
Oct 25th, 2018
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Eiffel 2.31 KB | None | 0 0
  1.  
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. #include "stm32f10x.h"
  81.  
  82. void TIM2_IRQHandler()
  83. {
  84.  if (TIM_GetITStatus(TIM2, TIM_IT_Update) == SET)
  85.  {
  86.  TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
  87.  
  88.  if (GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_5))
  89.  GPIO_ResetBits(GPIOA, GPIO_Pin_5);
  90.  else
  91.  GPIO_SetBits(GPIOA, GPIO_Pin_5);
  92.  
  93.  // zapal wszystkie diody
  94.  GPIO_SetBits(GPIOC, GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3);
  95.  }
  96.  
  97.  if (TIM_GetITStatus(TIM2, TIM_IT_CC1) == SET)
  98.  {
  99.  TIM_ClearITPendingBit(TIM2, TIM_IT_CC1);
  100.  GPIO_ResetBits(GPIOC, GPIO_Pin_0);
  101.  }
  102.  if (TIM_GetITStatus(TIM2, TIM_IT_CC2) == SET)
  103.  {
  104.  TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);
  105.  GPIO_ResetBits(GPIOC, GPIO_Pin_1);
  106.  }
  107.  if (TIM_GetITStatus(TIM2, TIM_IT_CC3) == SET)
  108.  {
  109.  TIM_ClearITPendingBit(TIM2, TIM_IT_CC3);
  110.  GPIO_ResetBits(GPIOC, GPIO_Pin_2);
  111.  }
  112.  if (TIM_GetITStatus(TIM2, TIM_IT_CC4) == SET)
  113.  {
  114.  TIM_ClearITPendingBit(TIM2, TIM_IT_CC4);
  115.  GPIO_ResetBits(GPIOC, GPIO_Pin_3);
  116.  }
  117. }
  118.  
  119. int main(void)
  120. {
  121.  GPIO_InitTypeDef gpio;
  122.  TIM_TimeBaseInitTypeDef tim;
  123.  NVIC_InitTypeDef nvic;
  124.  
  125.  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);
  126.  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
  127.  
  128.  GPIO_StructInit(&gpio);
  129.  gpio.GPIO_Pin = GPIO_Pin_5;
  130.  gpio.GPIO_Mode = GPIO_Mode_Out_PP;
  131.  GPIO_Init(GPIOA, &gpio);
  132.  
  133.  gpio.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3;
  134.  GPIO_Init(GPIOC, &gpio);
  135.  
  136.  TIM_TimeBaseStructInit(&tim);
  137.  tim.TIM_CounterMode = TIM_CounterMode_Up;
  138.  tim.TIM_Prescaler = 64000 - 1;
  139.  tim.TIM_Period = 1000 - 1;
  140.  TIM_TimeBaseInit(TIM2, &tim);
  141.  
  142.  TIM_ITConfig(TIM2, TIM_IT_Update|TIM_IT_CC1|TIM_IT_CC2|TIM_IT_CC3|TIM_IT_CC4, ENABLE);
  143.  TIM_Cmd(TIM2, ENABLE);
  144.  
  145.  TIM_SetCompare1(TIM2, 100);
  146.  TIM_SetCompare2(TIM2, 200);
  147.  TIM_SetCompare3(TIM2, 500);
  148.  TIM_SetCompare4(TIM2, 900);
  149.  
  150.  nvic.NVIC_IRQChannel = TIM2_IRQn;
  151.  nvic.NVIC_IRQChannelPreemptionPriority = 0;
  152.  nvic.NVIC_IRQChannelSubPriority = 0;
  153.  nvic.NVIC_IRQChannelCmd = ENABLE;
  154.  NVIC_Init(&nvic);
  155.  
  156.  while (1) {
  157.  }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement