本帖最后由 墨如风0205 于 2013-9-16 20:32 编辑
#include "..\include\hardware.h"
#include "..\include\sw.h"
#include "stm32f4xx.h"
#include "core_cm4.h"
//---------------- Function Prototype -------------------//
static int initialize(void);
//---------------- Variable -----------------------------//
SW_T sw={
.initialize = initialize
};
//-----------------Function------------------------------//
/*
* Name : initialize
* Description : ---
* Author : .
*
* History
* ----------------------
* Rev : 0.00
* Date : 07/17/2013
*
* create.
* ----------------------
*/
static int
initialize(void)
{
RCC->APB2ENR |= (1<<14); //使能syscfg
GPIOB->MODER &= ~((1<<11)|(1<<10)); //PB5为输入模式
GPIOB->PUPDR |= (1<<10); //PB5为上拉
EXTI->IMR |= (1<<5); //开放来自线5的中断请求
// EXTI->EMR |= (1<<5); //开放来自线5的事件请求
// EXTI->RTSR &= ~(1<<5); //禁止输入线5上的上升沿触发
EXTI->FTSR |= (1<<5); //允许输入线5上的下降沿触发
SYSCFG->EXTICR[2] |= SYSCFG_EXTICR2_EXTI5_PB;
NVIC->IP[23] = 0Xa; //中断优先级为a
NVIC->ISER[0] |= (1 << 23); //允许EXTI线[9:5]中断
SYSCFG->CMPCR = (1<<0); //使用IO补偿单元
return 0;
}
/*
* Name : delay_ms
* Description : ---
* Author : .
*
* History
* ----------------------
* Rev : 0.00
* Date : 07/17/2013
*
* create.
* ----------------------
*/
void
EXTI9_5_IRQHandler(void)
{
if(EXTI->PR&(1<<5)!=0){
LED_ON;
}
EXTI->PR = (1<<5); //该位置1,清除中断标志位(清除 中断挂起)
}
|