ARM_key1按键按下,打印key1

这篇具有很好参考价值的文章主要介绍了ARM_key1按键按下,打印key1。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

include/key.h

#ifndef __KEY_H__
#define __KEY_H__

#include "stm32mp1xx_exti.h"
#include "stm32mp1xx_gic.h"
#include "stm32mp1xx_rcc.h"
#include "stm32mp1xx_gpio.h"



//对RCC/GPIO/EXTI进行初始化
void hal_key1_exit_init();



//对GIC章节进行初始化
void hal_key1_gic_init();


#endif
*/

#ifndef __KEY_H__
#define __KEY_H__

#include "stm32mp1xx_rcc.h"
#include "stm32mp1xx_gpio.h"
#include "stm32mp1xx_exti.h"
#include "stm32mp1xx_gic.h"




//对RCC/GPIO/EXTI章节的初始化
void hal_key1_exit_init();

//对GIC的初始化
void hal_key1_gic_init();





#endif

src/key.c

/*
#include "key.h"


//对RCC/GPIO/EXTI进行初始化
void hal_key1_exit_init()
{
	//RCC_MP_AHB4ENSETR寄存器使能gpio组控制器
	//[5] = 1
	RCC->MP_AHB4ENSETR |= (0x1 << 5);


	//GPIOx_MODER寄存器设置引脚为输入模式
	//pf9[19:18]=00
	//pf7[15:14]=00
	//pf8[17:16]=00
	GPIOF->MODER &= (~(0x3 << 18));


	//EXTI_EXTICR3寄存器,外部中断选择寄存器
	//选择和哪一个EXTI进行连接
	//EXTI9[15:8]=0x05
	//EXTI7[31:24]=0x05
	//EXTI8[7:0]=0x05
	EXTI->EXTICR3 &= (~(0xFF) << 8);
	EXTI->EXTICR3 |= (0x05 << 8);

	//EXTI_FTSR1寄存器,设置中断下降沿触发方式
	EXTI->FTSR1 |= (0x1 << 9);
	
	//EXTI_IMR1中断屏蔽选择寄存器
	EXTI->C1IMR1 |= (0b01 << 9);
}



//对GIC的初始化
void hal_key1_gic_init()
{
	//GICD的初始化
	//1.使能GICD层控制器
	GICD->CTRL |= 0x1;
	//2.设置GICD层的中断使能
	GICD->ISENABLER[3] |= (0x1 << 3);
	//3.设置GICD层中断优先级[31:27]
	GICD->IPRIORITYR[24] &= (~(0x1F << 27));
	//4.设置GICD层中断目标分配寄存器[24:25]
	GICD->ITARGETSR[24] |= (0x1 << 24);

	//GICC章节初始化
	//1.使能GICC层控制器
	GICC->CTRL |= 0x1;
	//2.设置GICC层中断优先级
	GICC->PMR |= (0x1F << 3);
}
*/
#include "key.h"

//对RCC/GPIO/EXTI章节的初始化
void hal_key1_exit_init()
{
	//RCC
	RCC->MP_AHB4ENSETR |= (0x1 << 5);
	//GPIO设置输入模式
	GPIOF->MODER &= (~(0x3 << 18));
	//EXTI
	//1.外部中断选择寄存器,选择与哪个EXTI(16)链接
	EXTI->EXTICR3 &= (~(0xff << 8));
	EXTI->EXTICR3 |= (0x5 << 8);
	//2.设置中断下降沿触发方式
	EXTI->FTSR1 |= (0x1 << 9);
	//3.中断屏蔽选择寄存器
	EXTI->C1IMR1 |= (0b01 << 9);



}

//对GIC的初始化
void hal_key1_gic_init()
{
	//GICD的初始化
	//1.使能GICD层控制器
	GICD->CTRL |= 0x1;
	//2.设置GICD层的中断使能
	GICD->ISENABLER[3] |= (0x1 << 3);
	//3.设置GICD层中断优先级
	GICD->IPRIORITYR[24] &= (~(0x1F << 27));
	//4.设置GICD层中断目标分配寄存器
	GICD->ITARGETSR[24] |= (0x1 << 24);

	//GICC章节初始化
	//1.使能GICC层控制器
	GICC->CTRL |= 0x1;
	//2.设置GICC层中断优先级
	GICC->PMR |= (0x1 << 3);
}

main.c

/*
#include "key.h"


//对RCC/GPIO/EXTI进行初始化
void hal_key1_exit_init()
{
	//RCC_MP_AHB4ENSETR寄存器使能gpio组控制器
	//[5] = 1
	RCC->MP_AHB4ENSETR |= (0x1 << 5);


	//GPIOx_MODER寄存器设置引脚为输入模式
	//pf9[19:18]=00
	//pf7[15:14]=00
	//pf8[17:16]=00
	GPIOF->MODER &= (~(0x3 << 18));


	//EXTI_EXTICR3寄存器,外部中断选择寄存器
	//选择和哪一个EXTI进行连接
	//EXTI9[15:8]=0x05
	//EXTI7[31:24]=0x05
	//EXTI8[7:0]=0x05
	EXTI->EXTICR3 &= (~(0xFF) << 8);
	EXTI->EXTICR3 |= (0x05 << 8);

	//EXTI_FTSR1寄存器,设置中断下降沿触发方式
	EXTI->FTSR1 |= (0x1 << 9);
	
	//EXTI_IMR1中断屏蔽选择寄存器
	EXTI->C1IMR1 |= (0b01 << 9);
}



//对GIC的初始化
void hal_key1_gic_init()
{
	//GICD的初始化
	//1.使能GICD层控制器
	GICD->CTRL |= 0x1;
	//2.设置GICD层的中断使能
	GICD->ISENABLER[3] |= (0x1 << 3);
	//3.设置GICD层中断优先级[31:27]
	GICD->IPRIORITYR[24] &= (~(0x1F << 27));
	//4.设置GICD层中断目标分配寄存器[24:25]
	GICD->ITARGETSR[24] |= (0x1 << 24);

	//GICC章节初始化
	//1.使能GICC层控制器
	GICC->CTRL |= 0x1;
	//2.设置GICC层中断优先级
	GICC->PMR |= (0x1F << 3);
}
*/
#include "key.h"

//对RCC/GPIO/EXTI章节的初始化
void hal_key1_exit_init()
{
	//RCC
	RCC->MP_AHB4ENSETR |= (0x1 << 5);
	//GPIO设置输入模式
	GPIOF->MODER &= (~(0x3 << 18));
	//EXTI
	//1.外部中断选择寄存器,选择与哪个EXTI(16)链接
	EXTI->EXTICR3 &= (~(0xff << 8));
	EXTI->EXTICR3 |= (0x5 << 8);
	//2.设置中断下降沿触发方式
	EXTI->FTSR1 |= (0x1 << 9);
	//3.中断屏蔽选择寄存器
	EXTI->C1IMR1 |= (0b01 << 9);



}

//对GIC的初始化
void hal_key1_gic_init()
{
	//GICD的初始化
	//1.使能GICD层控制器
	GICD->CTRL |= 0x1;
	//2.设置GICD层的中断使能
	GICD->ISENABLER[3] |= (0x1 << 3);
	//3.设置GICD层中断优先级
	GICD->IPRIORITYR[24] &= (~(0x1F << 27));
	//4.设置GICD层中断目标分配寄存器
	GICD->ITARGETSR[24] |= (0x1 << 24);

	//GICC章节初始化
	//1.使能GICC层控制器
	GICC->CTRL |= 0x1;
	//2.设置GICC层中断优先级
	GICC->PMR |= (0x1 << 3);
}
ubuntu@vivi:06-key-c$ ^C
ubuntu@vivi:06-key-c$ cat 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()
{	
	hal_key1_exit_init();
	hal_key1_gic_init();

	while(1)
	{
	}
	return 0;
}

 src/do_irq.c

#include "key.h"
extern void printf(const char *fmt, ...);

void do_irq(void) 
{
	unsigned int num;
	num = GICC->IAR & 0x3ff;
	switch (num)
	{
	case 99:
		printf("key1 press#####\n");
		//1.消除EXTI层中断挂起标志位
		EXTI->FPR1 |= (0x1 << 9);
		//2.消除GICD层的中断挂起标志位
		GICD->ICPENDR[3] |= (0x1 << 3);
		break;
	case 98:
		break;
	case 97:
		break;
	}
	//3.清除获取到的中断号
	GICC->EOIR |= num;
}

result 

 ARM_key1按键按下,打印key1,arm开发,单片机,嵌入式硬件

 文章来源地址https://www.toymoban.com/news/detail-534786.html

 

 

到了这里,关于ARM_key1按键按下,打印key1的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包