Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- ******************************************************************************
- * @file main.c
- * @author Ac6
- * @version V1.0
- * @date 01-December-2013
- * @brief Default main function.
- ******************************************************************************
- */
- #include "stm32f4xx.h"
- #include "stm32f4_discovery.h"
- #include "stm32f4xx_syscfg.h"
- void EXTI0_IRQHandler(void)
- {
- if(EXTI_GetITStatus(EXTI_Line0) != RESET)
- {
- // miejsce na kod wywoływany w momencie wystąpienia przerwania
- GPIO_ToggleBits(GPIOD, GPIO_Pin_12);
- // wyzerowanie flagi wyzwolonego przerwania
- EXTI_ClearITPendingBit(EXTI_Line0);
- }
- }
- int main(void)
- {
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin =
- GPIO_Pin_12;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_Init(GPIOD, &GPIO_InitStructure);
- NVIC_InitTypeDef NVIC_InitStructure;
- // numer przerwania
- NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
- // priorytet główny
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
- // subpriorytet
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
- // uruchom dany kanał
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- // zapisz wypełnioną strukturę do rejestrów
- NVIC_Init(&NVIC_InitStructure);
- EXTI_InitTypeDef EXTI_InitStructure;
- // wybór numeru aktualnie konfigurowanej linii przerwań
- EXTI_InitStructure.EXTI_Line = EXTI_Line0;
- // wybór trybu - przerwanie bądź zdarzenie
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- // wybór zbocza, na które zareaguje przerwanie
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
- // uruchom daną linię przerwań
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- // zapisz strukturę konfiguracyjną przerwań zewnętrznych do rejestrów
- EXTI_Init(&EXTI_InitStructure);
- // podłączenie danego pinu portu do kontrolera przerwań
- SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
- for(;;)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement