豆皮2.0问题,高手们帮我看看我的程序怎么了?
发布: 2009-12-24 17:19 | 作者: tonghua209 | 来源: StmFans思蜕盟 OPELC 自由电子联盟
我用的是st32的3.0的库,用的是豆皮2.0的板子,弄了好久进不了按键中断,主文件见下面,哪位高手能帮我看一下,我错在哪里了!郁闷啊!整个工程见附件。
/**************************************************************************
* 头文件 *
**************************************************************************/
#include "stm32f10x.h"
#include "stm32f10x_conf.h"
/**************************************************************************
* 常量 *
**************************************************************************/
/**************************************************************************
* 宏定义 *
**************************************************************************/
/**************************************************************************
* 数据类型 *
**************************************************************************/
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
/**************************************************************************
* 全局变量定义 *
**************************************************************************/
/**************************************************************************
* 外部变量声明
**************************************************************************/
//extern
/**************************************************************************
* 外部函数声明 *
**************************************************************************/
//extern
/**************************************************************************
* 局部函数声明 *
**************************************************************************/
static void GPIO_CONF();
static void NVIC_CONF();
static void EXTI_CONF();
/**************************************************************************
* 局部函数实现 *
**************************************************************************/
/************************************************************************************
函数名称: GPIO_CONF(*)
功能描述: GPIO配置函数
输入参数: 无输入参数
输出参数: 无
返 回 值: 无返回值
其它说明:无
修改日期 版本号 修改人 修改内容
--------------------------------------------------------------------------------------
2009-12-24 V1.0 创建
**************************************************************************************/
static void GPIO_CONF()
{
/* Configure all unused GPIO port pins in Analog Input mode (floating input
trigger OFF), this will reduce the power consumption and increase the device
immunity against EMI/EMC *************************************************/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
RCC_APB2Periph_GPIOE, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_Init(GPIOE, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
RCC_APB2Periph_GPIOE, DISABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
/************************************************************************************
函数名称: NVIC_CONF(*)
功能描述: NVIC配置函数
输入参数: 无输入参数
输出参数: 无
返 回 值: 无返回值
其它说明:无
修改日期 版本号 修改人 修改内容
--------------------------------------------------------------------------------------
2009-12-24 V1.0 创建
**************************************************************************************/
static void NVIC_CONF()
{
/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* Enable the EXTI0 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_EnableIRQ(EXTI2_IRQn);
}
/************************************************************************************
函数名称: EXTI_INIT(*)
功能描述: 外部中断申请
输入参数: 无输入参数
输出参数: 无
返 回 值: 无返回值
其它说明:无
修改日期 版本号 修改人 修改内容
--------------------------------------------------------------------------------------
2009-12-24 V1.0 创建
**************************************************************************************/
static void EXTI_CONF()
{
// Configure EXTI Line0 to generate an interrupt on falling edge
EXTI_InitStructure.EXTI_Line = EXTI_Line8;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource8);
}
/**************************************************************************
* 全局函数声明 *
**************************************************************************/
void Delay(__IO uint32_t nCount);
/**************************************************************************
* 全局函数实现 *
**************************************************************************/
void Delay(__IO uint32_t nCount)
{
for(; nCount != 0; nCount--);
}
/****************************************************
* Start: 以下为系统入口及主功能函数 *
***************************************************/
/************************************************************************************
函数名称: main(*)
功能描述: 主功能模块入口
输入参数: 无输入参数
输出参数: 无
返 回 值: 返回值主功能ok
其它说明:系统初始化及主循环
修改日期 版本号 修改人 修改内容
-----------------------------------------------------------------------
2009-12-23 V1.0 创建
**************************************************************************************/
int main(void)
{
/* Setup STM32 system (clock, PLL and Flash configuration) */
SystemInit();//使能8M外部晶振,主频72M
/* Add your application code here
*/
GPIO_CONF();
NVIC_CONF();
EXTI_CONF();
/* Infinite loop */
while (1)
{
GPIO_SetBits(GPIOC, GPIO_Pin_10);//置位pc10
GPIO_SetBits(GPIOC, GPIO_Pin_11);//置位pc11
GPIO_SetBits(GPIOC, GPIO_Pin_12);//置位pc12
Delay(0xfFFFF);//延时一秒钟
GPIO_ResetBits(GPIOC, GPIO_Pin_10);//复位pc10
GPIO_ResetBits(GPIOC, GPIO_Pin_11);//复位pc11
GPIO_ResetBits(GPIOC, GPIO_Pin_12);//复位pc12
Delay(0xfFFFF);//延时一秒钟
}
}
#ifdef USE_FULL_ASSERT
/**************************************************************************
函数名称: assert_failed(*)
功能描述: 断言失败的提示函数。
输入参数: file:错误所在文件名称;line:错误所在行数
输出参数: 无
返 回 值:无返回值
其它说明:系统错误诊断打印函数
修改日期 版本号 修改人 修改内容
-----------------------------------------------------------------------
2009-12-23 V1.0 创建
**************************************************************************/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/**
* @}
*/
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
/**************************************************************************
* 头文件 *
**************************************************************************/
#include "stm32f10x.h"
#include "stm32f10x_conf.h"
/**************************************************************************
* 常量 *
**************************************************************************/
/**************************************************************************
* 宏定义 *
**************************************************************************/
/**************************************************************************
* 数据类型 *
**************************************************************************/
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
/**************************************************************************
* 全局变量定义 *
**************************************************************************/
/**************************************************************************
* 外部变量声明
**************************************************************************/
//extern
/**************************************************************************
* 外部函数声明 *
**************************************************************************/
//extern
/**************************************************************************
* 局部函数声明 *
**************************************************************************/
static void GPIO_CONF();
static void NVIC_CONF();
static void EXTI_CONF();
/**************************************************************************
* 局部函数实现 *
**************************************************************************/
/************************************************************************************
函数名称: GPIO_CONF(*)
功能描述: GPIO配置函数
输入参数: 无输入参数
输出参数: 无
返 回 值: 无返回值
其它说明:无
修改日期 版本号 修改人 修改内容
--------------------------------------------------------------------------------------
2009-12-24 V1.0 创建
**************************************************************************************/
static void GPIO_CONF()
{
/* Configure all unused GPIO port pins in Analog Input mode (floating input
trigger OFF), this will reduce the power consumption and increase the device
immunity against EMI/EMC *************************************************/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
RCC_APB2Periph_GPIOE, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_Init(GPIOE, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
RCC_APB2Periph_GPIOE, DISABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
/************************************************************************************
函数名称: NVIC_CONF(*)
功能描述: NVIC配置函数
输入参数: 无输入参数
输出参数: 无
返 回 值: 无返回值
其它说明:无
修改日期 版本号 修改人 修改内容
--------------------------------------------------------------------------------------
2009-12-24 V1.0 创建
**************************************************************************************/
static void NVIC_CONF()
{
/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* Enable the EXTI0 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_EnableIRQ(EXTI2_IRQn);
}
/************************************************************************************
函数名称: EXTI_INIT(*)
功能描述: 外部中断申请
输入参数: 无输入参数
输出参数: 无
返 回 值: 无返回值
其它说明:无
修改日期 版本号 修改人 修改内容
--------------------------------------------------------------------------------------
2009-12-24 V1.0 创建
**************************************************************************************/
static void EXTI_CONF()
{
// Configure EXTI Line0 to generate an interrupt on falling edge
EXTI_InitStructure.EXTI_Line = EXTI_Line8;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource8);
}
/**************************************************************************
* 全局函数声明 *
**************************************************************************/
void Delay(__IO uint32_t nCount);
/**************************************************************************
* 全局函数实现 *
**************************************************************************/
void Delay(__IO uint32_t nCount)
{
for(; nCount != 0; nCount--);
}
/****************************************************
* Start: 以下为系统入口及主功能函数 *
***************************************************/
/************************************************************************************
函数名称: main(*)
功能描述: 主功能模块入口
输入参数: 无输入参数
输出参数: 无
返 回 值: 返回值主功能ok
其它说明:系统初始化及主循环
修改日期 版本号 修改人 修改内容
-----------------------------------------------------------------------
2009-12-23 V1.0 创建
**************************************************************************************/
int main(void)
{
/* Setup STM32 system (clock, PLL and Flash configuration) */
SystemInit();//使能8M外部晶振,主频72M
/* Add your application code here
*/
GPIO_CONF();
NVIC_CONF();
EXTI_CONF();
/* Infinite loop */
while (1)
{
GPIO_SetBits(GPIOC, GPIO_Pin_10);//置位pc10
GPIO_SetBits(GPIOC, GPIO_Pin_11);//置位pc11
GPIO_SetBits(GPIOC, GPIO_Pin_12);//置位pc12
Delay(0xfFFFF);//延时一秒钟
GPIO_ResetBits(GPIOC, GPIO_Pin_10);//复位pc10
GPIO_ResetBits(GPIOC, GPIO_Pin_11);//复位pc11
GPIO_ResetBits(GPIOC, GPIO_Pin_12);//复位pc12
Delay(0xfFFFF);//延时一秒钟
}
}
#ifdef USE_FULL_ASSERT
/**************************************************************************
函数名称: assert_failed(*)
功能描述: 断言失败的提示函数。
输入参数: file:错误所在文件名称;line:错误所在行数
输出参数: 无
返 回 值:无返回值
其它说明:系统错误诊断打印函数
修改日期 版本号 修改人 修改内容
-----------------------------------------------------------------------
2009-12-23 V1.0 创建
**************************************************************************/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/**
* @}
*/
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
Test1.rar
(2009-12-24 17:19:27, Size: 714 KB, Downloads: 0)

我是模仿着2.0的固件库来做的,看了很多例子就是不知道自己错在哪里了。
我在中断函数里面加了断电就是进不进去。汗!啊!
不好意思,多发了一贴,删除。
对于2.x.x库时static void NVIC_CONF()代码应该为
static void NVIC_CONF()
{
/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* Enable the EXTI0 Interrupt */
//NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn;
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//NVIC_EnableIRQ(EXTI2_IRQn);
NVIC_EnableIRQ(EXTI9_5_IRQChannel);
}
搞不明白为什么用3.0库就是进入不了按键中断。
你想用GPIOC_8来做键盘中断输入,却定义了EXTI2_IRQn中断通道,这怎么有可能正常进入指定中断呢?
从0到4都用了。还是不行。
我感觉这个库里好像少了些什么东西。
QUOTE:
炳哥说得对,但是我还是怀疑楼主的AFIO时钟没开~
楼主:
GPx.1对应EXTI1
GPx.2对应EXTI2
以此类推。
EXTI1--EXTI4有独立中断源
EXTI5--EXTI9共用一个中断源,所以中断函数中应判断标志
/**
******************************************************************************
* @file EXTI/main.c
* @author MCD Application Team
* @version V3.0.0
* @date 04/06/2009
* @brief Main program body
******************************************************************************
* @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, STMICROELECTRONICS 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 2009 STMicroelectronics</center></h2>
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "stm32f10x_conf.h"
/** @addtogroup StdPeriph_Examples
* @{
*/
/** @addtogroup EXTI_Example
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
EXTI_InitTypeDef EXTI_InitStructure;
/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);
/* Private functions ---------------------------------------------------------*/
/**
* @brief Main program.
* @param None
* @retval : None
*/
int main(void)
{
/* System Clocks Configuration */
RCC_Configuration();
/* NVIC configuration */
NVIC_Configuration();
/* Configure the GPIO ports */
GPIO_Configuration();
/* Connect Key Button EXTI Line to Key Button GPIO Pin */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource8);
/* Configure Key Button EXTI Line to generate an interrupt on falling edge */
EXTI_InitStructure.EXTI_Line = GPIO_PinSource8;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_ClearITPendingBit(EXTI_Line8);
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Generate software interrupt: simulate a falling edge applied on Key Button EXTI line */
//EXTI_GenerateSWInterrupt(GPIO_PinSource8);
while (1)
{
}
}
/**
* @brief Configures the different system clocks.
* @param None
* @retval : None
*/
void RCC_Configuration(void)
{
/* Setup the microcontroller system. Initialize the Embedded Flash Interface,
initialize the PLL and update the SystemFrequency variable. */
SystemInit();
/* Enable Key Button GPIO Port, GPIO_LED and AFIO clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE);
}
/**
* @brief Configures the different GPIO ports.
* @param None
* @retval : None
*/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure GPIO Led pin 6 as Output push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Configure Key Button GPIO Pin as input floating (Key Button EXTI Line) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
/**
* @brief Configure the nested vectored interrupt controller.
* @param None
* @retval : None
*/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* Enable the EXTI9_5 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval : None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
但是还有个问题,为什么我的程序在上电之后会直接进入到中断函数,然后才会正常。
void EXTI9_5_IRQHandler()
{
if( EXTI_GetITStatus (EXTI_Line8) != RESET)
{
EXTI_ClearITPendingBit(EXTI_Line8);
kyh1022++;
}
}
就是会进入到这个函数里面并执行if里面的内容,但是我的按键的确没有按过啊。
看了手册和库函数函数说明还是有点不明白,虽然软件上容易处理,但是还是想弄清楚这是为什么。