基于stmf103的外部中断实验
文章目录
外部中断
中断就是主程序在正常执行时,CPU发出一个中断请求,然后程序就会跳到中断子程序去执行,执行完后会返回主程序。
一、概述
组成结构
1-15中断号用于系统异常
16开始是外部中断
<font color=#999AAA GPIO与中断线的映射关系
1、GPIO引脚0对应的是外部中断0
2、一个中断对应了9个IO口(PA0~PA9)
3、同一时刻一个中断只能对应一个IO口,不能PA0链接了外部中断0,PB0再链接外部中断0
二、使用步骤
1.GPIO端口设置为外部中断输入----参考stm32f10x_gpio.c
代码如下(示例):
void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
2.把引脚与EXIT0链接----参考stm32f10x_gpio.c
代码如下(示例):
void GPIO_EXTILineConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource);
函数原型:
/**
* @brief Selects the GPIO pin used as EXTI Line.
* @param GPIO_PortSource: selects the GPIO port to be used as source for EXTI lines.
* This parameter can be GPIO_PortSourceGPIOx where x can be (A..G).
* @param GPIO_PinSource: specifies the EXTI line to be configured.
* This parameter can be GPIO_PinSourcex where x can be (0..15).
* @retval None
*/
void GPIO_EXTILineConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource)
{
uint32_t tmp = 0x00;
/* Check the parameters */
assert_param(IS_GPIO_EXTI_PORT_SOURCE(GPIO_PortSource));
assert_param(IS_GPIO_PIN_SOURCE(GPIO_PinSource));
tmp = ((uint32_t)0x0F) << (0x04 * (GPIO_PinSource & (uint8_t)0x03));
AFIO->EXTICR[GPIO_PinSource >> 0x02] &= ~tmp;
AFIO->EXTICR[GPIO_PinSource >> 0x02] |