欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
stm32矩陣按鍵掃描代碼
[打印本頁]
作者:
阿拉聽聽的天涯
時間:
2017-8-7 08:08
標題:
stm32矩陣按鍵掃描代碼
//直接將代碼貼出來了,就不發附件了,僅供參考
u16 Get_KeyValue(void)//使用PF0~PF7
{
GPIO_InitTypeDef GPIO_InitStructure;
u8 i=5,j=5;
u16 temp1,temp2;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE);
GPIO_DeInit(GPIOF);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_ResetBits(GPIOF,GPIO_Pin_L);//掃描列值
if((GPIO_ReadInputData(GPIOF)&0x00f0)==0x00f0)
return 0;
else
{
Delay_nms(70);//按鍵消抖
if((GPIO_ReadInputData(GPIOF)&0x00f0)==0x00f0)
return 0;
else
temp1=GPIO_ReadInputData(GPIOF)&0x00f0;
}
switch(temp1)
{
case 0x00e0:j=0;break;
case 0x00d0:j=1;break;
case 0x00b0:j=2;break;
case 0x0070:j=3;break;
default:break;
}
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_ResetBits(GPIOF,GPIO_Pin_R);//掃描行值
if((GPIO_ReadInputData(GPIOF)&0x000f)==0x000f)
return 0;
else
{//這里不再延時再掃描,因為已經確定了不是抖動才會進入本步操作
temp2=GPIO_ReadInputData(GPIOF)&0x000f;
}
switch(temp2)
{
case 0x000e:i=0;break;
case 0x000d:i=1;break;
case 0x000b:i=2;break;
case 0x0007:i=3;break;
default:break;
}
if((i==5)||(j==5))
return 0;
else
return (Key_Tab[i][j]);
}
復制代碼
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1