key.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #include "key.h"
  2. /***************************************************************
  3. ** 功能:核心板按键端口初始化
  4. ** 参数:无
  5. ** 返回值:无
  6. ****************************************************************/
  7. void key_Init(void)
  8. {
  9. GPIO_InitTypeDef GPIO_InitStructure;
  10. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
  11. GPIO_InitStructure.GPIO_Pin=GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
  12. GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;//上拉输入模式
  13. GPIO_Init(GPIOB,&GPIO_InitStructure);
  14. }
  15. /***************************************************************
  16. ** 功能:核心板led灯初始化
  17. ** 参数:无
  18. ** 返回值:无
  19. ****************************************************************/
  20. void LED_Init(void)
  21. {
  22. GPIO_InitTypeDef GPIO_InitStructure;
  23. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);
  24. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11; //LED1-4 端口配置
  25. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
  26. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
  27. GPIO_Init(GPIOD, &GPIO_InitStructure); //根据设定参数初始化
  28. // GPIO_SetBits(GPIOD,GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11);//LED1-4 输出高
  29. GPIO_ResetBits(GPIOD,GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11); //LED1-4 熄灭
  30. }
  31. /***************************************************************
  32. ** 功能:核心板蜂鸣器初始化
  33. ** 参数:无
  34. ** 返回值:无
  35. ****************************************************************/
  36. void Buzz_Init(void)
  37. {
  38. GPIO_InitTypeDef GPIO_InitStructure;
  39. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);
  40. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; //Bell 端口配置
  41. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
  42. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
  43. GPIO_Init(GPIOD, &GPIO_InitStructure); //根据设定参数初始化
  44. GPIO_ResetBits(GPIOD,GPIO_Pin_12);//Bell 关闭
  45. }
  46. /***************************************************************
  47. ** 功能:关闭核心板蜂鸣器
  48. ** 参数:无
  49. ** 返回值:无
  50. ****************************************************************/
  51. void Close_Buzz(void)
  52. {
  53. GPIO_ResetBits(GPIOD,GPIO_Pin_12);//Bell 关闭
  54. }
  55. /***************************************************************
  56. ** 功能:开启核心板蜂鸣器
  57. ** 参数:无
  58. ** 返回值:无
  59. ****************************************************************/
  60. void Open_Buzz(void)
  61. {
  62. GPIO_SetBits(GPIOD,GPIO_Pin_12);//Bell 输出高 响起
  63. }
  64. /***************************************************************
  65. ** 功能:开启核心板蜂鸣器 延时关闭
  66. ** 参数:无
  67. ** 返回值:无
  68. ****************************************************************/
  69. char OpenBuzz_timer(int timer)
  70. {
  71. Open_Buzz();
  72. return CreateTimer(Close_Buzz,timer);
  73. }
  74. void Close_led(void)
  75. {
  76. GPIO_ResetBits(GPIOD,GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11);
  77. }
  78. char Open_led(char id,int timer)
  79. {
  80. switch(id)
  81. {
  82. case 1:GPIO_SetBits(GPIOD,GPIO_Pin_8);break;
  83. case 2:GPIO_SetBits(GPIOD,GPIO_Pin_9);break;
  84. case 3:GPIO_SetBits(GPIOD,GPIO_Pin_10);break;
  85. case 4:GPIO_SetBits(GPIOD,GPIO_Pin_11);break;
  86. }
  87. return CreateTimer(Close_led,timer);
  88. }
  89. void Init_key_led_buzz(void)
  90. {
  91. LED_Init();
  92. key_Init();
  93. Buzz_Init();
  94. }
  95. /***************************************************************
  96. ** 功能:按键扫描任务
  97. ** 参数:无
  98. ** 返回值:扫描时间
  99. ****************************************************************/
  100. int key_Read(void)
  101. {
  102. u16 key_value;
  103. u8 count=0;
  104. char bhf[5];
  105. static u8 key_up=0;
  106. key_value = GPIO_ReadInputData(GPIOB);
  107. key_value &=0xF000;
  108. if(key_value!=0xF000)
  109. {
  110. if(key_up==0)
  111. {
  112. key_up=1;
  113. switch(key_value)
  114. {
  115. case 0xE000:
  116. RC522_Read(10); //读RFID卡保存到flash
  117. break;
  118. case 0xD000:
  119. StartTask(6,0);
  120. break;
  121. case 0xB000:
  122. //
  123. // IR_AlarmBuff[0]=0x8f;//A1
  124. // IR_AlarmBuff[1]=0x54;
  125. // IR_AlarmBuff[2]=0x4d;
  126. // IR_AlarmBuff[3]=0x42;
  127. // IR_AlarmBuff[4]=0x09;
  128. // IR_AlarmBuff[5]=0x05;
  129. //
  130. // IR_AlarmBuff[0]=0XF7;//A2
  131. // IR_AlarmBuff[1]=0XA1;
  132. // IR_AlarmBuff[2]=0X54;
  133. // IR_AlarmBuff[3]=0X4B;
  134. // IR_AlarmBuff[4]=0X42;
  135. // IR_AlarmBuff[5]=0X03;
  136. //char IR_AlarmBuff[6] ={0x8f,0x54,0x4d,0x42,0x09,0x05};//A1
  137. //char IR_AlarmBuff[6] ={0XF7,0XA1,0X54,0X4B,0X42,0X03};//A2
  138. // Zigbee_TTS_Wantonly();//开启播报语音
  139. // IR_AlarmBuff[0]=0XFE;//A CS
  140. // IR_AlarmBuff[1]=0x8A;
  141. // IR_AlarmBuff[2]=0x54;
  142. // IR_AlarmBuff[3]=0x42;
  143. // IR_AlarmBuff[4]=0x42;
  144. // IR_AlarmBuff[5]=0x16;
  145. // OpenIRAlarm();
  146. // delayms(1000);
  147. //
  148. // Start_ASR(3);//开启语音识别
  149. // delayms(1000);
  150. break;
  151. case 0x7000:
  152. Read_Flash_RFID(); //读flash中的RFID数据
  153. break;
  154. }
  155. }
  156. }
  157. else key_up=0;
  158. return 1;
  159. }