




已阅读5页,还剩11页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
/=Keyboard.h=/*- 本程序实现4*5键盘的扫描 从左到右,从上到下,键值 依次为1-20-*/#ifndef _KEYBOARD_H#define _KEYBOARD_H#include stm32f10x_lib.h/选择扫描模式#define Interrupt_Scan /中断扫描模式 ,要在NVIC在中打开对应中断/*可以自己定义其它扫描方式*/#define DELAY_COUNT 0x0FFFF/* 键盘控制引脚定义 */#define Keyboard_Control_Port GPIOD#define Keyboard_Line_1 GPIO_Pin_0#define Keyboard_Line_2 GPIO_Pin_1#define Keyboard_Line_3 GPIO_Pin_2#define Keyboard_Line_4 GPIO_Pin_3#define Keyboard_Line_5 GPIO_Pin_4#define Keyboard_Row_1 GPIO_Pin_5#define Keyboard_Row_2 GPIO_Pin_6#define Keyboard_Row_3 GPIO_Pin_7#define Keyboard_Row_4 GPIO_Pin_8#define Keyboard_LineBase Keyboard_Line_1#define Keyboard_RowBase Keyboard_Row_1#define Keyboard_Line (Keyboard_Line_1 | Keyboard_Line_2 | Keyboard_Line_3 | Keyboard_Line_4 | Keyboard_Line_5)#define Keyboard_Row (Keyboard_Row_1 | Keyboard_Row_2 | Keyboard_Row_3 | Keyboard_Row_4)#ifdef Interrupt_Scan /* 中断扫描模式宏定义 */#define Keyboard_EXTI_Row1 EXTI_Line5#define Keyboard_EXTI_Row2 EXTI_Line6#define Keyboard_EXTI_Row3 EXTI_Line7#define Keyboard_EXTI_Row4 EXTI_Line8#define Keyboard_EXTI_PortSource GPIO_PortSourceGPIOD#define Keyboard_EXTI_PinSource1 GPIO_PinSource5#define Keyboard_EXTI_PinSource2 GPIO_PinSource6#define Keyboard_EXTI_PinSource3 GPIO_PinSource7#define Keyboard_EXTI_PinSource4 GPIO_PinSource8#define Keyboard_IRQ_Channel EXTI9_5_IRQChannel#define Keyboard_EXTI_Line (Keyboard_EXTI_Row1 | Keyboard_EXTI_Row2 | Keyboard_EXTI_Row3 | Keyboard_EXTI_Row4)#endif /* 中断扫描模式宏定义 */* 键盘全局变量声明 */extern unsigned int Keyboard_Val ; /当前键值extern unsigned char Keyboard_Change_Flag ; /键值改变标志,读取新的键值后由主程序清零/* 键盘接口函数声明 */#ifdef Interrupt_Scanextern void Init_Keyboard_Interrupt(void) ;/键盘初始化为键盘扫描模式 #endifextern void Delay(vu32 nCount) ; /用于延时消抖#endif /* KEYBOARD_H */ /=/=Keyboard.c=/#include stm32f10x_lib.h#include Keyboard.hunsigned int Keyboard_Val = 0 ; /保存键值unsigned char Keyboard_Change_Flag = 0 ; /键值改变标志,读取键值后清零/*函数名称: Init_Keyboard_Interrupt功 能: 键盘初始化为中断扫描模式 初始化键盘需要的IO,Line1-Line5设为输出低 Row1-Row4 接上拉电阻,使能下降沿中断参 数: 无返回值 : 无*/void Init_Keyboard_Interrupt(void) GPIO_InitTypeDef GPIO_InitStructure ; EXTI_InitTypeDef EXTI_InitStructure ; EXTI_DeInit() ; /Line1-Line5设为输出高 GPIO_InitStructure.GPIO_Pin = Keyboard_Line ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP ; /推挽输出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz ; GPIO_Init(Keyboard_Control_Port ,&GPIO_InitStructure) ; GPIO_SetBits(Keyboard_Control_Port ,Keyboard_Line) ; /Row1-Row4设置为下拉输入,用来接收上升沿中断 GPIO_InitStructure.GPIO_Pin = Keyboard_Row; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD ; /下拉输入 GPIO_Init(Keyboard_Control_Port ,&GPIO_InitStructure) ; EXTI_ClearITPendingBit(Keyboard_EXTI_Row1) ; /清除中断标志位 GPIO_EXTILineConfig(Keyboard_EXTI_PortSource ,Keyboard_EXTI_PinSource1 ); /Pinsource不能取或 EXTI_ClearITPendingBit(Keyboard_EXTI_Row2) ; /清除中断标志位 GPIO_EXTILineConfig(Keyboard_EXTI_PortSource ,Keyboard_EXTI_PinSource2 ); EXTI_ClearITPendingBit(Keyboard_EXTI_Row3) ; /清除中断标志位 GPIO_EXTILineConfig(Keyboard_EXTI_PortSource ,Keyboard_EXTI_PinSource3 ); EXTI_ClearITPendingBit(Keyboard_EXTI_Row4) ; /清除中断标志位 GPIO_EXTILineConfig(Keyboard_EXTI_PortSource ,Keyboard_EXTI_PinSource4 ); /设置Row1-Row4为上升沿中断 EXTI_InitStructure.EXTI_Line = Keyboard_EXTI_Line; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt ; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising ; EXTI_InitStructure.EXTI_LineCmd = ENABLE ; EXTI_Init(&EXTI_InitStructure) ;/*函数名称: Delay功 能: 在扫描按键时,用于延时消抖参 数: nCount - 延时长度返回值 : 无*/void Delay(vu32 nCount) for(; nCount!= 0;nCount-);/=/=stm32f10x_it.c=/void EXTI9_5_IRQHandler(void)unsigned long tmpFlag=0 ; /保存需要的中断标志位 unsigned char i = 0 ; /循环标量 tmpFlag = EXTI-PR & Keyboard_EXTI_Line ; /只取设定过的标志位 EXTI-PR = tmpFlag ; switch(tmpFlag) /判断是哪个标志位置位 case Keyboard_EXTI_Row1: GPIO_ResetBits(Keyboard_Control_Port ,Keyboard_Line) ; for(i=0 ;i5 ;i+) /扫描方式判断按键 GPIO_SetBits(Keyboard_Control_Port ,(Keyboard_LineBasePR = Keyboard_EXTI_Row1 ;/清除中断标志 break ; case Keyboard_EXTI_Row2: GPIO_ResetBits(Keyboard_Control_Port ,Keyboard_Line) ; for(i=0 ;i5 ;i+)/扫描方式判断按键 GPIO_SetBits(Keyboard_Control_Port ,(Keyboard_LineBasePR = Keyboard_EXTI_Row2 ; /清除中断标志 break ; case Keyboard_EXTI_Row3: GPIO_ResetBits(Keyboard_Control_Port ,Keyboard_Line) ; for(i=0 ;i5 ;i+) /扫描方式判断按键 GPIO_SetBits(Keyboard_Control_Port ,(Keyboard_LineBasePR = Keyboard_EXTI_Row3 ; /清除中断标志 break ; case Keyboard_EXTI_Row4: GPIO_ResetBits(Keyboard_Co
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 14 圆明园的毁灭 公开课一等奖创新教案
- 化妆实训室安全培训课件
- 2025年秋部编版语文五上 21 古诗词三首(公开课一等奖创新教案++备课素材)
- 先从自己做起课件
- 勾股定理说课稿课件
- 勾股定理的逆定理课件
- 康复技术专业介绍
- 家庭教育学解读
- 灯箱制作技术分析
- 2025年轨道车司机(高级技师)职业技能鉴定考试题库(含答案)
- 2025年食药监局考试题库
- 2024年下半年黑龙江省嫩江铁路有限责任公司校招笔试题带答案
- 2025廉洁答题题库与答案
- 整本书阅读教学课件
- 企业法制讲座课件
- 【高朋律师事务所】RWA发展研究报告:法律、监管和前瞻(2025年)
- 汽车网销电话邀约话术培训
- 2025年福州房地产市场分析报告
- 《大学生心理健康教育》课程教案
- 音乐感知:从听觉到绘画
- 手抄报设计花边课件
评论
0/150
提交评论