新手入门
- 积分
- 5
- 金钱
- 5
- 注册时间
- 2021-10-3
- 在线时间
- 1 小时
|
1金钱
中断不发生是什么原因。 代码如下。 Key0 接PE4上。PE4初始化为输入模式,上拉,Line4设置为 下降沿触发。

#include "stm32f10x.h"
#include "core_cm3.h"
#include "usart.h"
#include "delay.h"
int xt=0;
//void int_enable(void);
void EXTI4_IRQHandler(void)
{
printf("key0 pressed!\r\n");
GPIOE->ODR&=~(0x1<<5);
GPIOE->ODR|=xt<<5;
xt^=0x1;
EXTI->PR|=0x1<<4; //清中断线4
}
int main()
{
//pe.4 line4 interrupt
//xt=0;
uart_init(72,115200);
int i=3000000;
//初始化 PE.4 输入模式 上拉 Key0 按键下触发中断
RCC->APB2ENR |= (0x1<<6);
GPIOE->CRL = (GPIOE->CRL & ~(0xf<<16))| (0x8<<16);
GPIOE->ODR |= 0x1<<4 ;
//IO复用 使用AFIO时钟
RCC->APB2ENR |= 0x1; //enable rcc AFIO
AFIO->EXTICR[1] = (AFIO->EXTICR[1] & ~(0xf))|0x4;
EXTI->FTSR |= 0x1<<4; //下降沿触发
EXTI->IMR |= 0x1<<4; //使能中断
int tmp;
tmp=SCB->AIRCR;
SCB->AIRCR = (tmp & 0xf8ff)|(0x5<<8)|0x05fa0000; //group 2
NVIC->IP[4] = 0x8<<4; //设置优先级
NVIC->ISER[0] |= 0x1<<4; //使能中断
//led: pe.5 output LED PE5初始化
GPIOE->CRL=(GPIOE->CRL & ~(0xf<<20))|(0x3<<20);
GPIOE->ODR|=(0x1<<5);
GPIOE->ODR&=~(0x1<<5);
while(1)
{
i=30000000;
printf("hello world! %d\r\n",xt);
for(;i--;);
}
return 0;
}
|
|