📄 user_key.c
字号:
/****************************************Copyright (c)**************************************************
** 思 蜕 盟 豆 皮 开 发 小 组
** stmfans 论坛
**
** QQ 群: 65081316 StmFans思蜕盟 1组
** QQ 群: 68584951 StmFans思蜕盟 2组
** http://www.stmfans.com/bbs/
**
** This program was produced by the
** IAR Embedded Workbench 4.0 Kickstart 442
** Copyright 2008-2009 stmfans
** Chip type : STM32F103VB
** Program type : Application
** Clock frequency : 8.000000 MHz
** Memory model :
** External SRAM size :
** Data Stack size :
**--------------文件信息--------------------------------------------------------------------------------
**文 件 名: user_key.c
**创 建 人: 陈海
**最后修改日期: 2008年10月23日
**描 述: 豆皮开发板教程
**
**--------------历史版本信息----------------------------------------------------------------------------
** 创建人: 陈海
** 版 本: v0.01
** 日 期: 2008年10月23日
** 描 述: 原始版本
**
**--------------当前版本信息----------------------------------------------------------------------------
** 创建人: 陈海
** 版 本: v0.01
** 日 期: 2008年10月23日
** 描 述: 当前版本
**
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "user_key.h"
/*******************************************************************************
* Function Name : GPIO_Configuration
* Description : Configures the different GPIO ports.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void KEY_GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
/*******************************************************************************
* Function Name : KEY_GPIO_Scanning
* Description : Configures the KEY GPIO ports.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
u8 KEY_GPIO_Scanning(void)
{
u8 scan_bit; //单个按键扫描变量
u8 scan_sum; //四个按键总的情况变量 scan_sum低四位的每一位对应一个按键
scan_bit = 0;
scan_sum = 0;
//扫描按键
scan_bit = GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_8);
//如果按键按下 则延迟 再扫描 然后根据判断处理
if( 0x01 == scan_bit )
{
Delay_Ms(40);
scan_bit = 0;
scan_bit = GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_8);
if( 0x01 == scan_bit )
scan_sum |= GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_8);
scan_bit = 0;
}
scan_bit = GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_7);
if( 0x01 == scan_bit )
{
Delay_Ms(40);
scan_bit = 0;
scan_bit = GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_7);
if( 0x01 == scan_bit )
scan_sum |= GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_7)<<1;
scan_bit = 0;
}
scan_bit = GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_6);
if( 0x01 == scan_bit )
{
Delay_Ms(40);
scan_bit = 0;
scan_bit = GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_6);
if( 0x01 == scan_bit )
scan_sum |= GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_6)<<2;
scan_bit = 0;
}
scan_bit = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_15);
if( 0x01 == scan_bit )
{
Delay_Ms(40);
scan_bit = 0;
scan_bit = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_15);
if( 0x01 == scan_bit )
scan_sum |= GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_15)<<3;
scan_bit = 0;
}
return scan_sum;
}
/*******************************************************************************
* Function Name : LED_For_Key_Shine
* Description : Configures the different GPIO ports.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void LED_For_Key_Shine(u8 scan_sum)
{
//使用一个8位变量 表示当前是否有按键按下
u8 key_count = 4 ;
if( scan_sum & 0x01 )
{
GPIO_SetBits(GPIOD, GPIO_Pin_2);
key_count--;
}
else
{
GPIO_ResetBits(GPIOD, GPIO_Pin_2);
key_count++;
Uart1_PutString("Key 1 Press\n" , strlen("Key 1 Press\n"));
}
if( scan_sum & 0x02 )
{
GPIO_SetBits(GPIOD, GPIO_Pin_3);
key_count--;
}
else
{
GPIO_ResetBits(GPIOD, GPIO_Pin_3);
key_count++;
Uart1_PutString("Key 2 Press\n" , strlen("Key 2 Press\n"));
}
if( scan_sum & 0x04 )
{
GPIO_SetBits(GPIOD, GPIO_Pin_4);
key_count--;
}
else
{
GPIO_ResetBits(GPIOD, GPIO_Pin_4);
key_count++;
Uart1_PutString("Key 3 Press\n" , strlen("Key 3 Press\n"));
}
if( scan_sum & 0x08 )
{
GPIO_SetBits(GPIOD, GPIO_Pin_5);
key_count--;
}
else
{
GPIO_ResetBits(GPIOD, GPIO_Pin_5);
key_count++;
Uart1_PutString("Key 4 Press\n" , strlen("Key 4 Press\n"));
}
//如果 key_count为0 则表示当前没有按键被按下 蜂鸣器不响
if( key_count == 0 )
GPIO_ResetBits(GPIOB, GPIO_Pin_9);
else
{
GPIO_SetBits(GPIOB, GPIO_Pin_9);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -