-
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.
- Loading branch information
Showing
55 changed files
with
12,781 additions
and
4,780 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
OBJ | ||
|
||
OBJ |
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,8 @@ | ||
{ | ||
"files.associations": { | ||
"sys.h": "c", | ||
"uart4.h": "c", | ||
"lora_app.h": "c", | ||
"lora_cfg.h": "c" | ||
} | ||
} |
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,17 @@ | ||
#include "beep.h" | ||
|
||
void BEEP_Init(void) | ||
{ | ||
GPIO_InitTypeDef GPIO_InitStructure; | ||
|
||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //使能GPIOB端口时钟 | ||
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //BEEP-->PB.8 端口配置 | ||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出 | ||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //速度为50MHz | ||
GPIO_Init(GPIOB, &GPIO_InitStructure); //根据参数初始化GPIOB.8 | ||
|
||
GPIO_ResetBits(GPIOB,GPIO_Pin_8);//输出0,关闭蜂鸣器输出 | ||
|
||
} | ||
|
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,13 @@ | ||
#ifndef __BEEP_H__ | ||
#define __BEEP_H__ | ||
|
||
|
||
#include "sys.h" | ||
|
||
//蜂鸣器端口定义 | ||
#define BEEP PBout(8) // BEEP,蜂鸣器接口 | ||
|
||
void BEEP_Init(void); //初始化 | ||
|
||
#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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
#include "includes.h" | ||
#include "delay.h" | ||
|
||
|
||
#include "key.h" | ||
#include "beep.h" | ||
#include "led.h" | ||
#include "usart.h" | ||
|
||
|
||
|
||
|
||
//按键初始化函数 | ||
void KEY_Init(void) //IO初始化 | ||
{ | ||
GPIO_InitTypeDef GPIO_InitStructure; | ||
EXTI_InitTypeDef EXTI_InitStructure; | ||
NVIC_InitTypeDef NVIC_InitStructure; | ||
|
||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOE,ENABLE);//使能PORTA,PORTE时钟 | ||
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4;//KEY0-KEY2 | ||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //设置成上拉输入 | ||
GPIO_Init(GPIOE, &GPIO_InitStructure);//初始化GPIOE2,3,4 | ||
|
||
//初始化 WK_UP-->GPIOA.0 下拉输入 | ||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; | ||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //PA0设置成输入,默认下拉 | ||
GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIOA.0 | ||
|
||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); //使能复用功能时钟 | ||
|
||
//GPIOE.2 中断线以及中断初始化配置 下降沿触发 | ||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE,GPIO_PinSource2); | ||
|
||
EXTI_InitStructure.EXTI_Line=EXTI_Line2; //KEY2 | ||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; | ||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; | ||
EXTI_InitStructure.EXTI_LineCmd = ENABLE; | ||
EXTI_Init(&EXTI_InitStructure); //根据EXTI_InitStruct中指定的参数初始化外设EXTI寄存器 | ||
|
||
//GPIOE.3 中断线以及中断初始化配置 下降沿触发 //KEY1 | ||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE,GPIO_PinSource3); | ||
EXTI_InitStructure.EXTI_Line=EXTI_Line3; | ||
EXTI_Init(&EXTI_InitStructure); //根据EXTI_InitStruct中指定的参数初始化外设EXTI寄存器 | ||
|
||
//GPIOE.4 中断线以及中断初始化配置 下降沿触发 //KEY0 | ||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE,GPIO_PinSource4); | ||
EXTI_InitStructure.EXTI_Line=EXTI_Line4; | ||
EXTI_Init(&EXTI_InitStructure); //根据EXTI_InitStruct中指定的参数初始化外设EXTI寄存器 | ||
|
||
|
||
//GPIOA.0 中断线以及中断初始化配置 上升沿触发 PA0 WK_UP | ||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0); | ||
|
||
EXTI_InitStructure.EXTI_Line=EXTI_Line0; | ||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; | ||
EXTI_Init(&EXTI_InitStructure); //根据EXTI_InitStruct中指定的参数初始化外设EXTI寄存器 | ||
|
||
|
||
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; //使能按键WK_UP所在的外部中断通道 | ||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //抢占优先级2, | ||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x03; //子优先级3 | ||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道 | ||
NVIC_Init(&NVIC_InitStructure); | ||
|
||
NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn; //使能按键KEY2所在的外部中断通道 | ||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //抢占优先级2, | ||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02; //子优先级2 | ||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道 | ||
NVIC_Init(&NVIC_InitStructure); | ||
|
||
|
||
NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn; //使能按键KEY1所在的外部中断通道 | ||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //抢占优先级2 | ||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01; //子优先级1 | ||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道 | ||
NVIC_Init(&NVIC_InitStructure); //根据NVIC_InitStruct中指定的参数初始化外设NVIC寄存器 | ||
|
||
NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQn; //使能按键KEY0所在的外部中断通道 | ||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //抢占优先级2 | ||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00; //子优先级0 | ||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道 | ||
NVIC_Init(&NVIC_InitStructure); //根据NVIC_InitStruct中指定的参数初始化外设NVIC寄存器 | ||
//初始化外设NVIC寄存器 | ||
} | ||
|
||
//外部中断0服务程序 | ||
void EXTI0_IRQHandler(void) | ||
{ | ||
OS_ERR err; | ||
|
||
//进入中断 | ||
OSIntEnter(); | ||
|
||
if(EXTI_GetITStatus(EXTI_Line0) == SET) //WK_UP按键 | ||
{ | ||
printf("WK_UP happend\r\n"); | ||
//设置事件标志组 | ||
OSFlagPost(&g_flag_grp,FLAG_GRP_WK_UP_DOWN,OS_OPT_POST_FLAG_SET,&err); | ||
EXTI_ClearITPendingBit(EXTI_Line0); //清除LINE0上的中断标志位 | ||
} | ||
|
||
//退出中断 | ||
OSIntExit(); | ||
} | ||
|
||
//外部中断2服务程序 | ||
void EXTI2_IRQHandler(void) | ||
{ | ||
|
||
OS_ERR err; | ||
|
||
//进入中断 | ||
OSIntEnter(); | ||
|
||
if(EXTI_GetITStatus(EXTI_Line2) == SET) //按键KEY2 | ||
{ | ||
printf("key2222 happend\r\n"); | ||
//设置事件标志组 | ||
OSFlagPost(&g_flag_grp,FLAG_GRP_KEY2_DOWN,OS_OPT_POST_FLAG_SET,&err); | ||
//清除LINE2上的中断标志位 | ||
EXTI_ClearITPendingBit(EXTI_Line2); | ||
} | ||
//退出中断 | ||
OSIntExit(); | ||
|
||
} | ||
//外部中断3服务程序 | ||
void EXTI3_IRQHandler(void) | ||
{ | ||
|
||
OS_ERR err; | ||
|
||
//进入中断 | ||
OSIntEnter(); | ||
|
||
if(EXTI_GetITStatus(EXTI_Line3) == SET) //按键KEY1 | ||
{ | ||
printf("key1111 happend\r\n"); | ||
//设置事件标志组 | ||
OSFlagPost(&g_flag_grp,FLAG_GRP_KEY1_DOWN,OS_OPT_POST_FLAG_SET,&err); | ||
//清除LINE3上的中断标志位 | ||
EXTI_ClearITPendingBit(EXTI_Line3); | ||
} | ||
//退出中断 | ||
OSIntExit(); | ||
} | ||
|
||
//void EXTI4_IRQHandler(void) | ||
//{ | ||
// | ||
// OS_ERR err; | ||
// | ||
// //进入中断 | ||
// OSIntEnter(); | ||
|
||
// if(EXTI_GetITStatus(EXTI_Line4) == SET) //按键KEY0 | ||
// { | ||
// printf("key0000 happend\r\n"); | ||
// //设置事件标志组 | ||
// OSFlagPost(&g_flag_grp,FLAG_GRP_KEY0_DOWN,OS_OPT_POST_FLAG_SET,&err); | ||
// //清除LINE4上的中断标志位 | ||
// EXTI_ClearITPendingBit(EXTI_Line4); | ||
// } | ||
// //退出中断 | ||
// OSIntExit(); | ||
//} | ||
|
||
//按键处理函数 | ||
//返回按键值 | ||
//mode:0,不支持连续按;1,支持连续按; | ||
//0,没有任何按键按下 | ||
//1,KEY0按下 | ||
//2,KEY1按下 | ||
//3,KEY2按下 | ||
//4,KEY3按下 WK_UP | ||
//注意此函数有响应优先级,KEY0>KEY1>KEY2>KEY3!! | ||
u8 KEY_Scan(u8 mode) | ||
{ | ||
static u8 key_up=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 KEY0_PRES; | ||
else if(KEY1==0)return KEY1_PRES; | ||
else if(KEY2==0)return KEY2_PRES; | ||
else if(WK_UP==1)return WKUP_PRES; | ||
}else if(KEY0==1&&KEY1==1&&KEY2==1&&WK_UP==0)key_up=1; | ||
return 0;// 无按键按下 | ||
} |
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,25 @@ | ||
#ifndef __KEY_H | ||
#define __KEY_H | ||
#include "sys.h" | ||
|
||
//#define KEY0 PEin(4) //PE4 | ||
//#define KEY1 PEin(3) //PE3 | ||
//#define KEY2 PEin(2) //PE2 | ||
//#define WK_UP PAin(0) //PA0 WK_UP | ||
|
||
#define KEY0 GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_4)//读取按键0 | ||
#define KEY1 GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_3)//读取按键1 | ||
#define KEY2 GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_2)//读取按键2 | ||
#define WK_UP GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)//读取按键3(WK_UP) | ||
|
||
|
||
|
||
#define KEY0_PRES 1 //KEY0按下 | ||
#define KEY1_PRES 2 //KEY1按下 | ||
#define KEY2_PRES 3 //KEY2按下 | ||
#define WKUP_PRES 4 //KEY_UP按下(即WK_UP/KEY_UP) | ||
|
||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,21 @@ | ||
#include "led.h" | ||
|
||
////////////////////////////////////////////////////////////////////////////////// | ||
//本程序只供学习使用,未经作者许可,不得用于其它任何用途 | ||
//ALIENTEK战舰STM32开发板 | ||
//LED驱动代码 | ||
//正点原子@ALIENTEK | ||
//技术论坛:www.openedv.com | ||
//修改日期:2012/9/2 | ||
//版本:V1.0 | ||
//版权所有,盗版必究。 | ||
//Copyright(C) 广州市星翼电子科技有限公司 2009-2019 | ||
//All rights reserved | ||
////////////////////////////////////////////////////////////////////////////////// | ||
|
||
//初始化PB5和PE5为输出口.并使能这两个口的时钟 | ||
//LED IO初始化 | ||
void LED_Init(void) | ||
{ | ||
|
||
GPIO_InitTypeDef GPIO_InitStructure; | ||
|
||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOE, ENABLE); //使能PB,PE端口时钟 | ||
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //LED0-->PB.5 端口配置 | ||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出 | ||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz | ||
GPIO_Init(GPIOB, &GPIO_InitStructure); //根据设定参数初始化GPIOB.5 | ||
GPIO_SetBits(GPIOB,GPIO_Pin_5); //PB.5 输出高 | ||
{ | ||
GPIO_InitTypeDef GPIO_InitStructure; | ||
|
||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOE, ENABLE); //使能PB,PE端口时钟 | ||
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //LED0-->PB.5 端口配置 | ||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出 | ||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz | ||
GPIO_Init(GPIOB, &GPIO_InitStructure); //根据设定参数初始化GPIOB.5 | ||
GPIO_SetBits(GPIOB,GPIO_Pin_5); //PB.5 输出高 | ||
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //LED1-->PE.5 端口配置, 推挽输出 | ||
GPIO_Init(GPIOE, &GPIO_InitStructure); //推挽输出 ,IO口速度为50MHz | ||
GPIO_SetBits(GPIOE,GPIO_Pin_5); //PE.5 输出高 | ||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //LED1-->PE.5 端口配置, 推挽输出 | ||
GPIO_Init(GPIOE, &GPIO_InitStructure); //推挽输出 ,IO口速度为50MHz | ||
GPIO_SetBits(GPIOE,GPIO_Pin_5); //PE.5 输出高 | ||
} | ||
|
Oops, something went wrong.