|
/******************************************************************************
|
* Copyright (C) 2014-2015 HangZhou SiZhu Co.,LTD.
|
*
|
*-----------------------------------------------------------------------------
|
* File: KEY.c
|
* Description: KEY scan code
|
* Author: Lishoujian (867693272@qq.com)
|
* Date: Jan 8, 2015
|
*****************************************************************************/
|
|
/* ----------------------- Platform includes --------------------------------*/
|
|
#include "key.h"
|
#include "delay.h"
|
|
#include "stm32f10x_exti.h"
|
|
|
|
|
/******************************************
|
* func: Get_key
|
* desc: scan key & return key data
|
* input: none
|
* output: none
|
* return: key data 4bytes:
|
* 4# 3# 2# 1# byte
|
* | |KEY3|KEY2|KEY1|
|
*****************************************/
|
uint32 Get_key(void)
|
{
|
uint32 temp32a=0,temp32b=1;
|
while(temp32a != temp32b)
|
{
|
temp32a = (KEY1 | (KEY2 << 8) | (KEY3 << 16));
|
delay_ms(1);//È¥¶¶¶¯
|
temp32b = (KEY1 | (KEY2 << 8) | (KEY3 << 16));
|
}
|
return(temp32a);
|
}
|
|
|
uint32 get_key4(void)
|
{
|
uint32 temp32a=0,temp32b=1;
|
|
while(temp32a != temp32b)
|
{
|
temp32a = KEY4;
|
delay_ms(1);//È¥¶¶¶¯
|
temp32b = KEY4;
|
}
|
|
return(temp32a);
|
|
}
|
/******************************************
|
* func: Get_key_count
|
* desc:
|
* input: none
|
* output: none
|
* return:
|
|
*****************************************/
|
/*
|
u8 Get_key_count(u8 keybufs,u8 key_count)
|
{
|
uint32 key_stat=0;
|
key_stat = Get_key(); //get key state
|
|
if((key_stat) & 0xff) //°´¼ü°´Ï ËÉ¿ªÖ®ºó²ÅÄÜÉúЧÏÂÒ»´Î°´¼ü
|
{
|
if( !keybufs )
|
{
|
keybufs = 0x01;
|
}
|
}
|
else
|
{
|
if( keybufs )
|
{
|
keybufs = 0x00;
|
key_count++;
|
if(key_count==11)
|
{
|
key_count = 0;
|
}
|
}
|
}
|
return key_count;
|
|
} */
|
void key_interruptinit_disable(void)
|
{
|
EXTI_InitTypeDef EXTI_InitStructure;
|
// NVIC_InitTypeDef NVIC_InitStructure;
|
// GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
|
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
// GPIO_Init(GPIOC, &GPIO_InitStructure);
|
|
|
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
|
|
// NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
|
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
// NVIC_Init(&NVIC_InitStructure);
|
|
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource7);
|
EXTI_InitStructure.EXTI_Line = EXTI_Line7;
|
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
|
EXTI_InitStructure.EXTI_LineCmd = DISABLE;
|
EXTI_Init(&EXTI_InitStructure);
|
}
|
|
void key_interruptinit_enable(void)
|
{
|
EXTI_InitTypeDef EXTI_InitStructure;
|
// NVIC_InitTypeDef NVIC_InitStructure;
|
// GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
|
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
// GPIO_Init(GPIOC, &GPIO_InitStructure);
|
|
|
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
|
|
// NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
|
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
// NVIC_Init(&NVIC_InitStructure);
|
|
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource7);
|
EXTI_InitStructure.EXTI_Line = EXTI_Line7;
|
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
|
EXTI_InitStructure.EXTI_LineCmd = DISABLE;
|
EXTI_Init(&EXTI_InitStructure);
|
}
|
|
void key_interruptinit(void)
|
{
|
EXTI_InitTypeDef EXTI_InitStructure;
|
NVIC_InitTypeDef NVIC_InitStructure;
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
|
|
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
|
|
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
NVIC_Init(&NVIC_InitStructure);
|
|
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource7);
|
EXTI_InitStructure.EXTI_Line = EXTI_Line7;
|
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
|
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
EXTI_Init(&EXTI_InitStructure);
|
}
|