欢迎来到冰豆网! | 帮助中心 分享价值,成长自我!
冰豆网
全部分类
  • IT计算机>
  • 经管营销>
  • 医药卫生>
  • 自然科学>
  • 农林牧渔>
  • 人文社科>
  • 工程科技>
  • PPT模板>
  • 求职职场>
  • 解决方案>
  • 总结汇报>
  • 党团工作>
  • ImageVerifierCode 换一换
    首页 冰豆网 > 资源分类 > DOCX文档下载
    分享到微信 分享到微博 分享到QQ空间

    STM32矩阵键盘程序44.docx

    • 资源ID:24229266       资源大小:15.50KB        全文页数:11页
    • 资源格式: DOCX        下载积分:10金币
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录 QQ登录
    二维码
    微信扫一扫登录
    下载资源需要10金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP,免费下载
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    STM32矩阵键盘程序44.docx

    1、STM32矩阵键盘程序44STM32-矩阵键盘程序44Lt D/*-* 矩阵键盘驱动* 文 件: keyboard.c* 编写人: LiuHui* 描述: 扫描4x4 矩阵键盘输入,并返回键值* 适用范围: 驱动采用ST3.5 库编写,适用于STM32F10x 系列单片机* 所用引脚: PA0-PA7* 编写时间: 2021 年5 月20 日-*/#include stm32f10x.h#include keyboard.h#include dealy.h/*-矩阵键盘初始化-* 功能: 初始化stm32 单片机GPIO /PA0-PA7* 参数传递:* 输入: 无* 返回值:无-*/void

    2、 KeyBoard_Init(void)GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_Init(GPIOA, &GPIO_InitStructure);GPIO_InitStructure.GPIO_Pin =

    3、 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_IPD;GPIO_Init(GPIOA, &GPIO_InitStructure);GPIO_SetBits(GPIOA, GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3);GPIO_ResetBits(GPIOA, GPIO_Pin_4 | GPIO_Pin_5

    4、| GPIO_Pin_6 | GPIO_Pin_7);/*-矩阵键盘扫描-* 功能: 扫描矩阵键盘,并返回键值* 参数:* 输入: 无* 返回: 有键按下返回该键值* 无键按下时那么返回0-*/u8 Read_KeyValue(void)u8 KeyValue=0;if(GPIO_ReadInputData(GPIOA)&0xff)!=0x0f)Delay_ms(10);if(GPIO_ReadInputData(GPIOA)&0xff)!=0x0f)GPIO_SetBits(GPIOA, GPIO_Pin_0);GPIO_ResetBits(GPIOA, GPIO_Pin_1 | GPIO_

    5、Pin_2 | GPIO_Pin_3);switch(GPIO_ReadInputData(GPIOA)&0xff)case 0x11: KeyValue = 1; break;case 0x21: KeyValue = 5; break;case 0x41: KeyValue = 9; break;case 0x81: KeyValue = 13;break;GPIO_SetBits(GPIOA, GPIO_Pin_1);GPIO_ResetBits(GPIOA, GPIO_Pin_0 | GPIO_Pin_2 | GPIO_Pin_3);switch(GPIO_ReadInputData(

    6、GPIOA)&0xff)case 0x12: KeyValue = 2; break;case 0x22: KeyValue = 6; break;case 0x42: KeyValue = 10;break;case 0x82: KeyValue = 14;break;GPIO_SetBits(GPIOA, GPIO_Pin_2);GPIO_ResetBits(GPIOA, GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_3);switch(GPIO_ReadInputData(GPIOA)&0xff)case 0x14: KeyValue = 3; break;cas

    7、e 0x24: KeyValue = 7; break;case 0x44: KeyValue = 11;break;case 0x84: KeyValue = 15;break;GPIO_SetBits(GPIOA, GPIO_Pin_3);GPIO_ResetBits(GPIOA, GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2);switch(GPIO_ReadInputData(GPIOA)&0xff)case 0x18: KeyValue = 4; break;case 0x28: KeyValue = 8; break;case 0x48: KeyValu

    8、e = 12;break;case 0x88: KeyValue = 16;break;GPIO_SetBits(GPIOA, GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3);GPIO_ResetBits(GPIOA, GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 |GPIO_Pin_7);while(GPIO_ReadInputData(GPIOA)&0xff)!=0x0f);return KeyValue;return 0;/*-THE END-*/*-* 矩阵键盘驱动* 文 件: keyboard.h* 编

    9、写人: LiuHui* 描述: 扫描4x4 矩阵键盘输入,并返回键值* 适用范围: 驱动为ST3.5 库编写,适用于STM32F10x 系列单片机* 所用引脚: PA0-PA7* 编写时间: 2013 年11 月22 日* 版本: 1.0-*/#ifndef _KEYBOARD_H#define _KEYBOARD_Hvoid KeyBoard_Init(void);u8 Read_KeyValue(void);#endif/*-THE END-*#include stm32f10x.hvoid KeyBoard_Init(void)GPIO_InitTypeDef GPIO_InitStru

    10、cture;GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOA, &GPIO_InitStructure);GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;GPIO_InitStructure.GPIO_M

    11、ode = GPIO_Mode_IPD;GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_SetBits(GPIOB, GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6);GPIO_ResetBits(GPIOB, GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10);/PA,PBvoid Delay_ms(int time) int i=0; while(time-) i=12000; while(i-); u8 Read_KeyValue(void) u

    12、8 KeyValue=1; if(GPIO_ReadInputData(GPIOB)&0xff)!=0x0f) Delay_ms(10); if(GPIO_ReadInputData(GPIOB)&0xff)!=0x0f) GPIO_SetBits(GPIOB, GPIO_Pin_3);GPIO_ResetBits(GPIOB, GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6);switch(GPIO_ReadInputData(GPIOB)&0xff)case 0x11: KeyValue = 7; break;case 0x21: KeyValue = 4; br

    13、eak;case 0x41: KeyValue = 1; break;case 0x81: KeyValue = 0; break;GPIO_SetBits(GPIOB, GPIO_Pin_4);GPIO_ResetBits(GPIOB, GPIO_Pin_3 | GPIO_Pin_5 | GPIO_Pin_6);switch(GPIO_ReadInputData(GPIOB)&0xff)case 0x12: KeyValue = 8; break;case 0x22: KeyValue = 5; break;case 0x42: KeyValue = 2; break;case 0x82:

    14、KeyValue = 0; break;GPIO_SetBits(GPIOB, GPIO_Pin_5);GPIO_ResetBits(GPIOB, GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_6);switch(GPIO_ReadInputData(GPIOB)&0xff)case 0x14: KeyValue = 9; break;case 0x24: KeyValue = 6; break;case 0x44: KeyValue = 3; break;case 0x84: KeyValue = 0; break;GPIO_SetBits(GPIOB, GPIO_P

    15、in_6);GPIO_ResetBits(GPIOB, GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5);switch(GPIO_ReadInputData(GPIOB)&0xff)case 0x18: KeyValue = 0; break;case 0x28: KeyValue = 0; break;case 0x48: KeyValue = 0;break;case 0x88: KeyValue = 0;break;GPIO_SetBits(GPIOB, GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6);GPI

    16、O_ResetBits(GPIOB, GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10);/while(GPIO_ReadInputData(GPIOB)&0xff)!=0x0f);return KeyValue;return 0;uint16_t table=0xEB,0x28,0xB3,0xBA,0x78,0xDA,0xDB,0xA8,0xFB,0xFA;int main() RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); RCC_APB2PeriphClockCmd(RCC_AP

    17、B2Periph_GPIOB,ENABLE); KeyBoard_Init(); int keyvalue=Read_KeyValue(); GPIO_Write(GPIOA, tablekeyvalue); /*while(1) int i; for(i=0;i10;i+) GPIO_Write(GPIOA, tablei); Delay_ms(500); */ /*u8 keyvalue; for(int i=0;i+) KeyBoard_Init(); keyvalue=Read_KeyValue(); GPIO_Write(GPIOA,tablekeyvalue); Delay_ms(

    18、500); */#include stm32f10x.hvoid KeyBoard_Init(void)GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOA, &GPIO_InitStructure);GPIO_InitStructure.GPIO_Pin = GPIO

    19、_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_SetBits(GPIOB, GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6);GPIO_Res

    20、etBits(GPIOB, GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10); void Delay_ms(int time) int i=0; while(time-) i=12000; while(i-); u8 Read_KeyValue(void) if(GPIO_ReadInputData(GPIOB)&0xff)!=0x73)/在这个程序下为什么无论是GPIO_ReadInputData(GPIOB)&0xff)!=0x73还是GPIO_ReadInputData(GPIOB)&0xff)=0x73都能往下运行,而在屏蔽Delay_ms(10)后那么只能运行一种,是因为这个Delay_ms(10)对if里的判断有影响吗? Delay_ms(10); GPIO_Write(GPIOA,0x33);return 0;int main() RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); KeyBoard_Init(); Read_KeyValue();


    注意事项

    本文(STM32矩阵键盘程序44.docx)为本站会员主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

    copyright@ 2008-2022 冰点文档网站版权所有

    经营许可证编号:鄂ICP备2022015515号-1

    收起
    展开