豆皮2.0问题,高手们帮我看看我的程序怎么了?

我用的是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****/

Test1.rar (714.15 KB)

别人笑我太疯癫,我笑他人看不穿。

版主也帮忙看一下我错在哪里了。
我是模仿着2.0的固件库来做的,看了很多例子就是不知道自己错在哪里了。
我在中断函数里面加了断电就是进不进去。汗!啊!
别人笑我太疯癫,我笑他人看不穿。

TOP

是否使能了AFIO时钟??
砖家级的水准……

TOP

本帖最后由 catwill 于 2009-12-24 17:40 编辑

不好意思,多发了一贴,删除。
砖家级的水准……

TOP

看了你的程序,你是想用GPIOC_8作为外部中断输入是吧,那你为何在static void NVIC_CONF()里将NVIC_InitStructure.NVIC_IRQChannel 定义为EXTI2_IRQn?这里就明显不对了,另外看你的代码,你不是在模仿2.x.x的固件库,你模仿的是3.x.x的库的写法,你将EXTI2_IRQChannel写成EXTI2_IRQn就是最明显的不过了,EXTI2_IRQn是在3.x.x开始用。

对于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);
}

TOP

我用的就是3.0的库啊。是模仿2.0库的做法来做3.0库的。
搞不明白为什么用3.0库就是进入不了按键中断。
别人笑我太疯癫,我笑他人看不穿。

TOP

就算用3.0的库,这句“NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn;”也写错了,应改为:NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;

你想用GPIOC_8来做键盘中断输入,却定义了EXTI2_IRQn中断通道,这怎么有可能正常进入指定中断呢?

TOP

我用的是3.0库。看了很多资料我感觉该打开的都打开了啊。就是不见中断响应。
别人笑我太疯癫,我笑他人看不穿。

TOP

若不是EXTI2_IRQn,具体的pc7应该对应那个通道啊。
别人笑我太疯癫,我笑他人看不穿。

TOP

EXTI2_IRQn
从0到4都用了。还是不行。
我感觉这个库里好像少了些什么东西。
别人笑我太疯癫,我笑他人看不穿。

TOP

上面都说了呢,外部中断5-9号都是用同一个中断向量:EXTI9_5_IRQn。

TOP

上面都说了呢,外部中断5-9号都是用同一个中断向量:EXTI9_5_IRQn。
binglin 发表于 2009-12-25 17:52

炳哥说得对,
但是我还是怀疑楼主的AFIO时钟没开~
楼主:
GPx.1对应EXTI1
GPx.2对应EXTI2
以此类推。
EXTI1--EXTI4有独立中断源
EXTI5--EXTI9共用一个中断源,所以中断函数中应判断标志
砖家级的水准……

TOP

搞定了,终于能进入中断了响应也正常了。谢谢炳哥,还有坛友们。
/**
  ******************************************************************************
  * @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>&copy; 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里面的内容,但是我的按键的确没有按过啊。
看了手册和库函数函数说明还是有点不明白,虽然软件上容易处理,但是还是想弄清楚这是为什么。
别人笑我太疯癫,我笑他人看不穿。

TOP

Review opelc.org on alexa.com