10.4-国庆-作业

 中断实验(A7核/M4核)

A7核 

main.c

#include "key.h"
extern void printf(const char *fmt, ...);
void delay_ms(int ms)
{
	int i,j;
	for(i = 0; i < ms;i++)
		for (j = 0; j < 1800; j++);
}
int main()
{      
	//1.初始化EXTI1层
	pf9_exti_init();
	pf7_exti_init();
	pf8_exti_init();
	//2.初始化GICD层
	pf9_gicd_init();
	pf7_gicd_init();
	pf8_gicd_init();
	//3.初始化GICC层
	pf9_gicc_init();
	pf7_gicc_init();
	pf8_gicc_init();
	while(1)
	{
	}
	return 0;
}

key.c

#include "key.h"

/*********KEY1---PF9**********/
//初始化EXTI1层
void pf9_exti_init()
{
	/********RCC章节初始化********/
	//1.设置GPIO组时钟使能
	RCC->MP_AHB4ENSETR |= (0x1 << 5);
	/*******GPIO章节初始化**********/
	//1.设置PF9引脚为输入模式
	GPIOF->MODER &= (~(0x3 << 18));
	/*******EXTI章节初始化********/
	//1.设置PF9引脚和EXTI9控制器进行连接
	EXTI->EXTICR3 &= (~(0xff << 8));
	EXTI->EXTICR3 |= (0x05 << 8);
	//2.设置PF9引脚监测方式下降沿
	EXTI->FTSR1 |= (0x1 << 9);
	//3.设置PF9引脚中断不屏蔽
	EXTI->C1IMR1 |= (0x1 << 9);
}
//初始化GICD层
void pf9_gicd_init()
{
	//1.设置GICD层全局中断使能寄存器
	GICD->CTRL |= (0x1 << 0);
	//2.设置GICD层中断使能寄存器
	GICD->ISENABLER[3] |= (0x1 << 3);
	//3.设置GICD层中断优先级寄存器
	GICD->IPRIORITYR[24] |= (0x1 << 27); 
	//4.设置GICD层中断目标分配寄存器
	GICD->ITARGETSR[24] |= (0x01 << 24);
}
//初始化GICC层
void pf9_gicc_init()
{
	//1.设置GICC层全局中断使能寄存器
	GICC->CTRL |= (0x1 << 0);
	//2.设置GICD层中断优先级寄存器
	GICC->PMR |= (0x2 << 3);
}


/*********KEY2---PF7**********/
void pf7_exti_init()
{
	/********RCC章节初始化********/
	//1.设置GPIO组时钟使能
	RCC->MP_AHB4ENSETR |= (0x1 << 5);
	/*******GPIO章节初始化**********/
	//1.设置PF7引脚为输入模式
	GPIOF->MODER &= (~(0x3 << 14));
	/*******EXTI章节初始化********/
	//1.设置PF7引脚和EXTI7控制器进行连接
	EXTI->EXTICR2 &= (~(0xff << 24));
	EXTI->EXTICR2 |= (0x05 << 24);
	//2.设置PF7引脚监测方式下降沿
	EXTI->FTSR1 |= (0x1 << 7);
	//3.设置PF7引脚中断不屏蔽
	EXTI->C1IMR1 |= (0x1 << 7);
}
//初始化GICD层
void pf7_gicd_init()
{
	//1.设置GICD层全局中断使能寄存器
	GICD->CTRL |= (0x1 << 0);
	//2.设置GICD层中断使能寄存器
	GICD->ISENABLER[3] |= (0x1 << 1);
	//3.设置GICD层中断优先级寄存器
	GICD->IPRIORITYR[24] |= (0x1 << 11); 
	//4.设置GICD层中断目标分配寄存器
	GICD->ITARGETSR[24] |= (0x01 << 8);
}
//初始化GICC层
void pf7_gicc_init()
{
	//1.设置GICC层全局中断使能寄存器
	GICC->CTRL |= (0x1 << 0);
	//2.设置GICD层中断优先级寄存器
	GICC->PMR |= (0x2 << 3);
}

/*********KEY3---PF8**********/
void pf8_exti_init()
{
	/********RCC章节初始化********/
	//1.设置GPIO组时钟使能
	RCC->MP_AHB4ENSETR |= (0x1 << 5);
	/*******GPIO章节初始化**********/
	//1.设置PF8引脚为输入模式
	GPIOF->MODER &= (~(0x3 << 16));
	/*******EXTI章节初始化********/
	//1.设置PF8引脚和EXTI8控制器进行连接
	EXTI->EXTICR3 &= (~(0xff << 0));
	EXTI->EXTICR3 |= (0x05 << 0);
	//2.设置PF8引脚监测方式下降沿
	EXTI->FTSR1 |= (0x1 << 8);
	//3.设置PF8引脚中断不屏蔽
	EXTI->C1IMR1 |= (0x1 << 8);
}
//初始化GICD层
void pf8_gicd_init()
{
	//1.设置GICD层全局中断使能寄存器
	GICD->CTRL |= (0x1 << 0);
	//2.设置GICD层中断使能寄存器
	GICD->ISENABLER[3] |= (0x1 << 2);
	//3.设置GICD层中断优先级寄存器
	GICD->IPRIORITYR[24] |= (0x1 << 19); 
	//4.设置GICD层中断目标分配寄存器
	GICD->ITARGETSR[24] |= (0x01 << 16);
}
//初始化GICC层
void pf8_gicc_init()
{
	//1.设置GICC层全局中断使能寄存器
	GICC->CTRL |= (0x1 << 0);
	//2.设置GICD层中断优先级寄存器
	GICC->PMR |= (0x2 << 3);
}

key.h

#ifndef __KEY_H__
#define __KEY_H__
#include "stm32mp1xx_rcc.h"
#include "stm32mp1xx_gpio.h"
#include "stm32mp1xx_exti.h"
#include "stm32mp1xx_gic.h"

/*********KEY1---PF9**********/

//初始化EXTI1层
void pf9_exti_init();
//初始化GICD层
void pf9_gicd_init();
//初始化GICC层
void pf9_gicc_init();

/*********KEY2---PF7**********/
void pf7_exti_init();
//初始化GICD层
void pf7_gicd_init();
//初始化GICC层
void pf7_gicc_init();

/*********KEY3---PF8**********/
void pf8_exti_init();
//初始化GICD层
void pf8_gicd_init();
//初始化GICC层
void pf8_gicc_init();

#endif

M4核

gpio.c

void HAL_GPIO_EXTI_Rising_Callback(uint16_t GPIO_Pin)
{
	switch(GPIO_Pin)
	{
		case GPIO_PIN_5:
			HAL_GPIO_TogglePin(GPIOF,GPIO_PIN_10);
		break;
		case GPIO_PIN_12:
			HAL_GPIO_TogglePin(GPIOE,GPIO_PIN_10);
		break;
		case GPIO_PIN_15:
			HAL_GPIO_TogglePin(GPIOE,GPIO_PIN_8);
		break;
	}
}

你可能感兴趣的:(c++,蓝桥杯,c语言)