|
|
|
|
/******************** (C) COPYRIGHT 2013 CEPARK<EFBFBD><EFBFBD>ܿ<EFBFBD><EFBFBD><EFBFBD>ѧϰ<EFBFBD><EFBFBD>********************
|
|
|
|
|
* <EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>key4x4.c
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ú<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* ʵ<EFBFBD><EFBFBD>ƽ̨<EFBFBD><EFBFBD>CEPARK<EFBFBD><EFBFBD>ܿ<EFBFBD><EFBFBD><EFBFBD>ѧϰ<EFBFBD><EFBFBD>
|
|
|
|
|
* Ӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD>-------------------------
|
|
|
|
|
* | PB8 - H4 |
|
|
|
|
|
* | PB9 - H3 |
|
|
|
|
|
* | PB10 - H2 |
|
|
|
|
|
* | PB11 - H1 |
|
|
|
|
|
* | PB12 - L4 |
|
|
|
|
|
* | PB13 - L3 |
|
|
|
|
|
* | PB14 - L2 |
|
|
|
|
|
* | PB15 - L1 |
|
|
|
|
|
* -------------------------
|
|
|
|
|
* <EFBFBD><EFBFBD>汾 <EFBFBD><EFBFBD>ST3.5.0
|
|
|
|
|
**********************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "key.h"
|
|
|
|
|
#include "delay.h"
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Key_GPIO_Config
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ð<EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD>I/O<EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
void Key4x4_GPIO_Config(void)
|
|
|
|
|
{
|
|
|
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
|
|
|
|
|
|
/*<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿ڵ<EFBFBD>ʱ<EFBFBD><EFBFBD>*/
|
|
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOA,ENABLE);
|
|
|
|
|
|
|
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 ;
|
|
|
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
|
|
|
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
|
|
|
|
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
|
|
|
|
|
|
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_10 | GPIO_Pin_11;
|
|
|
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
|
|
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
|
|
|
|
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9;//KEY0-KEY1
|
|
|
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //<EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
GPIO_Init(GPIOB, &GPIO_InitStructure);//<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>GPIOE4,3
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
u8 Key_Scan(void)
|
|
|
|
|
{
|
|
|
|
|
u16 temp;
|
|
|
|
|
u8 ucBackValue=16;
|
|
|
|
|
//====ɨ<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>==========
|
|
|
|
|
|
|
|
|
|
PBout(1) = 0;
|
|
|
|
|
PBout(0) = 1;
|
|
|
|
|
PBout(10) = 1;
|
|
|
|
|
PBout(11) = 1;
|
|
|
|
|
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵõ<EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
|
|
|
|
|
temp=temp&0x003c; //<EFBFBD><EFBFBD><EFBFBD>ε<EFBFBD>4λ
|
|
|
|
|
if (temp!=0x003c) //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>4λ<EFBFBD><EFBFBD>ȫ<EFBFBD><EFBFBD>1
|
|
|
|
|
{
|
|
|
|
|
delay_ms(20); // <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA);
|
|
|
|
|
temp=temp&0x003c;
|
|
|
|
|
if (temp!=0x003c) //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٴθ<EFBFBD>4λȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ1
|
|
|
|
|
{
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA)&0x003c; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˴ΰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
switch(temp)
|
|
|
|
|
{
|
|
|
|
|
case 0x0038:
|
|
|
|
|
ucBackValue = 13;break;
|
|
|
|
|
case 0x0034:
|
|
|
|
|
ucBackValue = 6;break;
|
|
|
|
|
case 0x002c:
|
|
|
|
|
ucBackValue = 5;break;
|
|
|
|
|
case 0x001c:
|
|
|
|
|
ucBackValue = 4;break;
|
|
|
|
|
default:break;
|
|
|
|
|
}
|
|
|
|
|
while(temp!=0x003c) //<EFBFBD>ȴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ſ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>Ȼ<EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA);
|
|
|
|
|
temp=temp&0x003c;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//====<EFBFBD>ڶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0==========
|
|
|
|
|
PBout(1) = 1;
|
|
|
|
|
PBout(0) = 0;
|
|
|
|
|
PBout(10) = 1;
|
|
|
|
|
PBout(11) = 1;
|
|
|
|
|
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵõ<EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
temp=temp&0x003c; //<EFBFBD><EFBFBD><EFBFBD>ε<EFBFBD>4λ
|
|
|
|
|
if (temp!=0x003c) //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>4λ<EFBFBD><EFBFBD>ȫ<EFBFBD><EFBFBD>1
|
|
|
|
|
{
|
|
|
|
|
delay_ms(20); // <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA);
|
|
|
|
|
temp=temp&0x003c;
|
|
|
|
|
if (temp!=0x003c) //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٴθ<EFBFBD>4λȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ1
|
|
|
|
|
{
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA)&0x003c; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˴ΰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
switch(temp)
|
|
|
|
|
{
|
|
|
|
|
case 0x0038:
|
|
|
|
|
ucBackValue = 12; break;
|
|
|
|
|
case 0x0034:
|
|
|
|
|
ucBackValue = 3; break;
|
|
|
|
|
case 0x002c:
|
|
|
|
|
ucBackValue = 2; break;
|
|
|
|
|
case 0x001c:
|
|
|
|
|
ucBackValue = 1; break;
|
|
|
|
|
default:break;
|
|
|
|
|
}
|
|
|
|
|
while(temp!=0x003c) //<EFBFBD>ȴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ſ<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA);
|
|
|
|
|
temp=temp&0x003c;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//====<EFBFBD><EFBFBD>3<EFBFBD><EFBFBD><EFBFBD><EFBFBD>0==========
|
|
|
|
|
|
|
|
|
|
PBout(1) = 1;
|
|
|
|
|
PBout(0) = 1;
|
|
|
|
|
PBout(10) = 0;
|
|
|
|
|
PBout(11) = 1;
|
|
|
|
|
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵõ<EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
temp=temp&0x003c; //<EFBFBD><EFBFBD><EFBFBD>ε<EFBFBD>4λ
|
|
|
|
|
if (temp!=0x003c) //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>4λ<EFBFBD><EFBFBD>ȫ<EFBFBD><EFBFBD>1
|
|
|
|
|
{
|
|
|
|
|
delay_ms(20); // <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA);
|
|
|
|
|
temp=temp&0x003c;
|
|
|
|
|
if (temp!=0x003c) //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٴθ<EFBFBD>4λȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ1
|
|
|
|
|
{
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA)&0x003c; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˴ΰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
switch(temp)
|
|
|
|
|
{
|
|
|
|
|
case 0x0038:
|
|
|
|
|
ucBackValue = 14; break;
|
|
|
|
|
case 0x0034:
|
|
|
|
|
ucBackValue = 9; break;
|
|
|
|
|
case 0x002c:
|
|
|
|
|
ucBackValue = 8; break;
|
|
|
|
|
case 0x001c:
|
|
|
|
|
ucBackValue = 7; break;
|
|
|
|
|
default:break;
|
|
|
|
|
}
|
|
|
|
|
while(temp!=0x003c) //<EFBFBD>ȴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ſ<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA);
|
|
|
|
|
temp=temp&0x003c;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//====<EFBFBD><EFBFBD>4<EFBFBD><EFBFBD><EFBFBD><EFBFBD>0==========
|
|
|
|
|
PBout(1) = 1;
|
|
|
|
|
PBout(0) = 1;
|
|
|
|
|
PBout(10) = 1;
|
|
|
|
|
PBout(11) = 0;
|
|
|
|
|
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵõ<EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
temp=temp&0x003c; //<EFBFBD><EFBFBD><EFBFBD>ε<EFBFBD>4λ
|
|
|
|
|
if (temp!=0x003c) //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>4λ<EFBFBD><EFBFBD>ȫ<EFBFBD><EFBFBD>1
|
|
|
|
|
{
|
|
|
|
|
delay_ms(20); // <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA);
|
|
|
|
|
temp=temp&0x003c;
|
|
|
|
|
if (temp!=0x003c) //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٴθ<EFBFBD>4λȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ1
|
|
|
|
|
{
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA)&0x003c;
|
|
|
|
|
switch(temp)
|
|
|
|
|
{
|
|
|
|
|
case 0x0038:
|
|
|
|
|
ucBackValue = 15; break;
|
|
|
|
|
case 0x0034:
|
|
|
|
|
ucBackValue = 11; break;
|
|
|
|
|
case 0x002c:
|
|
|
|
|
ucBackValue = 0; break;
|
|
|
|
|
case 0x001c:
|
|
|
|
|
ucBackValue = 10; break;
|
|
|
|
|
default:break;
|
|
|
|
|
}
|
|
|
|
|
while(temp!=0x003c) //<EFBFBD>ȴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ſ<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA);
|
|
|
|
|
temp=temp&0x003c;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ucBackValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
//<EFBFBD><EFBFBD><EFBFBD>ذ<EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
//mode:0,<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;1,֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
|
|
|
|
//0<EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>κΰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
//1<EFBFBD><EFBFBD>KEY0<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
//2<EFBFBD><EFBFBD>KEY1<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
//3<EFBFBD><EFBFBD>KEY3<EFBFBD><EFBFBD><EFBFBD><EFBFBD> WK_UP
|
|
|
|
|
//ע<EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>,KEY0>KEY1>KEY_UP!!
|
|
|
|
|
u8 KEY_Scan(u8 mode)
|
|
|
|
|
{
|
|
|
|
|
static u8 key_up=1;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɿ<EFBFBD><EFBFBD><EFBFBD>־
|
|
|
|
|
if(mode)key_up=1; //֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if((IN==0||OUT==0))
|
|
|
|
|
{
|
|
|
|
|
delay_ms(10);//ȥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(IN==0)return IN_PRES;
|
|
|
|
|
else if(OUT==0)return OUT_PRES;
|
|
|
|
|
}else if(OUT==1&&IN==1)key_up=1;
|
|
|
|
|
return 0;// <EFBFBD>ް<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
|