PS2摇杆问题未解决

This commit is contained in:
zhan-min 2020-10-29 08:46:25 +08:00
parent 48ba6d81fb
commit a3f4581804
12 changed files with 2198 additions and 2166 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -674,7 +674,7 @@
<GroupNumber>4</GroupNumber>
<FileNumber>37</FileNumber>
<FileType>1</FileType>
<tvExp>1</tvExp>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\User\PS2\bsp_PS2.c</PathWithFileName>

View File

@ -16,7 +16,7 @@
<TargetCommonOption>
<Device>STM32F103VE</Device>
<Vendor>STMicroelectronics</Vendor>
<PackID>Keil.STM32F1xx_DFP.2.1.0</PackID>
<PackID>Keil.STM32F1xx_DFP.2.0.0</PackID>
<PackURL>http://www.keil.com/pack/</PackURL>
<Cpu>IRAM(0x20000000,0x10000) IROM(0x08000000,0x80000) CPUTYPE("Cortex-M3") CLOCK(12000000) ELITTLE</Cpu>
<FlashUtilSpec></FlashUtilSpec>

View File

@ -8,6 +8,7 @@
#include "bsp_PS2.h"
#define MeasurementRange 30
/*
@ -199,18 +200,19 @@ void Key_Scan(void* parameter)
queue_status = rt_mq_recv(key_scan_queue, &recv_data, sizeof(recv_data), RT_WAITING_FOREVER);
if(queue_status == RT_EOK && recv_data == 1)
{
setting_data = Read_X_Data(PS2_X_PORT, PS2_X_PIN);
setting_data = Read_X_Data();
if(setting_data == 1)
setting_data = 1;
else if(setting_data == 0)
setting_data = 2;
setting_data = Read_Y_Data(PS2_Y_PORT, PS2_Y_PIN);
setting_data = Read_Y_Data();
if(setting_data == 1)
setting_data = 3;
else if(setting_data == 0)
setting_data = 4;
rt_kprintf("key data: %d",setting_data);
rt_mq_send(setting_data_queue, &setting_data, sizeof(setting_data));
}
}
@ -226,11 +228,14 @@ void Run(void)
key_scan_queue = rt_mq_create("key_scan_queue", 1, 1, RT_IPC_FLAG_FIFO);
/**********创建线程************/
Setting_thread =
rt_thread_create("Setting", Setting, RT_NULL, 512, 1, 20);
Setting_thread = rt_thread_create("Setting", Setting, RT_NULL, 512, 1, 20);
if (Setting_thread != RT_NULL)
rt_thread_startup(Setting_thread);
KeyScan_thread = rt_thread_create("KeyScan", Key_Scan, RT_NULL, 512, 2, 20);
if (KeyScan_thread != RT_NULL)
rt_thread_startup(KeyScan_thread);
GetWave_thread = /* 线程控制块指针 */
rt_thread_create( "GetWave", /* 线程名字 */
ADCx_GetWaveData, /* 线程入口函数 */
@ -250,10 +255,6 @@ void Run(void)
20); /* 线程时间片 */
if (PlotWave_thread != RT_NULL)
rt_thread_startup(PlotWave_thread);
KeyScan_thread = rt_thread_create("KeyScan", Key_Scan, RT_NULL, 512, 2, 20);
if(KeyScan_thread != RT_NULL)
rt_thread_startup(KeyScan_thread);
}

View File

@ -1,69 +1,71 @@
#include "bsp_PS2.h"
#include "stm32f10x_gpio.h"
static void EXTI_NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStruct;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
//配置PS2的SW中断
NVIC_InitStruct.NVIC_IRQChannel = EXTI2_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
}
static void PS2_Key_Config(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
EXTI_InitTypeDef EXTI_InitStruct;
//配置中断优先级
EXTI_NVIC_Config();
//初始化GPIO
RCC_APB2PeriphClockCmd(PS2_SW_CLK, ENABLE);
RCC_APB2PeriphClockCmd(PS2_X_CLK, ENABLE);
RCC_APB2PeriphClockCmd(PS2_Y_CLK, ENABLE);
//初始化SW
GPIO_InitStruct.GPIO_Pin = PS2_SW_PIN;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(PS2_SW_PORT, &GPIO_InitStruct);
//初始化X
GPIO_InitStruct.GPIO_Pin = PS2_X_PIN;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(PS2_X_PORT, &GPIO_InitStruct);
//初始化Y
GPIO_InitStruct.GPIO_Pin = PS2_Y_PIN;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(PS2_Y_PORT, &GPIO_InitStruct);
//初始化EXTI
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource2);
//初始化SW中断
EXTI_InitStruct.EXTI_Line = EXTI_Line2;
EXTI_InitStruct.EXTI_Mode= EXTI_Mode_Interrupt;
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStruct);
}
uint8_t Read_X_Data(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
{
return GPIO_ReadInputDataBit(PS2_X_PORT, PS2_X_PIN);
}
uint8_t Read_Y_Data(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
{
return GPIO_ReadInputDataBit(PS2_Y_PORT, PS2_Y_PIN);
}
#include "bsp_PS2.h"
#include "stm32f10x_gpio.h"
static void EXTI_NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStruct;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
//配置PS2的SW中断
NVIC_InitStruct.NVIC_IRQChannel = EXTI2_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
}
void PS2_Key_Config(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
EXTI_InitTypeDef EXTI_InitStruct;
//配置中断优先级
EXTI_NVIC_Config();
//初始化GPIO
RCC_APB2PeriphClockCmd(PS2_SW_CLK, ENABLE);
RCC_APB2PeriphClockCmd(PS2_X_CLK, ENABLE);
RCC_APB2PeriphClockCmd(PS2_Y_CLK, ENABLE);
//初始化SW
GPIO_InitStruct.GPIO_Pin = PS2_SW_PIN;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(PS2_SW_PORT, &GPIO_InitStruct);
//初始化X
GPIO_InitStruct.GPIO_Pin = PS2_X_PIN;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(PS2_X_PORT, &GPIO_InitStruct);
//初始化Y
GPIO_InitStruct.GPIO_Pin = PS2_Y_PIN;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(PS2_Y_PORT, &GPIO_InitStruct);
//初始化EXTI
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource2);
//初始化SW中断
EXTI_InitStruct.EXTI_Line = EXTI_Line2;
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStruct);
}
uint8_t Read_X_Data(void)
{
return GPIO_ReadInputDataBit(PS2_X_PORT, PS2_X_PIN);
}
uint8_t Read_Y_Data(void)
{
return GPIO_ReadInputDataBit(PS2_Y_PORT, PS2_Y_PIN);
}
uint8_t Read_SW_Data(void)
{
return GPIO_ReadInputDataBit(PS2_SW_PORT, PS2_SW_PIN);
}

View File

@ -1,23 +1,24 @@
#ifndef __bsp_PS2_H
#define __bsp_PS2_H
#include "stm32f10x.h"
#define PS2_SW_PIN GPIO_Pin_2
#define PS2_SW_PORT GPIOA
#define PS2_SW_CLK RCC_APB2Periph_GPIOA
#define PS2_X_PIN GPIO_Pin_5
#define PS2_X_PORT GPIOB
#define PS2_X_CLK RCC_APB2Periph_GPIOB
#define PS2_Y_PIN GPIO_Pin_6
#define PS2_Y_PORT GPIOB
#define PS2_Y_CLK RCC_APB2Periph_GPIOB
uint8_t Read_X_Data(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
uint8_t Read_Y_Data(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
#endif /* __bsp_PS2_H */
#ifndef __bsp_PS2_H
#define __bsp_PS2_H
#include "stm32f10x.h"
#define PS2_SW_PIN GPIO_Pin_2
#define PS2_SW_PORT GPIOA
#define PS2_SW_CLK RCC_APB2Periph_GPIOA
#define PS2_X_PIN GPIO_Pin_14
#define PS2_X_PORT GPIOB
#define PS2_X_CLK RCC_APB2Periph_GPIOB
#define PS2_Y_PIN GPIO_Pin_15
#define PS2_Y_PORT GPIOB
#define PS2_Y_CLK RCC_APB2Periph_GPIOB
void PS2_Key_Config(void);
uint8_t Read_X_Data(void);
uint8_t Read_Y_Data(void);
uint8_t Read_SW_Data(void);
#endif /* __bsp_PS2_H */

View File

@ -1,130 +1,144 @@
/* 开发板硬件相关头文件 */
#include "board.h"
#include "bsp_ili9341_lcd.h"
#include "bsp_adc.h"
#include "bsp_TiMbase.h"
/* RT-Thread相关头文件 */
#include <rthw.h>
#include <rtthread.h>
#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
#define RT_HEAP_SIZE 1024
/* 从内部SRAM里面分配一部分静态内存来作为rtt的堆空间这里配置为4KB */
static uint32_t rt_heap[RT_HEAP_SIZE];
RT_WEAK void *rt_heap_begin_get(void)
{
return rt_heap;
}
RT_WEAK void *rt_heap_end_get(void)
{
return rt_heap + RT_HEAP_SIZE;
}
#endif
/**
* @brief
* @param
* @retval
*
* @attention
* RTT把开发板相关的初始化函数统一放到board.c文件中实现
* main.c文件也是可以的
*/
void rt_hw_board_init()
{
/* 初始化SysTick */
SysTick_Config( SystemCoreClock / RT_TICK_PER_SECOND );
/* 硬件BSP初始化统统放在这里比如LED串口LCD等 */
ILI9341_Init ();//LCD 初始化
LED_GPIO_Config();
USART_Config();
ADCx_Init();
EXTI_Key_Config();
BASIC_TIM_Init();
//其中0、3、5、6 模式适合从左至右显示文字,
//不推荐使用其它模式显示文字 其它模式显示文字会有镜像效果
//其中 6 模式为大部分液晶例程的默认显示方向
ILI9341_GramScan ( 3 );
LCD_SetColors(WHITE, BLACK);
ILI9341_Clear(0,0,LCD_X_LENGTH,LCD_Y_LENGTH);
ILI9341_Clear(200, 0, 320, (((sFONT *)LCD_GetFont())->Height));
ILI9341_DispString_EN(210, 0,"T: 2ms");
/* 调用组件初始化函数 (use INIT_BOARD_EXPORT()) */
#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();
#endif
#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get());
#endif
}
/**
* @brief SysTick中断服务函数
* @param
* @retval
*
* @attention
* SysTick中断服务函数在固件库文件stm32f10x_it.c中也定义了
* board.c中又定义一次
* stm32f10x_it.c中的注释或者删除即可
*/
void SysTick_Handler(void)
{
/* 进入中断 */
rt_interrupt_enter();
/* 更新时基 */
rt_tick_increase();
/* 离开中断 */
rt_interrupt_leave();
}
/**
* @brief DEBUG_USARTx到rt_kprintf()
* NoteDEBUG_USARTx是在bsp_usart.h中定义的宏使1
* @param str
* @retval
*
* @attention
*
*/
void rt_hw_console_output(const char *str)
{
/* 进入临界段 */
rt_enter_critical();
/* 直到字符串结束 */
while (*str!='\0')
{
/* 换行 */
if (*str=='\n')
{
USART_SendData(DEBUG_USARTx, '\r');
while (USART_GetFlagStatus(DEBUG_USARTx, USART_FLAG_TXE) == RESET);
}
USART_SendData(DEBUG_USARTx, *str++);
while (USART_GetFlagStatus(DEBUG_USARTx, USART_FLAG_TXE) == RESET);
}
/* 退出临界段 */
rt_exit_critical();
}
/*
*************************************************************************
*
*************************************************************************
*/
/* STM32 固件库头文件 */
#include "stm32f10x.h"
/* 开发板硬件bsp头文件 */
#include "board.h"
#include "bsp_ili9341_lcd.h"
#include "bsp_adc.h"
#include "bsp_TiMbase.h"
#include "bsp_led.h"
#include "bsp_usart.h"
#include "bsp_key_exti.h"
#include "bsp_PS2.h"
/* RT-Thread相关头文件 */
#include <rthw.h>
#include <rtthread.h>
#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
#define RT_HEAP_SIZE 1024
/* 从内部SRAM里面分配一部分静态内存来作为rtt的堆空间这里配置为4KB */
static uint32_t rt_heap[RT_HEAP_SIZE];
RT_WEAK void *rt_heap_begin_get(void)
{
return rt_heap;
}
RT_WEAK void *rt_heap_end_get(void)
{
return rt_heap + RT_HEAP_SIZE;
}
#endif
/**
* @brief
* @param
* @retval
*
* @attention
* RTT把开发板相关的初始化函数统一放到board.c文件中实现
* main.c文件也是可以的
*/
void rt_hw_board_init()
{
/* 初始化SysTick */
SysTick_Config( SystemCoreClock / RT_TICK_PER_SECOND );
/* 硬件BSP初始化统统放在这里比如LED串口LCD等 */
ILI9341_Init ();//LCD 初始化
LED_GPIO_Config();
USART_Config();
ADCx_Init();
EXTI_Key_Config();
PS2_Key_Config();
BASIC_TIM_Init();
//其中0、3、5、6 模式适合从左至右显示文字,
//不推荐使用其它模式显示文字 其它模式显示文字会有镜像效果
//其中 6 模式为大部分液晶例程的默认显示方向
ILI9341_GramScan ( 3 );
LCD_SetColors(WHITE, BLACK);
ILI9341_Clear(0,0,LCD_X_LENGTH,LCD_Y_LENGTH);
ILI9341_Clear(200, 0, 320, (((sFONT *)LCD_GetFont())->Height));
ILI9341_DispString_EN(210, 0,"T: 2ms");
/* 调用组件初始化函数 (use INIT_BOARD_EXPORT()) */
#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();
#endif
#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get());
#endif
}
/**
* @brief SysTick中断服务函数
* @param
* @retval
*
* @attention
* SysTick中断服务函数在固件库文件stm32f10x_it.c中也定义了
* board.c中又定义一次
* stm32f10x_it.c中的注释或者删除即可
*/
void SysTick_Handler(void)
{
/* 进入中断 */
rt_interrupt_enter();
/* 更新时基 */
rt_tick_increase();
/* 离开中断 */
rt_interrupt_leave();
}
/**
* @brief DEBUG_USARTx到rt_kprintf()
* NoteDEBUG_USARTx是在bsp_usart.h中定义的宏使1
* @param str
* @retval
*
* @attention
*
*/
void rt_hw_console_output(const char *str)
{
/* 进入临界段 */
rt_enter_critical();
/* 直到字符串结束 */
while (*str!='\0')
{
/* 换行 */
if (*str=='\n')
{
USART_SendData(DEBUG_USARTx, '\r');
while (USART_GetFlagStatus(DEBUG_USARTx, USART_FLAG_TXE) == RESET);
}
USART_SendData(DEBUG_USARTx, *str++);
while (USART_GetFlagStatus(DEBUG_USARTx, USART_FLAG_TXE) == RESET);
}
/* 退出临界段 */
rt_exit_critical();
}

View File

@ -1,26 +1,15 @@
#ifndef __BOARD_H__
#define __BOARD_H__
/*
*************************************************************************
*
*************************************************************************
*/
/* STM32 固件库头文件 */
#include "stm32f10x.h"
/* 开发板硬件bsp头文件 */
#include "bsp_led.h"
#include "bsp_usart.h"
#include "bsp_key_exti.h"
/*
*************************************************************************
*
*************************************************************************
*/
void rt_hw_board_init(void);
void SysTick_Handler(void);
#endif /* __BOARD_H__ */
#ifndef __BOARD_H__
#define __BOARD_H__
/*
*************************************************************************
*
*************************************************************************
*/
void rt_hw_board_init(void);
void SysTick_Handler(void);
#endif /* __BOARD_H__ */

View File

@ -1,63 +1,63 @@
#include "bsp_key_exti.h"
static void EXTI_NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_IntStruct;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
//配置key1
NVIC_IntStruct.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_IntStruct.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_IntStruct.NVIC_IRQChannelSubPriority = 1;
NVIC_IntStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_IntStruct);
//配置key2
NVIC_IntStruct.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_IntStruct.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_IntStruct.NVIC_IRQChannelSubPriority = 1;
NVIC_Init(&NVIC_IntStruct);
}
void EXTI_Key_Config(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
EXTI_InitTypeDef EXTI_InitStruct;
//配置中断优先级
EXTI_NVIC_Config();
//初始化GPIO
RCC_APB2PeriphClockCmd(KEY1_INT_GPIO_CLK, ENABLE); //key1时钟
RCC_APB2PeriphClockCmd(KEY2_INT_GPIO_CLK, ENABLE); //key2时钟
//初始化key1
GPIO_InitStruct.GPIO_Pin = KEY1_INT_GPIO_PIN;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(KEY1_INT_GPIO_PORT, &GPIO_InitStruct);
//初始化key2
GPIO_InitStruct.GPIO_Pin = KEY2_INT_GPIO_PIN;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(KEY2_INT_GPIO_PORT, &GPIO_InitStruct);
//初始化EXTI
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource13);
EXTI_InitStruct.EXTI_Line = EXTI_Line0; //key1
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStruct);
EXTI_InitStruct.EXTI_Line = EXTI_Line13; //key2
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStruct);
}
#include "bsp_key_exti.h"
static void EXTI_NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_IntStruct;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
//配置key1
NVIC_IntStruct.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_IntStruct.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_IntStruct.NVIC_IRQChannelSubPriority = 1;
NVIC_IntStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_IntStruct);
//配置key2
NVIC_IntStruct.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_IntStruct.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_IntStruct.NVIC_IRQChannelSubPriority = 1;
NVIC_Init(&NVIC_IntStruct);
}
void EXTI_Key_Config(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
EXTI_InitTypeDef EXTI_InitStruct;
//配置中断优先级
EXTI_NVIC_Config();
//初始化GPIO
RCC_APB2PeriphClockCmd(KEY1_INT_GPIO_CLK, ENABLE); //key1时钟
RCC_APB2PeriphClockCmd(KEY2_INT_GPIO_CLK, ENABLE); //key2时钟
//初始化key1
GPIO_InitStruct.GPIO_Pin = KEY1_INT_GPIO_PIN;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(KEY1_INT_GPIO_PORT, &GPIO_InitStruct);
//初始化key2
GPIO_InitStruct.GPIO_Pin = KEY2_INT_GPIO_PIN;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(KEY2_INT_GPIO_PORT, &GPIO_InitStruct);
//初始化EXTI
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource13);
EXTI_InitStruct.EXTI_Line = EXTI_Line0; //key1
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStruct);
EXTI_InitStruct.EXTI_Line = EXTI_Line13; //key2
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStruct);
}

View File

@ -1,16 +1,16 @@
#ifndef __BSP_KEY_EXTI_H
#define __BSP_KEY_EXTI_H
#include "stm32f10x.h"
#define KEY1_INT_GPIO_PIN GPIO_Pin_0
#define KEY1_INT_GPIO_PORT GPIOA
#define KEY1_INT_GPIO_CLK RCC_APB2Periph_GPIOA
#define KEY2_INT_GPIO_PIN GPIO_Pin_13
#define KEY2_INT_GPIO_PORT GPIOC
#define KEY2_INT_GPIO_CLK RCC_APB2Periph_GPIOC
void EXTI_Key_Config(void);
#endif /* __BSP_KEY_EXTI_H */
#ifndef __BSP_KEY_EXTI_H
#define __BSP_KEY_EXTI_H
#include "stm32f10x.h"
#define KEY1_INT_GPIO_PIN GPIO_Pin_0
#define KEY1_INT_GPIO_PORT GPIOA
#define KEY1_INT_GPIO_CLK RCC_APB2Periph_GPIOA
#define KEY2_INT_GPIO_PIN GPIO_Pin_13
#define KEY2_INT_GPIO_PORT GPIOC
#define KEY2_INT_GPIO_CLK RCC_APB2Periph_GPIOC
void EXTI_Key_Config(void);
#endif /* __BSP_KEY_EXTI_H */

View File

@ -11,6 +11,8 @@
#include "OSC.h"
#include <stdio.h>
#include "bsp_led.h"
volatile uint32_t Time_us = 0; // us 计时变量
@ -41,8 +43,9 @@ void BASIC_TIM_IRQHandler (void)
*/
void EXTI2_IRQnHandler(void)
{
if(EXTI_GetFlagStatus(EXTI_Line2) != RESET)
if(EXTI_GetITStatus(EXTI_Line2) != RESET)
{
LED1_ON;
rt_interrupt_enter();
rt_mq_send(setting_data_queue,
&setting_data_set,