123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- #include "key.h"
- /***************************************************************
- ** 功能:核心板按键端口初始化
- ** 参数:无
- ** 返回值:无
- ****************************************************************/
- void key_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;//上拉输入模式
- GPIO_Init(GPIOB,&GPIO_InitStructure);
- }
- /***************************************************************
- ** 功能:核心板led灯初始化
- ** 参数:无
- ** 返回值:无
- ****************************************************************/
- void LED_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11; //LED1-4 端口配置
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
- GPIO_Init(GPIOD, &GPIO_InitStructure); //根据设定参数初始化
- // GPIO_SetBits(GPIOD,GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11);//LED1-4 输出高
- GPIO_ResetBits(GPIOD,GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11); //LED1-4 熄灭
- }
- /***************************************************************
- ** 功能:核心板蜂鸣器初始化
- ** 参数:无
- ** 返回值:无
- ****************************************************************/
- void Buzz_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; //Bell 端口配置
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
- GPIO_Init(GPIOD, &GPIO_InitStructure); //根据设定参数初始化
- GPIO_ResetBits(GPIOD,GPIO_Pin_12);//Bell 关闭
- }
- /***************************************************************
- ** 功能:关闭核心板蜂鸣器
- ** 参数:无
- ** 返回值:无
- ****************************************************************/
- void Close_Buzz(void)
- {
- GPIO_ResetBits(GPIOD,GPIO_Pin_12);//Bell 关闭
- }
- /***************************************************************
- ** 功能:开启核心板蜂鸣器
- ** 参数:无
- ** 返回值:无
- ****************************************************************/
- void Open_Buzz(void)
- {
- GPIO_SetBits(GPIOD,GPIO_Pin_12);//Bell 输出高 响起
- }
- /***************************************************************
- ** 功能:开启核心板蜂鸣器 延时关闭
- ** 参数:无
- ** 返回值:无
- ****************************************************************/
- char OpenBuzz_timer(int timer)
- {
- Open_Buzz();
- return CreateTimer(Close_Buzz,timer);
- }
- void Close_led(void)
- {
-
- GPIO_ResetBits(GPIOD,GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11);
-
- }
- char Open_led(char id,int timer)
- {
- switch(id)
- {
- case 1:GPIO_SetBits(GPIOD,GPIO_Pin_8);break;
- case 2:GPIO_SetBits(GPIOD,GPIO_Pin_9);break;
- case 3:GPIO_SetBits(GPIOD,GPIO_Pin_10);break;
- case 4:GPIO_SetBits(GPIOD,GPIO_Pin_11);break;
- }
- return CreateTimer(Close_led,timer);
- }
- void Init_key_led_buzz(void)
- {
- LED_Init();
- key_Init();
- Buzz_Init();
- }
- /***************************************************************
- ** 功能:按键扫描任务
- ** 参数:无
- ** 返回值:扫描时间
- ****************************************************************/
- int key_Read(void)
- {
- u16 key_value;
- u8 count=0;
- char bhf[5];
- static u8 key_up=0;
- key_value = GPIO_ReadInputData(GPIOB);
- key_value &=0xF000;
- if(key_value!=0xF000)
- {
- if(key_up==0)
- {
- key_up=1;
- switch(key_value)
- {
- case 0xE000:
- RC522_Read(10); //读RFID卡保存到flash
- break;
- case 0xD000:
- StartTask(6,0);
- break;
-
- case 0xB000:
- //
- // IR_AlarmBuff[0]=0x8f;//A1
- // IR_AlarmBuff[1]=0x54;
- // IR_AlarmBuff[2]=0x4d;
- // IR_AlarmBuff[3]=0x42;
- // IR_AlarmBuff[4]=0x09;
- // IR_AlarmBuff[5]=0x05;
- //
- // IR_AlarmBuff[0]=0XF7;//A2
- // IR_AlarmBuff[1]=0XA1;
- // IR_AlarmBuff[2]=0X54;
- // IR_AlarmBuff[3]=0X4B;
- // IR_AlarmBuff[4]=0X42;
- // IR_AlarmBuff[5]=0X03;
- //char IR_AlarmBuff[6] ={0x8f,0x54,0x4d,0x42,0x09,0x05};//A1
- //char IR_AlarmBuff[6] ={0XF7,0XA1,0X54,0X4B,0X42,0X03};//A2
-
- // Zigbee_TTS_Wantonly();//开启播报语音
- // IR_AlarmBuff[0]=0XFE;//A CS
- // IR_AlarmBuff[1]=0x8A;
- // IR_AlarmBuff[2]=0x54;
- // IR_AlarmBuff[3]=0x42;
- // IR_AlarmBuff[4]=0x42;
- // IR_AlarmBuff[5]=0x16;
- // OpenIRAlarm();
- // delayms(1000);
- //
- // Start_ASR(3);//开启语音识别
- // delayms(1000);
- break;
- case 0x7000:
- Read_Flash_RFID(); //读flash中的RFID数据
- break;
- }
- }
- }
- else key_up=0;
-
- return 1;
- }
|