/**
******************************************************************************
* [url=home.php?mod=space&uid=288409]@file[/url] main.c
* [url=home.php?mod=space&uid=187600]@author[/url] AE team
* [url=home.php?mod=space&uid=895143]@version[/url] V1.1.1
* [url=home.php?mod=space&uid=212281]@date[/url] 15/05/2019
* @brief
******************************************************************************
* @copy
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, MindMotion SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>© COPYRIGHT 2019 MindMotion</center></h2>
*/
#include "HAL_device.h"
#include "HAL_conf.h"
#include "stdio.h"
void LED_Init(void);
void KEY_Init(void);
void EXTIX_Init(void);
#define LED4_ON() GPIO_ResetBits(GPIOA,GPIO_Pin_15) // PA15
#define LED4_OFF() GPIO_SetBits(GPIOA,GPIO_Pin_15) // PA15
#define LED4_TOGGLE() (GPIO_ReadOutputDataBit(GPIOA,GPIO_Pin_15))?(GPIO_ResetBits(GPIOA,GPIO_Pin_15)):(GPIO_SetBits(GPIOA,GPIO_Pin_15)) // PA15
#define LED3_ON() GPIO_ResetBits(GPIOB,GPIO_Pin_3) // PB3
#define LED3_OFF() GPIO_SetBits(GPIOB,GPIO_Pin_3) // PB3
#define LED3_TOGGLE() (GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_3))?(GPIO_ResetBits(GPIOB,GPIO_Pin_3)):(GPIO_SetBits(GPIOB,GPIO_Pin_3)) // PB3
#define LED2_ON() GPIO_ResetBits(GPIOB,GPIO_Pin_4) // PB4
#define LED2_OFF() GPIO_SetBits(GPIOB,GPIO_Pin_4) // PB4
#define LED2_TOGGLE() (GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_4))?(GPIO_ResetBits(GPIOB,GPIO_Pin_4)):(GPIO_SetBits(GPIOB,GPIO_Pin_4)) // PB4
#define LED1_ON() GPIO_ResetBits(GPIOB,GPIO_Pin_5) // PB5
#define LED1_OFF() GPIO_SetBits(GPIOB,GPIO_Pin_5) // PB5
#define LED1_TOGGLE() (GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_5))?(GPIO_ResetBits(GPIOB,GPIO_Pin_5)):(GPIO_SetBits(GPIOB,GPIO_Pin_5)) // PB5
#define KEY1 GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_13)//读取按键1
#define WK_UP GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)//读取按键2
#define KEY3 GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_10)//读取按键3
#define KEY4 GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_11)//读取按键4
#define KEY1_PRES 1 //KEY1
#define WKUP_PRES 2 //WK_UP
#define KEY3_PRES 3 //KEY3
#define KEY4_PRES 4 //KEY4
/********************************************************************************************************
**函数信息 :main(void)
**功能描述 :
**输入参数 :无
**输出参数 :无
********************************************************************************************************/
int main(void)
{
//GPIO口测试,闪烁LED灯
LED_Init(); //初始化与LED连接的硬件接口
KEY_Init(); //初始化与按键连接的硬件接口
EXTIX_Init();
while(1) {
}
}
/********************************************************************************************************
**函数信息 :LED_Init(void)
**功能描述 :LED初始化
**输入参数 :无
**输出参数 :无
********************************************************************************************************/
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB, ENABLE); //开启GPIOA,GPIOB时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
LED1_ON();
LED2_ON();
LED3_ON();
LED4_ON();
}
/********************************************************************************************************
**函数信息 :void KEY_Init(void)
**功能描述 :按键初始化函数
**输入参数 :
**输出参数 :
** 备注 :
********************************************************************************************************/
void KEY_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC, ENABLE); //使能GPIOA,GPIOB,GPIOC时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; //PC13,K1
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //设置成上拉输入
GPIO_Init(GPIOC, &GPIO_InitStructure); //初始化GPIOC13
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //PA0,K2(WK_UP)
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //设置成下拉输入
GPIO_Init(GPIOA, &GPIO_InitStructure); //初始化GPIOA0
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11; //PB10,PB11,K3,K4
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //设置成上拉输入
GPIO_Init(GPIOB, &GPIO_InitStructure); //初始化GPIOB.10,11
}
/********************************************************************************************************
**函数信息 :void EXTIX_Init(void)
**功能描述 :外部中断初始化函数
**输入参数 :
**输出参数 :
**常用函数 :
********************************************************************************************************/
void EXTIX_Init(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); //外部中断,需要使能AFIO时钟
KEY_Init(); //初始化按键对应io模式
//GPIOC.13 中断线以及中断初始化配置
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource13);
EXTI_InitStructure.EXTI_Line = EXTI_Line13;
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寄存器
//GPIOA.0 中断线以及中断初始化配置
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
EXTI_InitStructure.EXTI_Line = EXTI_Line0;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //上升沿触发
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure); //根据EXTI_InitStruct中指定的参数初始化外设EXTI寄存器
//GPIOB.10 中断线以及中断初始化配置
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource10);
EXTI_InitStructure.EXTI_Line = EXTI_Line10;
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寄存器
//GPIOB.11 中断线以及中断初始化配置
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource11);
EXTI_InitStructure.EXTI_Line = EXTI_Line11;
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寄存器
NVIC_InitStructure.NVIC_IRQChannel = EXTI4_15_IRQn; //使能按键所在的外部中断通道
NVIC_InitStructure.NVIC_IRQChannelPriority = 0x02; //子优先级2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道
NVIC_Init(&NVIC_InitStructure); //根据NVIC_InitStruct中指定的参数初始化外设NVIC寄存器
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_1_IRQn; //使能按键所在的外部中断通道
NVIC_InitStructure.NVIC_IRQChannelPriority = 0x01; //子优先级1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道
NVIC_Init(&NVIC_InitStructure);
}
/********************************************************************************************************
**函数信息 :void EXTI0_1_IRQHandler(void)
**功能描述 :外部中断函数
**输入参数 :
**输出参数 :
**常用函数 :
********************************************************************************************************/
u16 EXTI_DELAY = 0;
void EXTI0_1_IRQHandler(void)
{
for(EXTI_DELAY = 0; EXTI_DELAY < 1000; EXTI_DELAY++);
if(WK_UP == 1) {
LED2_TOGGLE();
}
EXTI_ClearFlag(EXTI_Line0); //清除EXTI0线路挂起位
}
/********************************************************************************************************
**函数信息 :void EXTI4_15_IRQHandler(void)
**功能描述 :外部中断函数
**输入参数 :
**输出参数 :
**常用函数 :
********************************************************************************************************/
void EXTI4_15_IRQHandler(void)
{
for(EXTI_DELAY = 0; EXTI_DELAY < 1000; EXTI_DELAY++);
if(KEY1 == 0) {
LED1_TOGGLE();
} else if(KEY3 == 0) {
LED3_TOGGLE();
} else if(KEY4 == 0) {
LED4_TOGGLE();
}
EXTI_ClearFlag(EXTI_Line10 | EXTI_Line11 | EXTI_Line13); //清除EXTI10,11,13线路挂起位
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/*-------------------------(C) COPYRIGHT 2019 MindMotion ----------------------*/