Chinaunix首页 | 论坛 | 博客
  • 博客访问: 488810
  • 博文数量: 93
  • 博客积分: 1431
  • 博客等级: 上尉
  • 技术积分: 1006
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-18 10:30
文章分类

全部博文(93)

文章存档

2011年(20)

2010年(2)

2009年(71)

我的朋友

分类: LINUX

2009-07-02 10:46:28

1.GPIO 的正确设置
 
 GPIO_InitTypeDef GPIO_InitStructure;
  /* Enable GPIOD clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
 
/* Configure PD.03, PC.04, as input floating */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 ;
    
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOD, &GPIO_InitStructure);
 
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource3);
 
2.设置中断类型,注册申请中断
 
EXTI_InitTypeDef EXTI_InitStructure;
 
 
  // Configure EXTI Line9 to generate an interrupt on falling edge
  EXTI_InitStructure.EXTI_Line = EXTI_Line3;
  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_PortSourceGPIOD, GPIO_PinSource4);

  // Configure EXTI Line9 to generate an interrupt on falling edge
  EXTI_InitStructure.EXTI_Line = EXTI_Line4;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);
 
3.在NVIC_Configuration 中Configures the NVIC and Vector Table base address.

  /* Configure the Priority Group to 2 bits */
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  /* enabling interrupt */
  NVIC_InitStructure.NVIC_IRQChannel=TIM2_IRQChannel;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  /* Enable the EXTI3 Interrupt on PD.3 */
  NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQChannel;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
    /* Enable the EXTI4 Interrupt on PD.4 */
  NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQChannel;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
 
4.在stm32f0x_it.c 中写入 中断处理函数
 
/*******************************************************************************
* Function Name  : EXTI3_IRQHandler
* Description    : This function handles External interrupt Line 3 request.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void EXTI3_IRQHandler(void)
{
 if(EXTI_GetITStatus(EXTI_Line3) != RESET)
  {
   // Led_RW_ON();
    GPIO_SetBits(GPIOC, GPIO_Pin_4| GPIO_Pin_5 );
   
   
    /* Clear the EXTI line 9 pending bit */
    EXTI_ClearITPendingBit(EXTI_Line3);
  }
}
/*******************************************************************************
* Function Name  : EXTI4_IRQHandler
* Description    : This function handles External interrupt Line 4 request.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void EXTI4_IRQHandler(void)
{
 if(EXTI_GetITStatus(EXTI_Line4) != RESET)
  {
    //Led_RW_OFF();
    GPIO_ResetBits(GPIOC, GPIO_Pin_4 | GPIO_Pin_5);
    /* Clear the EXTI line 9 pending bit */
    EXTI_ClearITPendingBit(EXTI_Line4);
  }
}
阅读(4135) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~