Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stm32f4xx.h"
- /* Set variables used */
- GPIO_InitTypeDef GPIO_InitStruct;
- EXTI_InitTypeDef EXTI_InitStruct;
- NVIC_InitTypeDef NVIC_InitStruct;
- /* Configure pin to be interrupts */
- void Configure_PA0(void)
- {
- /* Enable clock for GPIOA */
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
- /* Enable clock for SYSCFG */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
- /* Set pin as input */
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
- GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
- GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;
- GPIO_Init(GPIOA, &GPIO_InitStruct);
- /* Tell system that you will use PA0 for EXTI_Line0 */
- SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
- /* PA0 is connected to EXTI_Line0 */
- EXTI_InitStruct.EXTI_Line = EXTI_Line0;
- /* Enable interrupt */
- EXTI_InitStruct.EXTI_LineCmd = ENABLE;
- /* Interrupt mode */
- EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
- /* Triggers on rising and falling edge */
- EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
- /* Add to EXTI */
- EXTI_Init(&EXTI_InitStruct);
- /* Add IRQ vector to NVIC */
- /* PA0 is connected to EXTI_Line0, which has EXTI0_IRQn vector */
- NVIC_InitStruct.NVIC_IRQChannel = EXTI0_IRQn;
- /* Set priority */
- NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0x00;
- /* Set sub priority */
- NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0x00;
- /* Enable interrupt */
- NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
- /* Add to NVIC */
- NVIC_Init(&NVIC_InitStruct);
- }
- void GPIOD_Initialize(void)
- {
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);
- GPIO_InitStruct.GPIO_Pin=GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
- GPIO_InitStruct.GPIO_Mode=GPIO_Mode_OUT;
- GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_InitStruct.GPIO_OType=GPIO_OType_PP;
- GPIO_InitStruct.GPIO_PuPd=GPIO_PuPd_UP;
- GPIO_Init(GPIOD,&GPIO_InitStruct);
- }
- void EXTI0_IRQHandler(void)
- {
- /* Make sure that interrupt flag is set */
- if (EXTI_GetITStatus(EXTI_Line0) != RESET)
- {
- GPIO_ResetBits(GPIOD,GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);
- /* Clear interrupt flag */
- EXTI_ClearITPendingBit(EXTI_Line0);
- }
- }
- void main()
- {
- SystemInit();
- Configure_PA0();
- GPIOD_Initialize();
- GPIO_SetBits(GPIOD,GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);
- while(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement