|
|
/******************** (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); |
|
|
} |
|
|
|
|
|
|
|
|
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 = 12;break; |
|
|
case 0x0034: |
|
|
ucBackValue = 13;break; |
|
|
case 0x002c: |
|
|
ucBackValue = 14;break; |
|
|
case 0x001c: |
|
|
ucBackValue = 15;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 = 3; break; |
|
|
case 0x0034: |
|
|
ucBackValue = 6; break; |
|
|
case 0x002c: |
|
|
ucBackValue = 9; break; |
|
|
case 0x001c: |
|
|
ucBackValue = 11; 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 = 1; break; |
|
|
case 0x0034: |
|
|
ucBackValue = 4; break; |
|
|
case 0x002c: |
|
|
ucBackValue = 7; 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; |
|
|
} |
|
|
} |
|
|
} |
|
|
//====<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 = 2; break; |
|
|
case 0x0034: |
|
|
ucBackValue = 5; break; |
|
|
case 0x002c: |
|
|
ucBackValue = 8; break; |
|
|
case 0x001c: |
|
|
ucBackValue = 0; break; |
|
|
default:break; |
|
|
} |
|
|
while(temp!=0x003c) //<EFBFBD>ȴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ſ<EFBFBD> |
|
|
{ |
|
|
temp=GPIO_ReadInputData(GPIOA); |
|
|
temp=temp&0x003c; |
|
|
} |
|
|
} |
|
|
} |
|
|
return ucBackValue; |
|
|
} |
|
|
|
|
|
|