Experiment 4 External interruption experiment
1 Development environment
- STM32F407ZGT6
- Wedge uVision 5
2 Experiment content
- After pressing KEY_UP → KEY2 → KEY2 → KEY2 → KEY1 → KEY1 → KEY0 , the state of LED0 changes.
- If this order is not followed, the state of LED0 does not change.
比如按下的状态是:
1、KEY_UP → KEY1 → KEY2 → KEY0 → KEY1
2、KEY_UP → KEY2 → KEY2 → KEY1 → KEY0
则LED0不切换
3 Experimental code
[exti.c]
int isBling=0;//用于判断LED0是否到了需要改变状态的时候
//外部中断0服务程序
void EXTI0_IRQHandler(void)
{
delay_ms(10); //消抖
if(WK_UP==1)
{
if(isBling==0)
isBling++;
else
isBling=0;
}
EXTI_ClearITPendingBit(EXTI_Line0); //清除LINE0上的中断标志位
}
//外部中断2服务程序
void EXTI2_IRQHandler(void)
{
delay_ms(10); //消抖
if(KEY2==0)
{
if(isBling<5)
isBling++;
else
isBling=0;
}
EXTI_ClearITPendingBit(EXTI_Line2);//清除LINE2上的中断标志位
}
//外部中断3服务程序
void EXTI3_IRQHandler(void)
{
delay_ms(10); //消抖
if(KEY1==0)
{
if(isBling<7)
isBling++;
else
isBling=0;
}
EXTI_ClearITPendingBit(EXTI_Line3); //清除LINE3上的中断标志位
}
//外部中断4服务程序
void EXTI4_IRQHandler(void)
{
delay_ms(10); //消抖
if(KEY0==0)
{
if(isBling==6)
LED0=!LED0;
else
isBling=0;
}
EXTI_ClearITPendingBit(EXTI_Line4);//清除LINE4上的中断标志位
}
4 matters needing attention
- The design of this experiment is rather simple, so the universality is poor
- Consider using arrays for experiments