HC32F460的中断有多种类型,针对Io口输入中断,是有几个步骤可以归纳的。
1、按照管脚配好外部中断通道.
2、设置时钟和滤波。
3、设置边沿触发方式。
4、管脚初始化。
5、管脚中断启用。
6、配置中断向量。
7、配置中断处理子程序入口。
8、注册中断。
9、设置中断优先级。
10、中断使能启用。
例程如下,配置PORTB 05脚外中断的初始化函数:
stc_exint_config_t stcExtiConfig;
stc_irq_regi_conf_t stcIrqRegiConf;
stc_port_init_t stcPortInit;
/* configuration structure initialization */
MEM_ZERO_STRUCT(stcExtiConfig);
MEM_ZERO_STRUCT(stcIrqRegiConf);
MEM_ZERO_STRUCT(stcPortInit);
/**************************************************************************/
/* External Int Ch.5 */
/**************************************************************************/
stcExtiConfig.enExitCh = ExtiCh05;
/* Filter setting */
stcExtiConfig.enFilterEn = Enable;
stcExtiConfig.enFltClk = Pclk3Div8;
stcExtiConfig.enExtiLvl = ExIntFallingEdge;
EXINT_Init(&stcExtiConfig);
/* Set External Int */
MEM_ZERO_STRUCT(stcPortInit);
stcPortInit.enExInt = Enable;
PORT_Init(KEY15_PORT, KEY15_PIN, &stcPortInit);
/* Select External Int Ch.5 */
stcIrqRegiConf.enIntSrc = INT_PORT_EIRQ5;
/* Register External Int to Vect.No.000 */
stcIrqRegiConf.enIRQn = Int005_IRQn;
/* Callback function */
stcIrqRegiConf.pfnCallback = &ExtInt05_Callback;
/* Registration IRQ */
enIrqRegistration(&stcIrqRegiConf);
/* Clear pending */
NVIC_ClearPendingIRQ(stcIrqRegiConf.enIRQn);
/* Set priority */
NVIC_SetPriority(stcIrqRegiConf.enIRQn, DDL_IRQ_PRIORITY_DEFAULT);
/* Enable NVIC */
NVIC_EnableIRQ(stcIrqRegiConf.enIRQn);
中断处理函数如下:
void ExtInt05_Callback(void)
{
if (Set == EXINT_IrqFlgGet(ExtiCh05))
{
u32ExtInt05Count++;
/* clear int request flag */
EXINT_IrqFlgClr(ExtiCh05);
}
}