|
- //直接將代碼貼出來(lái)了,就不發(fā)附件了,僅供參考
- 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
- {//這里不再延時(shí)再掃描,因?yàn)橐呀?jīng)確定了不是抖動(dòng)才會(huì)進(jìn)入本步操作
- 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]);
- }
復(fù)制代碼 |
評(píng)分
-
查看全部評(píng)分
|