按键中断方式测试不成功,也许是还有哪里没有设置好。主函数中的代码如下:
int main(void)
{
/* Initializes MCU, drivers and middleware */
SYSTEM_Initialize();
/* 开启按键中断 */
IO_PF6_SetDigitalInput(); //设置数字输入方式
IO_PF6_EnableInterruptForLowLevelSensing();//启用低电平感应中断
/* Replace with your application code */
while (1){
if(keys>0){
// if(IO_PF6_GetValue()==0){
keyok = 1; //锁定按键,此时不接收新按键
DELAY_milliseconds(50); //延时防抖
if(IO_PF6_GetValue()==0){
if(direction==1){
delays = delays << 1;
if(delays > 1000){
direction = 0;
delays = 800;
}
}
else{
delays = delays >> 1;
if(delays < 100){
direction = 1;
delays = 100;
}
}
}
keyok = 0; //释放按键锁定
}
IO_PF5_Toggle();
DELAY_milliseconds(delays);
}
}
中断处理函数中的代码如下:
void PORTF_IO_PF6_DefaultInterruptHandler(void)
{
// add your PORTF_IO_PF6 interrupt custom code
if(keyok==0)
keys++;
// or set custom function using PORTF_IO_PF6_SetInterruptHandler()
}
|