STM矩阵键盘程序Word文件下载.docx

上传人:b****4 文档编号:6443606 上传时间:2023-05-06 格式:DOCX 页数:11 大小:15.36KB
下载 相关 举报
STM矩阵键盘程序Word文件下载.docx_第1页
第1页 / 共11页
STM矩阵键盘程序Word文件下载.docx_第2页
第2页 / 共11页
STM矩阵键盘程序Word文件下载.docx_第3页
第3页 / 共11页
STM矩阵键盘程序Word文件下载.docx_第4页
第4页 / 共11页
STM矩阵键盘程序Word文件下载.docx_第5页
第5页 / 共11页
STM矩阵键盘程序Word文件下载.docx_第6页
第6页 / 共11页
STM矩阵键盘程序Word文件下载.docx_第7页
第7页 / 共11页
STM矩阵键盘程序Word文件下载.docx_第8页
第8页 / 共11页
STM矩阵键盘程序Word文件下载.docx_第9页
第9页 / 共11页
STM矩阵键盘程序Word文件下载.docx_第10页
第10页 / 共11页
STM矩阵键盘程序Word文件下载.docx_第11页
第11页 / 共11页
亲,该文档总共11页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

STM矩阵键盘程序Word文件下载.docx

《STM矩阵键盘程序Word文件下载.docx》由会员分享,可在线阅读,更多相关《STM矩阵键盘程序Word文件下载.docx(11页珍藏版)》请在冰点文库上搜索。

STM矩阵键盘程序Word文件下载.docx

keyboard.h"

dealy.h"

/*--------------------------------矩阵键盘初始化----------------------------------------*功能:

初始化stm32单片机GPIO//PA0-PA7

*参数传递:

*输入:

*返回值:

voidKeyBoard_Init(void)

{

GPIO_InitTypeDefGPIO_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=GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPD;

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);

}

/*------------------------------矩阵键盘扫描--------------------------------------------*功能:

扫描矩阵键盘,并返回键值

*参数:

*返回:

有键按下返回该键值

*无键按下时则返回0

u8Read_KeyValue(void)

u8KeyValue=0;

if((GPIO_ReadInputData(GPIOA)&

0xff)!

=0x0f)

Delay_ms(10);

GPIO_SetBits(GPIOA,GPIO_Pin_0);

GPIO_ResetBits(GPIOA,GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3);

switch(GPIO_ReadInputData(GPIOA)&

0xff)

case0x11:

KeyValue=1;

break;

case0x21:

KeyValue=5;

case0x41:

KeyValue=9;

case0x81:

KeyValue=13;

break;

GPIO_SetBits(GPIOA,GPIO_Pin_1);

GPIO_ResetBits(GPIOA,GPIO_Pin_0|GPIO_Pin_2|GPIO_Pin_3);

case0x12:

KeyValue=2;

case0x22:

KeyValue=6;

case0x42:

KeyValue=10;

case0x82:

KeyValue=14;

GPIO_SetBits(GPIOA,GPIO_Pin_2);

GPIO_ResetBits(GPIOA,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_3);

case0x14:

KeyValue=3;

case0x24:

KeyValue=7;

case0x44:

KeyValue=11;

case0x84:

KeyValue=15;

GPIO_SetBits(GPIOA,GPIO_Pin_3);

GPIO_ResetBits(GPIOA,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2);

case0x18:

KeyValue=4;

case0x28:

KeyValue=8;

case0x48:

KeyValue=12;

case0x88:

KeyValue=16;

GPIO_ResetBits(GPIOA,GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|

GPIO_Pin_7);

while((GPIO_ReadInputData(GPIOA)&

=0x0f);

returnKeyValue;

return0;

/*--------------------------------THEEND--------------------------------------------*/

keyboard.h

驱动为ST3.5库编写,适用于STM32F10x系列单片机

2013年11月22日

*版本:

1.0

#ifndef__KEYBOARD_H

#define__KEYBOARD_H

voidKeyBoard_Init(void);

u8Read_KeyValue(void);

#endif

/*----------------------------------THEEND------------------------------------------*

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_All;

GPIO_InitStructure.GPIO_Speed=GPIO_Speed_2MHz;

GPIO_Init(GPIOB,&

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);

//3?

ê

?

ˉPA,PB

voidDelay_ms(inttime){

inti=0;

while(time--)

{

i=12000;

while(i--);

}

u8KeyValue=1;

if((GPIO_ReadInputData(GPIOB)&

Delay_ms(10);

GPIO_SetBits(GPIOB,GPIO_Pin_3);

GPIO_ResetBits(GPIOB,GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6);

switch(GPIO_ReadInputData(GPIOB)&

KeyValue=0;

GPIO_SetBits(GPIOB,GPIO_Pin_4);

GPIO_ResetBits(GPIOB,GPIO_Pin_3|GPIO_Pin_5|GPIO_Pin_6);

GPIO_SetBits(GPIOB,GPIO_Pin_5);

GPIO_ResetBits(GPIOB,GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_6);

GPIO_SetBits(GPIOB,GPIO_Pin_6);

GPIO_ResetBits(GPIOB,GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5);

//while((GPIO_ReadInputData(GPIOB)&

uint16_ttable[]={0xEB,0x28,0xB3,0xBA,0x78,0xDA,0xDB,0xA8,0xFB,0xFA};

intmain(){

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);

KeyBoard_Init();

intkeyvalue=Read_KeyValue();

GPIO_Write(GPIOA,table[keyvalue]);

/*while

(1){

inti;

for(i=0;

i<

10;

i++){

GPIO_Write(GPIOA,table[i]);

Delay_ms(500);

}*/

/*u8keyvalue;

for(inti=0;

;

KeyBoard_Init();

keyvalue=Read_KeyValue();

GPIO_Write(GPIOA,table[keyvalue]);

}*/

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10;

=0x73)

//在这个程序下为什么无论是GPIO_ReadInputData(GPIOB)&

=0x73还是GPIO_ReadInputData(GPIOB)&

0xff)==0x73都能往下运行,而在屏蔽Delay_ms(10)后则只能运行一种,是因为这个Delay_ms(10)对if里的判断有影响吗?

GPIO_Write(GPIOA,0x33);

Read_KeyValue();

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 求职职场 > 自我管理与提升

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2