Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.90 KB | None | 0 0
  1. // lab 4b zad 1
  2. // zad 2 nie dziala
  3. /**
  4. ******************************************************************************
  5. * @file main.c
  6. * @author Ac6
  7. * @version V1.0
  8. * @date 01-December-2013
  9. * @brief Default main function.
  10. ******************************************************************************
  11. */
  12.  
  13.  
  14. #include "stm32f4xx.h"
  15. #include "stm32f4_discovery.h"
  16. #include "stm32f4xx_syscfg.h"
  17.  
  18. void EXTI0_IRQHandler(void)
  19. {
  20. if(EXTI_GetITStatus(EXTI_Line0) != RESET)
  21. {
  22. // GPIO_ToggleBits(GPIOD, GPIO_Pin_0 | GPIO_Pin_8);
  23. TIM_Cmd(TIM4, ENABLE);
  24. // TIM_SetCounter(TIM4, 0);
  25. // EXTI_ClearITPendingBit(EXTI_Line0);
  26.  
  27. }
  28. }
  29.  
  30. void TIM4_IRQHandler(void)
  31. {
  32. if(TIM_GetITStatus(TIM4, TIM_IT_Update) != RESET)
  33. {
  34. if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)==1)
  35. {
  36. GPIO_ToggleBits(GPIOD, GPIO_Pin_0 | GPIO_Pin_8);
  37. TIM_Cmd(TIM4, DISABLE);
  38. TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
  39. EXTI_ClearITPendingBit(EXTI_Line0);
  40. }
  41. }
  42. }
  43.  
  44. int main(void)
  45. {
  46. // zad 1
  47.  
  48. RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
  49.  
  50. RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  51.  
  52. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  53.  
  54. NVIC_InitTypeDef NVIC_InitStructure;
  55. // numer przerwania
  56. NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
  57. // priorytet główny
  58. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
  59. // subpriorytet
  60. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
  61. // uruchom dany kanał
  62. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  63. // zapisz wypełnioną strukturę do rejestrów
  64. NVIC_Init(&NVIC_InitStructure);
  65.  
  66.  
  67. EXTI_InitTypeDef EXTI_InitStructure;
  68. // wybór numeru aktualnie konfigurowanej linii przerwań
  69. EXTI_InitStructure.EXTI_Line = EXTI_Line0;
  70. // wybór trybu - przerwanie bądź zdarzenie
  71. EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  72. // wybór zbocza, na które zareaguje przerwanie
  73. EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  74. // uruchom daną linię przerwań
  75. EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  76. // zapisz strukturę konfiguracyjną przerwań zewnętrznych do rejestrów
  77. EXTI_Init(&EXTI_InitStructure);
  78.  
  79. // podłączenie danego pinu portu do kontrolera przerwań
  80. SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
  81.  
  82. // wyswietlacz
  83. GPIO_InitTypeDef GPIO_InitStructure;
  84. /* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */
  85. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_8 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
  86. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  87. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  88. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  89. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  90. GPIO_Init(GPIOD, &GPIO_InitStructure);
  91.  
  92. GPIO_SetBits(GPIOD, GPIO_Pin_8);
  93. GPIO_ResetBits(GPIOD, GPIO_Pin_0);
  94. GPIO_ResetBits(GPIOD, GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7);
  95.  
  96. // zad 2
  97. // timer
  98. TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure4;
  99. TIM_TimeBaseStructure4.TIM_Period = 16800-1;
  100. TIM_TimeBaseStructure4.TIM_Prescaler = 1000-1;
  101. TIM_TimeBaseStructure4.TIM_ClockDivision = TIM_CKD_DIV1;
  102. TIM_TimeBaseStructure4.TIM_CounterMode = TIM_CounterMode_Up;
  103. TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure4);
  104. TIM_Cmd(TIM4, DISABLE);
  105.  
  106. // przerwanie
  107. NVIC_InitTypeDef NVIC_InitStructure2;
  108. // numer przerwania
  109. NVIC_InitStructure2.NVIC_IRQChannel = TIM4_IRQn;
  110. // priorytet główny
  111. NVIC_InitStructure2.NVIC_IRQChannelPreemptionPriority = 0x00;
  112. // subpriorytet
  113. NVIC_InitStructure2.NVIC_IRQChannelSubPriority = 0x00;
  114. // uruchom dany kanał
  115. NVIC_InitStructure2.NVIC_IRQChannelCmd = ENABLE;
  116. // zapisz wypełnioną strukturę do rejestrów
  117. NVIC_Init(&NVIC_InitStructure2);
  118.  
  119.  
  120. for(;;)
  121. {
  122.  
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement