exti.c
来自「keil for arm 下测试:MCBSTM32测试程序的外部中断程序」· C语言 代码 · 共 65 行
C
65 行
/*----------------------------------------------------------------------------
* Name: Exti.c
* Purpose: EXTI usage for STM32
* Version: V1.00
*----------------------------------------------------------------------------
* This file is part of the uVision/ARM development tools.
* This software may only be used under the terms of a valid, current,
* end user licence from KEIL for a compatible version of KEIL software
* development tools. Nothing else gives you the right to use this software.
*
* Copyright (c) 2005-2007 Keil Software. All rights reserved.
*----------------------------------------------------------------------------*/
#include <stm32f10x_lib.h> // STM32F10x Library Definitions
#include "STM32_Init.h" // STM32 Initialization
unsigned int ledPosExti = 0; // led position (from 0..7) for EXTI
unsigned int ledExti = 0;
/*----------------------------------------------------------------------------
EXTI0 Interrupt Handler
*----------------------------------------------------------------------------*/
void EXTI0_IRQHandler(void)
{
if (EXTI->PR & (1<<0)) { // EXTI13 interrupt pending?
if ((ledExti ^=1) == 0)
GPIOB->ODR &= ~(1 << (ledPosExti+8)); // switch off LED
else
GPIOB->ODR |= (1 << (ledPosExti+8)); // switch on LED
EXTI->PR |= (1<<0); // clear pending interrupt
}
}
/*----------------------------------------------------------------------------
EXTI15..10 Interrupt Handler
*----------------------------------------------------------------------------*/
void EXTI15_10_IRQHandler(void)
{
if (EXTI->PR & (1<<13)) { // EXTI0 interrupt pending?
if ((ledExti ^=1) == 0)
GPIOB->ODR &= ~(1 << (ledPosExti+8)); // switch off LED
else
GPIOB->ODR |= (1 << (ledPosExti+8)); // switch on LED
EXTI->PR |= (1<<13); // clear pending interrupt
}
}
/*----------------------------------------------------------------------------
MAIN function
*----------------------------------------------------------------------------*/
int main (void) {
stm32_Init (); // STM32 setup
while (1) { // Loop forever
;
} // end while
} // end main
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?