只能说太懒了。在ST提供的STM8固件库下面\STM8SFWLib v1.1.1\FWLib\examples\GPIO\GPIO_IOToggle_InterruptMode目录有个例程:
/** @page GPIO_IOToggle_InterruptMode LEDs toggling, Button reading in interrupt mode
@par Example description
This example provides a short description of how to use the GPIO peripheral:
- Initialization of the GPIO in output and input modes with interrupt
- LEDs toggling
- Button state reading in interrupt mode
将BUTTON_PIN(PC3)初始化为带中断的输入口。
/* Initialize I/O in Input Mode with Interrupt */
GPIO_Init(BUTTON_PORT, BUTTON_PIN, GPIO_MODE_IN_FL_IT);
/* Initialize the Interrupt sensitivity */
EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOC, EXTI_SENSITIVITY_FALL_ONLY);
enableInterrupts();
记得IO中断是同一端口共用同一中断源,触发方式有下降沿和低电平触发、仅上升沿触发、仅下降沿触发、上升沿和下降沿触发四种方式,需要改EXTI_CRx寄存器,对应的就是上面的EXTI_SetExtIntSensitivity()函数第二个参数。
typedef enum {
EXTI_SENSITIVITY_FALL_LOW = (u8)0x00, /*!< Interrupt on Falling edge and Low level */
EXTI_SENSITIVITY_RISE_ONLY = (u8)0x01, /*!< Interrupt on Rising edge only */
EXTI_SENSITIVITY_FALL_ONLY = (u8)0x02, /*!< Interrupt on Falling edge only */
EXTI_SENSITIVITY_RISE_FALL = (u8)0x03 /*!< Interrupt on Rising and Falling edges */
} EXTI_Sensitivity_TypeDef; |