12.26

key_it.h 

#ifndef __KEY_IT_H__
#define __KEY_IT_H__
#include"stm32mp1xx_gpio.h"
#include"stm32mp1xx_gic.h"
#include"stm32mp1xx_exti.h"
#include "stm32mp1xx_rcc.h"
 void delay(int ms);

void key1_it_config();
void key2_it_config();
void key3_it_config();
#endif

do_irq.c

#include"key_it.h"
#include"led.h"
extern void printf(const char *fmt, ...);
unsigned int i = 0;
void do_irq(void) 
{
    all_led_init();
    int irqno=(GICC->IAR &0X3FF);
    switch(irqno)
    {
        case 99:
        {
            printf("im key1\n");
           
            led1_on(); 
            delay(1000);
           
            GICD->ICPENDR[3] |=(0X1<<3);
            EXTI->FPR1 |=(0X1<<9);
            led1_off();
        }break;
        case 98:
        {
            printf("im key3\n");
            led2_on();
            delay(1000);

            GICD->ICPENDR[3] |=(0X1<<2);
            EXTI->FPR1 |=(0X1<<8);
            led2_off();
        }break;
        case 97: 
        {
            printf("im key2\n");
           
            led3_on();
            delay(1000);
            GICD->ICPENDR[3] |=(0X1<<1);
            EXTI->FPR1 |=(0X1<<7);
            led3_off();
        }break;
    }
    GICC->EOIR=irqno;
}

led.c

#include "led.h"
void all_led_init()
{
    RCC_GPIO |= (0X3<<4);//时钟使能
    GPIOE_MODER &=(~(0X3<<20));//设置PE10输出
    GPIOE_MODER |= (0X1<<20);
    //设置PE10为推挽输出
    GPIOE_OTYPER &=(~(0x1<<10));
    //PE10为低速输出
    GPIOE_OSPEEDR &= (~(0x3<<20));
    //设置无上拉下拉
    GPIOE_PUPDR &= (~(0x3<<20));
 
    //LED2
    GPIOF_MODER &=(~(0X3<<20));//设置Pf10输出
    GPIOF_MODER |= (0X1<<20);
    //设置Pf10为推挽输出
    GPIOF_OTYPER &=(~(0x1<<10));
    //Pf10为低速输出
    GPIOF_OSPEEDR &= (~(0x3<<20));
    //设置无上拉下拉
    GPIOF_PUPDR &= (~(0x3<<20));
 
    //LED3
    GPIOE_MODER &=(~(0X3<<16));//设置PE8输出
    GPIOE_MODER |= (0X1<<16);
    //设置PE8为推挽输出
    GPIOE_OTYPER &=(~(0x1<<8));
    //PE8为低速输出
    GPIOE_OSPEEDR &= (~(0x3<16));
    //设置无上拉下拉
    GPIOE_PUPDR &= (~(0x3<<16));
}
void led1_on()
{
    GPIOE_ODR |= (0x1<<10);
}
 
void led1_off()
{
    GPIOE_ODR &= (~(0x1<<10));
}
void led2_on()
{
    GPIOF_ODR |= (0x1<<10);
}
 
void led2_off()
{
    GPIOF_ODR &= (~(0x1<<10));
}
void led3_on()
{
    GPIOE_ODR |= (0x1<<8);
}
 
void led3_off()
{
    GPIOE_ODR &= (~(0x1<<8));
}

main.c

e "led.h"



void delay(int ms)

{

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

	{

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

		{

		}

	}

}



int main()

{

	key1_it_config();

	key2_it_config();

	key3_it_config();

	while (1)

	{

		delay(1000);

		printf("hello world\n");

	}



	return 0;

}

led.h

#include "key_it.h"

void key1_it_config()
{
    //使能GPIOF时钟
    RCC->MP_AHB4ENSETR |=(0x1<<5);
    //设置PF9管脚为输入
    GPIOF->MODER &=(~(0X3<<18));
    //设置PF9作为EXTI9事件的输入
    EXTI->EXTICR3 &=(~(0X1F<<8));
    EXTI->EXTICR3 |=(0X05<<8);
    //设置下降沿使能检测EXTI9事件
    EXTI->FTSR1 |=(0X1<<9);
    //设置EXTI9事件不屏蔽
    EXTI->C1IMR1 |=(0X1<<9);
    //GICD设置99号中断
    GICD->ISENABLER[3] |=(0X1<<3);
    //GICD设置99号中断的优先级
    GICD->IPRIORITYR[24] &=(~(0X1F<<27));
    //CPU0处理当前中断
    GICD->ITARGETSR[24] |=(0X1<<24);
    //全局使能组0中断被转发到GICC
    GICD->CTRL |=(0X1);
    //设置中断的优先级掩码
    GICC->PMR |=(0X1F<<3);
    //允许组0中断被CPU处理
     GICC->CTRL |=(0X1);
}
void key2_it_config()//PF7
{
      //使能GPIOF时钟
    RCC->MP_AHB4ENSETR |=(0x1<<5);
    //设置PF7管脚为输入
    GPIOF->MODER &=(~(0X3<<14));
    //设置PF7作为EXTI7事件的输入
    EXTI->EXTICR2 &=(~(0X1F<<24));
    EXTI->EXTICR2 |=(0X05<<24);
    //设置下降沿使能检测EXTI7事件
    EXTI->FTSR1 |=(0X1<<7);
    //设置EXTI7事件不屏蔽
    EXTI->C1IMR1 |=(0X1<<7);
    //GICD设置97号中断
    GICD->ISENABLER[3] |=(0X1<<1);
    //GICD设置97号中断的优先级????
    GICD->IPRIORITYR[24] &=(~(0X1F<<11));
    //CPU0处理当前中断
    GICD->ITARGETSR[24] |=(0X1<<8);
    //全局使能组0中断被转发到GICC
    GICD->CTRL |=(0X1);
    //设置中断的优先级掩码
    GICC->PMR |=(0X1F<<3);
    //允许组0中断被CPU处理
     GICC->CTRL |=(0X1);
}
void key3_it_config()//PF8
{
      //使能GPIOF时钟
    RCC->MP_AHB4ENSETR |=(0x1<<5);
    //设置PF8管脚为输入
    GPIOF->MODER &=(~(0X3<<16));
    //设置PF8作为EXTI8事件的输入
    EXTI->EXTICR3 &=(~(0X1F));
    EXTI->EXTICR3 |=(0X05);
    //设置下降沿使能检测EXTI8事件
    EXTI->FTSR1 |=(0X1<<8);
    //设置EXTI9事件不屏蔽
    EXTI->C1IMR1 |=(0X1<<8);
    //GICD设置98号中断
    GICD->ISENABLER[3] |=(0X1<<2);
    //GICD设置98号中断的优先级
    GICD->IPRIORITYR[24] &=(~(0X1F<<19));
    //CPU0处理当前中断???
    GICD->ITARGETSR[24] |=(0X1<<16);
    //全局使能组0中断被转发到GICC
    GICD->CTRL |=(0X1);
    //设置中断的优先级掩码
    GICC->PMR |=(0X1F<<3);
    //允许组0中断被CPU处理
     GICC->CTRL |=(0X1);
}

led.h

#ifndef __LED_H_
#define __LED_H_

#define RCC_GPIO     (*(unsigned int *)0x50000a28)
#define GPIOE_MODER     (*(unsigned int *)0x50006000)
#define GPIOF_MODER     (*(unsigned int *)0x50007000)
#define GPIOE_OTYPER     (*(unsigned int *)0x50006004)
#define GPIOF_OTYPER     (*(unsigned int *)0x50007004)
#define GPIOF_OSPEEDR     (*(unsigned int *)0x50007008)
#define GPIOE_OSPEEDR     (*(unsigned int *)0x50006008)
#define GPIOF_PUPDR      (*(unsigned int *)0x5000700C)
#define GPIOE_PUPDR     (*(unsigned int *)0x5000600C)
#define GPIOE_ODR     (*(unsigned int *)0x50007014)
#define GPIOF_ODR     (*(unsigned int *)0x50006014)

void led1_on();
void led2_on();
void led3_on();
void led1_off();
void led2_off();
void led3_off();
 void delay(int ms);
 void all_led_init();
#endif

你可能感兴趣的:(javascript,前端,开发语言,大作业)