|
|
|
|
#include "key.h"
|
|
|
|
|
#include "delay.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Key4x4_GPIO_Config(void)
|
|
|
|
|
{
|
|
|
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
|
|
|
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOA,ENABLE);
|
|
|
|
|
|
|
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
PBout(1) = 0;
|
|
|
|
|
PBout(0) = 1;
|
|
|
|
|
PBout(10) = 1;
|
|
|
|
|
PBout(11) = 1;
|
|
|
|
|
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA);
|
|
|
|
|
|
|
|
|
|
temp=temp&0x00F0;
|
|
|
|
|
if (temp!=0x00F0)
|
|
|
|
|
{
|
|
|
|
|
delay_ms(20);
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA);
|
|
|
|
|
temp=temp&0x00F0;
|
|
|
|
|
if (temp!=0x00F0)
|
|
|
|
|
{
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA)&0x00F0;
|
|
|
|
|
switch(temp)
|
|
|
|
|
{
|
|
|
|
|
case 0x00E0:
|
|
|
|
|
ucBackValue = 15;break;
|
|
|
|
|
case 0x00D0:
|
|
|
|
|
ucBackValue = 11;break;
|
|
|
|
|
case 0x00B0:
|
|
|
|
|
ucBackValue = 0;break;
|
|
|
|
|
case 0x0070:
|
|
|
|
|
ucBackValue = 10;break;
|
|
|
|
|
default:break;
|
|
|
|
|
}
|
|
|
|
|
while(temp!=0x00F0)
|
|
|
|
|
{
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA);
|
|
|
|
|
temp=temp&0x00F0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PBout(1) = 1;
|
|
|
|
|
PBout(0) = 0;
|
|
|
|
|
PBout(10) = 1;
|
|
|
|
|
PBout(11) = 1;
|
|
|
|
|
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA);
|
|
|
|
|
temp=temp&0x00F0;
|
|
|
|
|
if (temp!=0x00F0)
|
|
|
|
|
{
|
|
|
|
|
delay_ms(20);
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA);
|
|
|
|
|
temp=temp&0x00F0;
|
|
|
|
|
if (temp!=0x00F0)
|
|
|
|
|
{
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA)&0x00F0;
|
|
|
|
|
switch(temp)
|
|
|
|
|
{
|
|
|
|
|
case 0x00E0:
|
|
|
|
|
ucBackValue = 12; break;
|
|
|
|
|
case 0x00D0:
|
|
|
|
|
ucBackValue = 3; break;
|
|
|
|
|
case 0x00B0:
|
|
|
|
|
ucBackValue = 2; break;
|
|
|
|
|
case 0x0070:
|
|
|
|
|
ucBackValue = 1; break;
|
|
|
|
|
default:break;
|
|
|
|
|
}
|
|
|
|
|
while(temp!=0x00F0)
|
|
|
|
|
{
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA);
|
|
|
|
|
temp=temp&0x00F0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PBout(1) = 1;
|
|
|
|
|
PBout(0) = 1;
|
|
|
|
|
PBout(10) = 0;
|
|
|
|
|
PBout(11) = 1;
|
|
|
|
|
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA);
|
|
|
|
|
temp=temp&0x00F0;
|
|
|
|
|
if (temp!=0x00F0)
|
|
|
|
|
{
|
|
|
|
|
delay_ms(20); // <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA);
|
|
|
|
|
temp=temp&0x00F0;
|
|
|
|
|
if (temp!=0x00F0) //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٴθ<EFBFBD>4λȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ1
|
|
|
|
|
{
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA)&0x00F0; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˴ΰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
switch(temp)
|
|
|
|
|
{
|
|
|
|
|
case 0x00E0:
|
|
|
|
|
ucBackValue = 13; break;
|
|
|
|
|
case 0x00D0:
|
|
|
|
|
ucBackValue = 5; break;
|
|
|
|
|
case 0x00B0:
|
|
|
|
|
ucBackValue = 4; break;
|
|
|
|
|
case 0x0070:
|
|
|
|
|
ucBackValue = 3; break;
|
|
|
|
|
default:break;
|
|
|
|
|
}
|
|
|
|
|
while(temp!=0x00F0) //<EFBFBD>ȴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ſ<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA);
|
|
|
|
|
temp=temp&0x00F0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//====<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&0x00F0; //<EFBFBD><EFBFBD><EFBFBD>ε<EFBFBD>4λ
|
|
|
|
|
if (temp!=0x00F0) //<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&0x00F0;
|
|
|
|
|
if (temp!=0x00F0) //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٴθ<EFBFBD>4λȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ1
|
|
|
|
|
{
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA)&0x00F0;
|
|
|
|
|
switch(temp)
|
|
|
|
|
{
|
|
|
|
|
case 0x00E0:
|
|
|
|
|
ucBackValue = 14; break;
|
|
|
|
|
case 0x00D0:
|
|
|
|
|
ucBackValue = 9; break;
|
|
|
|
|
case 0x00B0:
|
|
|
|
|
ucBackValue = 8; break;
|
|
|
|
|
case 0x0070:
|
|
|
|
|
ucBackValue = 7; break;
|
|
|
|
|
default:break;
|
|
|
|
|
}
|
|
|
|
|
while(temp!=0x00F0) //<EFBFBD>ȴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ſ<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
temp=GPIO_ReadInputData(GPIOA);
|
|
|
|
|
temp=temp&0x00F0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ucBackValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|