#include "stm32f10x.h"unsigned int TimingDelay;
void Delay(unsigned int x)
{
TimingDelay=x;
while(TimingDelay--);
}
void EXTI9_5_IRQHandler(void) //中斷處理函數
{
unsigned int tt;
tt=6553500;
if(EXTI_GetITStatus(EXTI_Line5)!=RESET)
{
GPIO_SetBits(GPIOC, GPIO_Pin_7);
while(tt--);
GPIO_ResetBits(GPIOC, GPIO_Pin_7);
while(tt--);
EXTI_ClearFlag(EXTI_Line5);//清除中斷標志
EXTI_ClearITPendingBit(EXTI_Line5);//清除EXTI線路掛起位
}
}
int main(void)
{
//配置IO口
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE,ENABLE);//IO口使能設置
GPIO_InitTypeDef GPIO_InitStructure; //定義結構體
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
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_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //設置為上拉輸入
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
//配置外部中斷控制器
EXTI_InitTypeDef EXTI_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//使能時鐘
EXTI_InitStructure.EXTI_Line = EXTI_Line5; //使用IO口5作為中斷口
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //設置EXTI線路為中斷請求
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //下降沿觸發(fā)
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE,GPIO_PinSource5);//將PE5掛接到EXTI9_5_IRQn中斷源上
//配置中斷控制器
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); //選擇中斷組0
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; //指定中斷源,0-4管腳屬于EXTI0_IRQn~EXTI4_IRQn,5-9管腳屬于EXTI9_5_IRQn,10-15管腳屬于EXTI15_10_IRQn
//NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;//無先占優(yōu)先級,從優(yōu)先級為1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
while(1);
}
//以下是報錯函數
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
while (1)
{
}
}
#endif
評論