当前位置:   article > 正文

3.22号arm

3.22号arm

作业

实验现象,主函数每一秒循环字符m,当按下按键1,则串口输出1,按下按键2,串口输出2,按下按键3,串口输出3

main.c

  1. #include "uart4.h"
  2. #include "led.h"
  3. #include "key_in.h"
  4. int main()
  5. {
  6. uart4_init();
  7. all_led_init();
  8. key1_init();
  9. key2_init();
  10. key3_init();
  11. while(1)
  12. {
  13. putchar('m');
  14. delay(1000);
  15. }
  16. return 0;
  17. }

do_irq.c

  1. #include "stm32mp1xx_gic.h"
  2. #include "stm32mp1xx_exti.h"
  3. #include "uart4.h"
  4. extern void printf(const char *fmt, ...);
  5. unsigned int i = 0;
  6. void do_irq(void)
  7. {
  8. uart4_init();
  9. unsigned int irqno=GICC->IAR&0x3ff;
  10. switch(irqno)
  11. {
  12. case 99:
  13. putchar('1');
  14. GICD->ICPENDR[3] |=(0x1<<3);
  15. EXTI->FPR1 |=(0x1<<9);
  16. break;
  17. case 97:
  18. putchar('2');
  19. GICD->ICPENDR[3] |=(0x1<<1);
  20. EXTI->FPR1 |=(0x1<<7);
  21. break;
  22. case 98:
  23. putchar('3');
  24. GICD->ICPENDR[3] |=(0x1<<2);
  25. EXTI->FPR1 |=(0x1<<8);
  26. break;
  27. default:
  28. break;
  29. }
  30. GICC->EOIR |=irqno;
  31. }

key_in.c

  1. #include "key_in.h"
  2. void key1_init()
  3. {
  4. //使能GPIOF外设时钟
  5. RCC->MP_AHB4ENSETR |=(0x1<< 5);
  6. //pf9设为输出模式
  7. GPIOF->MODER &=(~(0x3<<18));
  8. //设置pf9管脚产生exti9事件
  9. EXTI->EXTICR3 &=(~(0xff<<8));
  10. EXTI->EXTICR3 |=(0x05<<8);
  11. //通过下降沿判断事件9是否产生
  12. EXTI->FTSR1 |=(0x1<<9);
  13. //取消exti9中断屏蔽
  14. EXTI->C1IMR1 |=(0x1<<9);
  15. //设置exti9全局中断使能
  16. GICD->ISENABLER[3] |=(0x1<<3);
  17. //设置中断优先级
  18. GICD->IPRIORITYR[24] &=(~(0x1f<<27));
  19. //设置cpu0处理中断
  20. GICD->ITARGETSR[24] |=(0x1<<24);
  21. //设置组0中断可以发送到GICC层
  22. GICD->CTRL |=(0x1);
  23. //设置中断优先级掩码
  24. GICC->PMR |= (0x1f<<3);
  25. //设置组0中断交给指定处理器处理
  26. GICC->CTRL |=0x1;
  27. }
  28. void key2_init()
  29. {
  30. //使能GPIOF外设时钟
  31. RCC->MP_AHB4ENSETR |=(0x1<< 5);
  32. //pf7设为输出模式
  33. GPIOF->MODER &=(~(0x3<<14));
  34. //设置pf7管脚产生exti7事件
  35. EXTI->EXTICR2 &=(~(0xff<<24));
  36. EXTI->EXTICR2 |=(0x05<<24);
  37. //通过下降沿判断事件7是否产生
  38. EXTI->FTSR1 |=(0x1<<7);
  39. //取消exti7中断屏蔽
  40. EXTI->C1IMR1 |=(0x1<<7);
  41. //设置exti7全局中断使能
  42. GICD->ISENABLER[3] |=(0x1<<1);
  43. //设置中断优先级
  44. GICD->IPRIORITYR[24] &=(~(0x1f<<11));
  45. //设置cpu0处理中断
  46. GICD->ITARGETSR[24] |=(0x1<<8);
  47. //设置组0中断可以发送到GICC层
  48. GICD->CTRL |=(0x1);
  49. //设置中断优先级掩码
  50. GICC->PMR |= (0x1f<<3);
  51. //设置组0中断交给指定处理器处理
  52. GICC->CTRL |=0x1;
  53. }
  54. void key3_init()
  55. {
  56. //使能GPIOF外设时钟
  57. RCC->MP_AHB4ENSETR |=(0x1<< 5);
  58. //pf8设为输出模式
  59. GPIOF->MODER &=(~(0x3<<16));
  60. //设置pf8管脚产生exti8事件
  61. EXTI->EXTICR3 &=(~(0xff));
  62. EXTI->EXTICR3 |=(0x05);
  63. //通过下降沿判断事件8是否产生
  64. EXTI->FTSR1 |=(0x1<<8);
  65. //取消exti8中断屏蔽
  66. EXTI->C1IMR1 |=(0x1<<8);
  67. //设置exti8全局中断使能
  68. GICD->ISENABLER[3] |=(0x1<<2);
  69. //设置中断优先级
  70. GICD->IPRIORITYR[24] &=(~(0x1f<<19));
  71. //设置cpu0处理中断
  72. GICD->ITARGETSR[24] |=(0x1<<16);
  73. //设置组0中断可以发送到GICC层
  74. GICD->CTRL |=(0x1);
  75. //设置中断优先级掩码
  76. GICC->PMR |= (0x1f<<3);
  77. //设置组0中断交给指定处理器处理
  78. GICC->CTRL |=0x1;
  79. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/316116
推荐阅读
相关标签
  

闽ICP备14008679号