OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 3246|回复: 1

参考论坛上写的4X4矩阵键盘程序,没有任何反应,求大哥们帮忙看下啊

[复制链接]

16

主题

32

帖子

0

精华

初级会员

Rank: 2

积分
116
金钱
116
注册时间
2015-5-22
在线时间
0 小时
发表于 2015-7-29 09:50:06 | 显示全部楼层 |阅读模式
5金钱
[mw_shl_code=c,true]#include "keyboard.h" #include "delay.h" u16 rowPin[4] = {GPIO_Pin_0|GPIO_Pin_2|GPIO_Pin_4|GPIO_Pin_6}; u16 colPin[4] = {GPIO_Pin_0|GPIO_Pin_2|GPIO_Pin_4|GPIO_Pin_6}; u8 lastKey,currentKey; void keyboard_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOF, ENABLE); //????GPIOBEF?????±?? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_2|GPIO_Pin_4|GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //???ì???? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //??????50MHz GPIO_Init(GPIOE, &GPIO_InitStructure); //?ù????????????GPIOB.8 GPIO_ResetBits(GPIOE, GPIO_Pin_0|GPIO_Pin_2|GPIO_Pin_4|GPIO_Pin_6); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_2|GPIO_Pin_4|GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //???????? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //??????50MHz GPIO_Init(GPIOF, &GPIO_InitStructure); //?ù????????????GPIOB.8 //GPIO_SetBits(GPIOF, GPIO_Pin_0|GPIO_Pin_2|GPIO_Pin_4|GPIO_Pin_6); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //LED0-->B.5 ???????? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //???ì???? GPIO_Init(GPIOB, &GPIO_InitStructure); //?ù???è?¨??????????GPIOB.5 //LED?????? GPIO_SetBits(GPIOB,GPIO_Pin_5); //PB.5 ?????? } u8 Rescan(u16 colPin,u8 colIndex) { u8 i; for(i=0;i<4;i++) { GPIO_ResetBits(GPIOE, GPIO_Pin_0|GPIO_Pin_2|GPIO_Pin_4|GPIO_Pin_6); delay_ms(10); if((GPIO_ReadInputDataBit(GPIOF, colPin)==0)) { GPIO_ResetBits(GPIOE, GPIO_Pin_0|GPIO_Pin_2|GPIO_Pin_4|GPIO_Pin_6); return colIndex*4+i+1; } } GPIO_ResetBits(GPIOE, GPIO_Pin_0|GPIO_Pin_2|GPIO_Pin_4|GPIO_Pin_6); return 0; } u8 KEY_scan(void) { u8 i; for(i = 0;i<4;i++) { if(GPIO_ReadInputDataBit(GPIOF,colPin) == 0){ currentKey = Rescan(colPin,i); if(currentKey == 0) { lastKey = 0; return 0; } else { if(currentKey != lastKey) { lastKey = currentKey; return lastKey; } else { lastKey = currentKey; return 0; } } } } lastKey = 0; return 0; }[/mw_shl_code]


最佳答案

查看完整内容[请看2#楼]

你先行输出0,列作为输入,读出列的值,暂存,然后列输出0,行作为输入,读出行的值,把读出的值合并就得到按键的状态值了,你把读出的值显示出来,然后根据值来安排键值就行了。
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

10

主题

561

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1836
金钱
1836
注册时间
2014-6-27
在线时间
981 小时
发表于 2015-7-29 09:50:07 | 显示全部楼层
你先行输出0,列作为输入,读出列的值,暂存,然后列输出0,行作为输入,读出行的值,把读出的值合并就得到按键的状态值了,你把读出的值显示出来,然后根据值来安排键值就行了。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-19 15:52

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表