arm_按键中断控制LED、蜂鸣器、风扇
功能函数
#include "led.h"
void led_set()
{
// 使能rcc
RCC->MP_AHB4ENSETR |= (0x01 << 4);
// 设置输出
GPIOE->MODER &= (~(0x03 << 20));
GPIOE->MODER |= (0x1 << 20);
// 设置推挽输出
GPIOE->OTYPER &= (~(0x01 << 10));
// 无上拉下拉
GPIOE->PUPDR &= (~(0x3 << 20));
// 设置输出速率 低速
GPIOE->OSPEEDR &= (~(0x3 << 20));
GPIOE->ODR ^= (0x1 << 10);
}
// 蜂鸣器
void SPI_set()
{
RCC->MP_AHB4ENSETR |= (0x01 << 1);
// 设置输出
GPIOB->MODER &= (~(0x03 << 12));
GPIOB->MODER |= (0x1 << 12);
// 设置推挽输出
GPIOB->OTYPER &= (~(0x01 << 6));
// 无上拉下拉
GPIOB->PUPDR &= (~(0x3 << 12));
// 设置输出速率
GPIOB->OSPEEDR |= (0x3 << 12);
GPIOB->ODR ^= (0x1 << 6);
}
// 风扇 PE9
void FAN_set()
{
RCC->MP_AHB4ENSETR |= (0x01 << 4);
// 设置输出
GPIOE->MODER &= (~(0x03 << 18));
GPIOE->MODER |= (0x1 << 18);
// 设置推挽输出
GPIOE->OTYPER &= (~(0x01 << 9));
// 无上拉下拉
GPIOE->PUPDR &= (~(0x3 << 18));
// 设置输出速率
GPIOE->OSPEEDR |= (0x3 << 18);
GPIOE->ODR ^= (0x1 << 9);
}
中断处理函数
#include "key_it.h"
#include "led.h"
extern void printf(const char *fmt, ...);
unsigned int i = 0;
void do_irq(void)
{
int irqno; // 保存中断号
irqno = GICC->IAR & 0x3FF;
printf("%d\n", irqno);
switch (irqno)
{
case 97:
/* key2 */
printf("key2 INT\n");
SPI_set();
GICD->ICPENDR[3] |=(0x1<<1) ;
EXTI->FPR1 |= (0x1 << 7);
break;
case 98:
/* key3 */
printf("key3 INT\n");
FAN_set();
GICD->ICPENDR[3] |=(0x1<<2) ;
EXTI->FPR1 |= (0x1 << 8);
break;
case 99:
/* key1 LED1 PE10亮*/
printf("key1 INT\n");
led_set();
GICD->ICPENDR[3] |=(0x1<<3) ;
EXTI->FPR1 |= (0x1 << 9);
break;
}
// 清除中断
GICC->EOIR = irqno;
}