华清作业day48

发布时间:2023年12月26日

key.h

#ifndef __KEY__H__
#define __KEY__H__

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

void key1_init();
void key2_init();
void key3_init();

#endif

key.c

#include "key_it.h"

void key1_init()
{
    //使能GPIOF时钟
    RCC->MP_AHB4ENSETR |= (0x1<<5);

    //设置PF9管脚为输入
    GPIOF->MODER &= (~(0x3<<18));

    //设置PF9作为EXTI9事件的输入
    EXTI->EXTICR3 &= (~(0xff<<8)); 
    EXTI->EXTICR3 |= (0x5<<8);

    //设置下降沿使能检测EXTI9事件
    EXTI->FTSR1 |= (0x1<<9);

    //设置EXTI9事件不屏蔽
    EXTI->C1IMR1 |= (0x1<<9);

    //GICD使能EXTI9(99号)中断
    GICD->ISENABLER[3] |= (0x1<<3);

    //GICD 设置99号中断的优先级
    GICD->IPRIORITYR[24] &= (~(0x0<<27));

    //选择CPU0处理当前中断
   GICD->ITARGETSR[24] |= (0x1<<24);

    //全局使能组0中断被转发到GICC
    GICD->CTRL |= (0x1);

    //设置中断的优先级掩码
    GICC->PMR |= (0x1f<<3);

    //允许组0中断被CPU处理
    GICC->CTRL |= (0x1);
}
void key2_init()
{
    //设置PF8管脚为输入
    GPIOF->MODER &= (~(0x3<<16));

    //设置PF8作为EXTI8事件的输入
    EXTI->EXTICR3 &= (~(0xff));
    EXTI->EXTICR3 |= (0x5);

    //设置下降沿使能检测EXTI8事件
    EXTI->FTSR1 |= (0x1<<8);

    //设置EXTI8事件不屏蔽
    EXTI->C1IMR1 |= (0x1<<8);

    //GICD使能EXTI8(98号)中断
    GICD->ISENABLER[3] |= (0x1<<2);

    //GICD 设置98号中断的优先级
    GICD->IPRIORITYR[24] &= (~(0x01<<19));

    //选择CPU0处理当前中断
   GICD->ITARGETSR[24] |= (0x1<<16);
}
void key3_init()
{
    //设置PF7管脚为输入
    GPIOF->MODER &= (~(0x3<<14));

    //设置PF7作为EXTI7事件的输入
    EXTI->EXTICR2 &= (~(0xff<<24)); 
    EXTI->EXTICR2 |= (0x5<<24);

    //设置下降沿使能检测EXTI7事件
    EXTI->FTSR1 |= (0x1<<7);

    //设置EXTI7事件不屏蔽
    EXTI->C1IMR1 |= (0x1<<7);

    //GICD使能EXTI7(97号)中断
    GICD->ISENABLER[3] |= (0x1<<1);

    //GICD 设置97号中断的优先级
    GICD->IPRIORITYR[24] &= (~(0x02<<11));

    //选择CPU0处理当前中断
   GICD->ITARGETSR[24] |= (0x1<<8);

}

main.c

#include "key_it.h"

void delay(int ms)

{

    for(int i=0; i<ms; i++)

    {

        for(int j=0; j<2000; j++);

    }

}

int main()

{ 

     key1_init();

     key2_init();

     key3_init();

    while(1)

    {

        printf("asdasdasd\n");

        delay(1000);

    }

    return 0;

}

文章来源:https://blog.csdn.net/2301_78323287/article/details/135231825
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。