This repository has been archived by the owner on Mar 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
按着网友的代码做了简要修改,添加了三角波,矩形波,锯齿波(按键不够就没有加锯齿波,但是代码里有),同时有运行和暂停功能。 实验时把 PA5 和 PA4 短接,或把探索者开发板右下方 DAC 和 ADC 短接
- Loading branch information
Showing
17 changed files
with
4,363 additions
and
3,445 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include "key.h" | ||
#include "delay.h" | ||
#include "lcd.h" | ||
////////////////////////////////////////////////////////////////////////////////// | ||
//本程序只供学习使用,未经作者许可,不得用于其它任何用途 | ||
//ALIENTEK STM32F407开发板 | ||
//按键输入驱动代码 | ||
//正点原子@ALIENTEK | ||
//技术论坛:www.openedv.com | ||
//创建日期:2014/5/3 | ||
//版本:V1.0 | ||
//版权所有,盗版必究。 | ||
//Copyright(C) 广州市星翼电子科技有限公司 2014-2024 | ||
//All rights reserved | ||
////////////////////////////////////////////////////////////////////////////////// | ||
|
||
//按键初始化函数 | ||
void KEY_Init(void) | ||
{ | ||
|
||
GPIO_InitTypeDef GPIO_InitStructure; | ||
|
||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOE, ENABLE);//使能GPIOA,GPIOE时钟 | ||
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4; //KEY0 KEY1 KEY2对应引脚 | ||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//普通输入模式 | ||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100M | ||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 | ||
GPIO_Init(GPIOE, &GPIO_InitStructure);//初始化GPIOE2,3,4 | ||
|
||
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;//WK_UP对应引脚PA0 | ||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;//下拉 | ||
GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIOA0 | ||
|
||
} | ||
//按键处理函数 | ||
//返回按键值 | ||
//mode:0,不支持连续按;1,支持连续按; | ||
//0,没有任何按键按下 | ||
//1,KEY0按下 | ||
//2,KEY1按下 | ||
//3,KEY2按下 | ||
//4,WKUP按下 WK_UP | ||
//注意此函数有响应优先级,KEY0>KEY1>KEY2>WK_UP!! | ||
u8 KEY_Scan(u8 mode) | ||
{ | ||
static u8 key_up=1;//按键按松开标志u | ||
//u8 runstop=1; | ||
|
||
if(mode)key_up=1; //支持连按 | ||
if(key_up&&(KEY0==0||KEY1==0||KEY2==0||WK_UP==1)) | ||
{ | ||
delay_ms(10);//去抖动 | ||
key_up=0; | ||
if(KEY0==0)return 0; | ||
else if(KEY1==0)return 2; | ||
else if(KEY2==0)return 3; | ||
else if(WK_UP==1)return 4; | ||
}else if(KEY0==1&&KEY1==1&&KEY2==1&&WK_UP==0)key_up=1; | ||
return 1;// 无按键按下 | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifndef __KEY_H | ||
#define __KEY_H | ||
#include "sys.h" | ||
////////////////////////////////////////////////////////////////////////////////// | ||
//本程序只供学习使用,未经作者许可,不得用于其它任何用途 | ||
//ALIENTEK STM32F407开发板 | ||
//按键输入驱动代码 | ||
//正点原子@ALIENTEK | ||
//技术论坛:www.openedv.com | ||
//创建日期:2014/5/3 | ||
//版本:V1.0 | ||
//版权所有,盗版必究。 | ||
//Copyright(C) 广州市星翼电子科技有限公司 2014-2024 | ||
//All rights reserved | ||
////////////////////////////////////////////////////////////////////////////////// | ||
|
||
/*下面的方式是通过直接操作库函数方式读取IO*/ | ||
#define KEY0 GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_4) //PE4 | ||
#define KEY1 GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_3) //PE3 | ||
#define KEY2 GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_2) //PE2 | ||
#define WK_UP GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0) //PA0 | ||
|
||
|
||
/*下面方式是通过位带操作方式读取IO*/ | ||
/* | ||
#define KEY0 PEin(4) //PE4 | ||
#define KEY1 PEin(3) //PE3 | ||
#define KEY2 PEin(2) //P32 | ||
#define WK_UP PAin(0) //PA0 | ||
*/ | ||
|
||
|
||
#define KEY0_PRES 1 | ||
#define KEY1_PRES 2 | ||
#define KEY2_PRES 3 | ||
#define WKUP_PRES 4 | ||
|
||
void KEY_Init(void); //IO初始化 | ||
u8 KEY_Scan(u8); //按键扫描函数 | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.