• DSP2335的按键输入key工程笔记


    配置输入

    时钟

    方向

    下拉

    本文使用的是矩阵按键  12 13 14 为物理上拉输入,48 49 50为输出;

    可以考虑输入AQ滤波;里面没有加;

    1. /*
    2. * key.c
    3. *
    4. * Created on: 2023年11月19日
    5. * Author: peng
    6. */
    7. #include"key.h"
    8. #include"led1.h"
    9. void key_init(void)
    10. {
    11. EALLOW;
    12. SysCtrlRegs.PCLKCR3.bit.GPIOINENCLK=1;
    13. GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 0;
    14. GpioCtrlRegs.GPADIR.bit.GPIO12 = 0;//输入
    15. GpioCtrlRegs.GPAPUD.bit.GPIO12 = 0;
    16. GpioCtrlRegs.GPAMUX1.bit.GPIO13 = 0;
    17. GpioCtrlRegs.GPADIR.bit.GPIO13 = 0;//输入
    18. GpioCtrlRegs.GPAPUD.bit.GPIO13 = 0;
    19. GpioCtrlRegs.GPAMUX1.bit.GPIO14 = 0;
    20. GpioCtrlRegs.GPADIR.bit.GPIO14 = 0;//输入
    21. GpioCtrlRegs.GPAPUD.bit.GPIO14 = 0;
    22. //输出
    23. GpioCtrlRegs.GPBMUX2.bit.GPIO48 = 0;
    24. GpioCtrlRegs.GPBDIR.bit.GPIO48 = 1;//
    25. GpioCtrlRegs.GPBPUD.bit.GPIO48 = 0;
    26. GpioCtrlRegs.GPBMUX2.bit.GPIO49 = 0;
    27. GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1;//
    28. GpioCtrlRegs.GPBPUD.bit.GPIO49 = 0;
    29. GpioCtrlRegs.GPBMUX2.bit.GPIO50 = 0;
    30. GpioCtrlRegs.GPBDIR.bit.GPIO50 = 1;//
    31. GpioCtrlRegs.GPBPUD.bit.GPIO50 = 0;
    32. EDIS;
    33. GpioDataRegs.GPBSET.bit.GPIO48 = 1;
    34. GpioDataRegs.GPBSET.bit.GPIO49 = 1;
    35. GpioDataRegs.GPBSET.bit.GPIO50 = 1;
    36. }
    37. unsigned char read_row()
    38. {
    39. unsigned char temp=0;
    40. temp=( GpioDataRegs.GPADAT.bit.GPIO12<<0| GpioDataRegs.GPADAT.bit.GPIO13<<1| GpioDataRegs.GPADAT.bit.GPIO14<<2);
    41. return temp;
    42. }
    43. unsigned char read_line()
    44. {
    45. unsigned char temp=0;
    46. temp= (
    47. GpioDataRegs.GPBDAT.bit.GPIO48
    48. |((GpioDataRegs.GPBDAT.bit.GPIO49&0x01)<<1)
    49. |((GpioDataRegs.GPBDAT.bit.GPIO50&0x01)<<2)
    50. );
    51. return temp;
    52. }
    53. void _SCAN_line(char x)
    54. {
    55. GpioDataRegs.GPBDAT.bit.GPIO48=~((long)0x01&x);
    56. GpioDataRegs.GPBDAT.bit.GPIO49=~(((long)0x02&x)>>1);
    57. GpioDataRegs.GPBDAT.bit.GPIO50=~(((long)0x04&x)>>2);
    58. }
    59. char SCAN_row ()
    60. {
    61. return GpioDataRegs.GPADAT.bit.GPIO12<<0| GpioDataRegs.GPADAT.bit.GPIO13<<1| GpioDataRegs.GPADAT.bit.GPIO14<<2;
    62. }
    63. char key_scan()
    64. {
    65. char key = 0;
    66. unsigned char i = 0,tt=0x1;
    67. unsigned int temp=0;
    68. unsigned char p48=0,p49=0,p50=0;
    69. tt=~tt;
    70. static char key_up_flag = 0,key_breakup=0;
    71. for ( i = 0; i < 3; i++)
    72. {
    73. switch (i)//列扫描
    74. {
    75. case 0: _SCAN_line(1);
    76. break;
    77. case 1: _SCAN_line(2);
    78. break;
    79. case 2: _SCAN_line(4);
    80. break;
    81. default:
    82. break;
    83. }
    84. if ( (temp=(SCAN_row() & 0x07) )!= 0x07 )//被按下
    85. {
    86. DELAY_US(10000);
    87. if ((temp=(SCAN_row() & 0x07)) != 0x07)
    88. {
    89. key_up_flag = 1;
    90. switch (temp=( ~temp)&0x07 )
    91. {
    92. case 1: key = (temp - 1) * 3 + i+1; key_breakup = key;return 0;
    93. case 2: key = (temp- 1) * 3 + i+1 ; key_breakup = key;return 0;
    94. case 4: key = (temp - 1) * 3 + i+1; key_breakup = key;return 0;
    95. default:key = 0;
    96. break;
    97. }
    98. // key_breakup = key;
    99. }
    100. }
    101. else
    102. {
    103. if (key_up_flag == 1)
    104. {
    105. key_up_flag = 0;
    106. return key_breakup;
    107. }
    108. }
    109. }
    110. return 0;
    111. }
    112. void key_LED()//按键控制LED
    113. {
    114. //char key = 0;
    115. switch (key_scan())
    116. {
    117. case 1: LED1_TOGGLE; break;
    118. case 2: LED2_TOGGLE; break;
    119. case 3: LED3_TOGGLE; break;
    120. default: break;
    121. }
    122. }

  • 相关阅读:
    git拉取代码到本地及提交代码
    计算机网络笔记1 概述
    【数据结构】二叉树的顺序结构-堆
    Python入门系列(七)开发常说的“累”与“对象”
    线程中开启线程池异步处理,主副线程设置执行顺序
    记:谷歌开发者大会2022——共码未来
    【竞赛那些事】追忆本科首次参加数学建模获得第一名特等奖
    时间复杂度(Time Complexity)
    docker安装使用xdebug
    JY61P.C
  • 原文地址:https://blog.csdn.net/qq_36658033/article/details/134498279