Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.31 KB | None | 0 0
  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. #include "stm32f4xx.h"
  12. #include "stm32f4_discovery.h"
  13. #include "stm32f4xx_syscfg.h"
  14.  
  15.     void EXTI0_IRQHandler(void)
  16.     {
  17.                  if(EXTI_GetITStatus(EXTI_Line0) != RESET)
  18.                  {
  19.                     // miejsce na kod wywoływany w momencie wystąpienia przerwania
  20.                      GPIO_ToggleBits(GPIOD, GPIO_Pin_12);
  21.     // wyzerowanie flagi wyzwolonego przerwania
  22.                      EXTI_ClearITPendingBit(EXTI_Line0);
  23.                   }
  24.     }
  25. int main(void)
  26. {
  27.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  28.     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  29.  
  30.     GPIO_InitTypeDef GPIO_InitStructure;
  31.     GPIO_InitStructure.GPIO_Pin =
  32.     GPIO_Pin_12;
  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(GPIOD, &GPIO_InitStructure);
  38.  
  39.  
  40.     NVIC_InitTypeDef NVIC_InitStructure;
  41.     // numer przerwania
  42.     NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
  43.     // priorytet główny
  44.     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
  45.     // subpriorytet
  46.     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
  47.     // uruchom dany kanał
  48.     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  49.     // zapisz wypełnioną strukturę do rejestrów
  50.     NVIC_Init(&NVIC_InitStructure);
  51.  
  52.     EXTI_InitTypeDef EXTI_InitStructure;
  53.     // wybór numeru aktualnie konfigurowanej linii przerwań
  54.     EXTI_InitStructure.EXTI_Line = EXTI_Line0;
  55.     // wybór trybu - przerwanie bądź zdarzenie
  56.     EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  57.     // wybór zbocza, na które zareaguje przerwanie
  58.     EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  59.     // uruchom daną linię przerwań
  60.     EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  61.     // zapisz strukturę konfiguracyjną przerwań zewnętrznych do rejestrów
  62.     EXTI_Init(&EXTI_InitStructure);
  63.  
  64.     // podłączenie danego pinu portu do kontrolera przerwań
  65.     SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
  66.  
  67.  
  68.  
  69.     for(;;)
  70.     {
  71.  
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement