STM32中反转法矩阵短按键的应用 测试通过_第1页
STM32中反转法矩阵短按键的应用 测试通过_第2页
STM32中反转法矩阵短按键的应用 测试通过_第3页
STM32中反转法矩阵短按键的应用 测试通过_第4页
STM32中反转法矩阵短按键的应用 测试通过_第5页
已阅读5页,还剩2页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

本文格式为Word版,下载可任意编辑——STM32中反转法矩阵短按键的应用测试通过#include\//反转法测矩阵按键

voidDelay(__IOuint32_tt);voidRCC_Config(void);voidGPIO_Config(void);uint32_tKey_Scan(void);voidGPIO_RConfig(void);voidLED_Config(void);

voidDelay_ms(__IOuint32_ttime);voidTime_Delay(void);

voidGPIO_SetBits_Row(void);voidGPIO_ResetBits_Row(void);voidGPIO_SetBits_Col(void);voidGPIO_ResetBits_Col(void);

GPIO_InitTypeDefGPIO_InitStructure;static__IOuint32_tTimingDelay=0;

uint32_tnum=0;uint8_tj,i;//PA6PA7PB7PA5uint8_tkey[4][4]={0x01,0x05,0x09,0x0d,//PE150x02,0x06,0x0a,0x0e,//PE140x03,0x07,0x0b,0x0f,//PE130x04,0x08,0x0c,0x10};//PE11

structIO_Port{

GPIO_TypeDef*GPIO_X;unsignedshortGPIO_Pin;};

staticstructIO_Portkey_row[4]={

{GPIOE,GPIO_Pin_15},{GPIOE,GPIO_Pin_14},{GPIOE,GPIO_Pin_13},{GPIOE,GPIO_Pin_11}};

staticstructIO_Portkey_col[4]={

{GPIOA,GPIO_Pin_6},{GPIOA,GPIO_Pin_7},

1

{GPIOB,GPIO_Pin_7},{GPIOA,GPIO_Pin_5}};

intmain(void){

uint32_tkey=0;RCC_Config();LED_Config();

SysTick_Config(72000);

while(1){key=Key_Scan();switch(key){case0x01:

GPIO_WriteBit(GPIOB,GPIO_Pin_5,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_5)));break;case0x02:

GPIO_WriteBit(GPIOB,GPIO_Pin_5,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_5)));break;case0x03:

GPIO_WriteBit(GPIOB,GPIO_Pin_5,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_5)));break;case0x04:

GPIO_WriteBit(GPIOB,GPIO_Pin_5,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_5)));break;case0x05:

GPIO_WriteBit(GPIOB,GPIO_Pin_5,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_5)));break;

2

case0x06:

GPIO_WriteBit(GPIOB,GPIO_Pin_5,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_5)));break;case0x07:

GPIO_WriteBit(GPIOB,GPIO_Pin_5,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_5)));break;case0x08:

GPIO_WriteBit(GPIOB,GPIO_Pin_5,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_5)));break;case0x09:

GPIO_WriteBit(GPIOB,GPIO_Pin_5,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_5)));break;case0x0a:

GPIO_WriteBit(GPIOB,GPIO_Pin_5,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_5)));break;case0x0b:

GPIO_WriteBit(GPIOB,GPIO_Pin_5,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_5)));break;case0x0c:

GPIO_WriteBit(GPIOB,GPIO_Pin_5,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_5)));break;case0x0d:

GPIO_WriteBit(GPIOB,GPIO_Pin_5,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_5)));break;case0x0e:

GPIO_WriteBit(GPIOB,GPIO_Pin_5,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_5)));

3

break;case0x0f:

GPIO_WriteBit(GPIOB,GPIO_Pin_5,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_5)));break;case0x10:

GPIO_WriteBit(GPIOB,GPIO_Pin_5,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_5)));break;default:break;}

}}

voidGPIO_SetBits_Row(void){

uint8_ti;

for(i=0;i

num=key[j][i];}}}}

returnnum;}

voidRCC_Config(void){

SystemInit();

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|

RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE|RCC_APB2Periph_AFIO,ENABLE);}

voidGPIO_RConfig(void){

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;GPIO_Init(GPIOA,

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7;GPIO_Init(GPIOB,

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_11|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;GPIO_Init(GPIOE,}

voidGPIO_Config(void){

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_11|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;

6

GPIO_Init(GPIOE,

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;GPIO_Init(GPIOA,

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7;GPIO_Init(GPIOB,}

voidLED_Config(void){

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5;

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;GPIO_Init(GPIOB,GPIO_ResetBits(GPIOB,GPIO_Pin_5);}

voidDelay(__IOuint32_tt){

uin

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论