\u6ce8\u610f<\/strong><\/mark>\uff1a\u6bcf\u4e2a\u65f6\u95f4\u53ea\u80fd\u6709\u4e00\u4e2aI\/O\u53ef\u6620\u5c04\u5230\u5bf9\u5e94\u7684\u4e2d\u65ad\u7ebf\u3002<\/p>\n\u5916\u90e8\u4e2d\u65ad\u670d\u52a1\u51fd\u6570<\/h3>\n
\u2003\u2003\u662f\u4e0d\u662f16\u4e2a\u4e2d\u65ad\u7ebf\u5c31\u53ef\u4ee5\u5206\u914d16\u4e2a\u4e2d\u65ad\u670d\u52a1\u51fd\u6570\u5462\uff1f
\u2003\u2003IO\u53e3\u5916\u90e8\u4e2d\u65ad\u5728\u4e2d\u65ad\u5411\u91cf\u8868\u4e2d\u53ea\u5206\u914d\u4e867\u4e2a\u4e2d\u65ad\u5411\u91cf\uff0c\u4e5f\u5c31\u662f\u53ea\u80fd\u4f7f\u75287\u4e2a\u4e2d\u65ad\u670d\u52a1\u51fd\u6570\uff08\u4e0b\u8868\u5c11\u5199\u4e86EXTI0\uff09
\u2003\u2003\u4ece\u8868\u4e2d\u53ef\u4ee5\u770b\u51fa\uff0c\u5916\u90e8\u4e2d\u65ad\u7ebf5~9\u5206\u914d\u4e00\u4e2a\u4e2d\u65ad\u5411\u91cf\uff0c\u5171\u7528\u4e00\u4e2a\u670d\u52a1\u51fd\u6570\u5916\u90e8\u4e2d\u65ad\u7ebf10 ~15\u5206\u914d\u4e00\u4e2a\u4e2d\u65ad\u5411\u91cf\uff0c\u5171\u7528\u4e00\u4e2a\u4e2d\u65ad\u670d\u52a1\u51fd\u6570\u3002<\/p>\n
\u4e2d\u65ad\u670d\u52a1\u51fd\u6570\u5217\u8868<\/h3>\n
\u2003\u2003EXTI0_IRQHandler
\u2003\u2003EXTI1_IRQHandler
\u2003\u2003EXTI2_IRQHandler
\u2003\u2003EXTI3_IRQHandler
\u2003\u2003EXTI4_IRQHandler
\u2003\u2003EXTI9_5_IRQHandler
\u2003\u2003 EXTI15_10_IRQHandler<\/p>\n
\u5916\u90e8\u4e2d\u65ad\u8bbe\u7f6e\u6b65\u9aa4<\/h3>\n
\u2003\u2003\u2460\u6620\u5c04
\u2003\u2003\u2461\u4e2d\u65ad\u4f7f\u80fd\u3001\u89e6\u53d1\u6a21\u5f0f\u7b49\u4f7f\u80fd\u65b9\u5f0f\u3002
\u2003\u2003\u2462\u7f16\u5199\u4e2d\u65ad\u670d\u52a1\u51fd\u6570<\/p>\n
\u4e00\u822c\u914d\u7f6e\u6b65\u9aa4\uff1a
\u2003\u2003\u2460\u521d\u59cb\u5316IO\u53e3\u4e3a\u8f93\u5165\u3002
\u2003\u2003\u2003\u2003GPIO_Init();
\u2003\u2003\u2461 \u5f00\u542fIO\u53e3\u590d\u7528\u65f6\u949f\u3002\u2003\u2003\u2003\u2003RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
\u2003\u2003\u2462\u8bbe\u7f6eIO\u53e3\u4e0e\u4e2d\u65ad\u7ebf\u7684\u6620\u5c04\u5173\u7cfb\u3002
\u2003\u2003\u2003\u2003void GPIO_EXTILineConfig();
\u2003\u2003\u2463\u521d\u59cb\u5316\u7ebf\u4e0a\u4e2d\u65ad\uff0c\u8bbe\u7f6e\u89e6\u53d1\u6761\u4ef6\u7b49\u3002
\u2003\u2003\u2003\u2003EXTI_Init();
\u2003\u2003\u2464\u914d\u7f6e\u4e2d\u65ad\u5206\u7ec4\uff08NVIC\uff09\uff0c\u5e76\u4f7f\u80fd\u4e2d\u65ad\u3002
\u2003\u2003\u2003\u2003NVIC_Init();
\u2003\u2003\u2465\u7f16\u5199\u4e2d\u65ad\u670d\u52a1\u51fd\u6570\u3002
\u2003\u2003\u2003\u2003EXTIx_IRQHandler();
\u2003\u2003\u2466\u6e05\u9664\u4e2d\u65ad\u6807\u5fd7\u4f4d
\u2003\u2003\u2003\u2003EXTI_ClearITPendingBit();<\/p>\n
\u5916\u90e8\u4e2d\u65ad\u5e38\u7528\u5e93\u51fd\u6570<\/h3>\n
\u2460void GPIO_EXTILineConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource);
\/\/\u8bbe\u7f6eIO\u53e3\u4e0e\u4e2d\u65ad\u7ebf\u7684\u6620\u5c04\u5173\u7cfb
exp: GPIO_EXTILineConfig(GPIO_PortSourceGPIOE,GPIO_PinSource2);<\/p>\n
\u2461void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct);
\/\/\u521d\u59cb\u5316\u4e2d\u65ad\u7ebf\uff1a\u89e6\u53d1\u65b9\u5f0f\u7b49<\/p>\n
\u2462ITStatus EXTI_GetITStatus(uint32_t EXTI_Line);
\/\/\u5224\u65ad\u4e2d\u65ad\u7ebf\u4e2d\u65ad\u72b6\u6001\uff0c\u662f\u5426\u53d1\u751f<\/p>\n
\u2463void EXTI_ClearITPendingBit(uint32_t EXTI_Line);
\/\/\u6e05\u9664\u4e2d\u65ad\u7ebf\u4e0a\u7684\u4e2d\u65ad\u6807\u5fd7\u4f4d<\/p>\n
\u786c\u4ef6\u7535\u8def<\/h3>\nLED<\/h4>\n
<\/p>\n
\u6309\u952e<\/h4>\n
<\/p>\n
\u5177\u4f53\u5b9e\u73b0<\/h3>\n
\u65b0\u5efa\u6a21\u7248\uff0c\u5728HARDWARE\u6587\u4ef6\u5939\u6dfb\u52a0exit\u6587\u4ef6\u3002\u7136\u540e\u5c31\u662f\u586b\u5165\u5de5\u7a0b\uff0c\u6dfb\u52a0\u5934\u6587\u4ef6\u8def\u5f84\u7b49\u7b49\u64cd\u4f5c\u3002<\/p>\n
\u7b2c\u4e00\u6b65\uff1a\u521d\u59cb\u5316IO\u53e3\u4e3a\u8f93\u5165<\/h4>\n#include<\/span> \"stm32f10x.h\"<\/span><\/span> void<\/span> EXTIX_Init<\/span>(<\/span>void<\/span>)<\/span>{ \n <\/span> GPIO_InitTypeDef GPIO_InitStruce;<\/span> RCC_APB2PeriphClockCmd<\/span>(<\/span>RCC_APB2Periph_GPIOA |<\/span>RCC_APB2Periph_GPIOE ,<\/span> ENABLE)<\/span>;<\/span> GPIO_InitStruce.<\/span>GPIO_Mode=<\/span>GPIO_Mode_IPU;<\/span>\/\/\u4e0a\u62c9\u8f93\u5165<\/span> GPIO_InitStruce.<\/span>GPIO_Pin=<\/span>GPIO_Pin_4|<\/span>GPIO_Pin_3;<\/span> GPIO_InitStruce.<\/span>GPIO_Speed=<\/span>GPIO_Speed_50MHz;<\/span> GPIO_Init<\/span>(<\/span>GPIOE,<\/span> &<\/span>GPIO_InitStruce)<\/span>;<\/span> GPIO_InitStruce.<\/span>GPIO_Mode=<\/span>GPIO_Mode_IPD;<\/span>\/\/\u4e0b\u62c9\u8f93\u5165<\/span> GPIO_InitStruce.<\/span>GPIO_Pin=<\/span>GPIO_Pin_0;<\/span> GPIO_InitStruce.<\/span>GPIO_Speed=<\/span>GPIO_Speed_50MHz;<\/span> GPIO_Init<\/span>(<\/span>GPIOA,<\/span> &<\/span>GPIO_InitStruce)<\/span>;<\/span> }<\/span> <\/code><\/pre>\n\u7b2c\u4e8c\u6b65\uff1a\u5f00\u542fIO\u53e3\u590d\u7528\u65f6\u949f<\/h4>\n
\u589e\u52a0\uff1aRCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO , ENABLE);<\/code><\/p>\n\u7b2c\u4e09\u6b65\uff1a\u8bbe\u7f6eIO\u53e3\u4e0e\u4e2d\u65ad\u7ebf\u7684\u6620\u5c04\u5173\u7cfb<\/h4>\n
\u8be5\u51fd\u6570\u5b58\u5728\u4e8e\uff1astm32f10x_gpio.h\u4e2d
\u589e\u52a0\uff1aGPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource4);<\/code><\/p>\n\u7b2c\u56db\u6b65\uff1a\u521d\u59cb\u5316\u7ebf\u4e0a\u4e2d\u65ad\uff0c\u8bbe\u7f6e\u89e6\u53d1\u6761\u4ef6\u7b49\u3002<\/h4>\n
\u8be5\u51fd\u6570\u5b58\u5728\u4e8e\uff1astm32f10x_exti.h\u4e2d
\u589e\u52a0\uff1a<\/p>\n
EXTI_InitTypeDef EXTI_InitStruce;<\/span> GPIO_EXTILineConfig<\/span>(<\/span>GPIO_PortSourceGPIOE,<\/span> GPIO_PinSource4)<\/span>;<\/span> EXTI_InitStruce.<\/span>EXTI_Line=<\/span>EXTI_Line4;<\/span> \/\/\u786e\u5b9a\u4e2d\u65ad\u7ebf<\/span> EXTI_InitStruce.<\/span>EXTI_LineCmd=<\/span>ENABLE;<\/span>\/\/\u4f7f\u80fd<\/span> EXTI_InitStruce.<\/span>EXTI_Mode=<\/span>EXTI_Mode_Interrupt;<\/span>\/\/\u6a21\u5f0f\uff1a\u4e2d\u65ad<\/span> EXTI_InitStruce.<\/span>EXTI_Trigger=<\/span>EXTI_Trigger_Falling;<\/span>\/\/\u89e6\u53d1\u65b9\u5f0f(\u6839\u636e\u6309\u952e\u7535\u8def\u56fe\uff0c\u9009\u62e9\u4e0b\u964d\u6cbf\u89e6\u53d1)<\/span> EXTI_Init<\/span>(<\/span>&<\/span>EXTI_InitStruce)<\/span>;<\/span> <\/code><\/pre>\n\u7b2c\u4e94\u6b65\uff1a\u914d\u7f6e\u4e2d\u65ad\u5206\u7ec4\uff08NVIC\uff09\uff0c\u5e76\u4f7f\u80fd\u4e2d\u65ad\u3002<\/h4>\n
\u8be5\u51fd\u6570\u5b58\u5728\u4e8e\uff1amisc.h\u4e2d
\u901a\u9053\u7684\u53c2\u6570\u662f\u5728stm32f10x,h\u4e2d\u627e\u5230IRQn\u7ed3\u5c3e\u7684\u3002
\u589e\u52a0\uff1a<\/p>\n
EXTI_Init<\/span>(<\/span>&<\/span>EXTI_InitStruce)<\/span>;<\/span> NVIC_InitTypeDef NVIC_InitStruce;<\/span> NVIC_InitStruce.<\/span>NVIC_IRQChannel=<\/span>EXTI4_IRQn ;<\/span>\/\/\u8bbe\u7f6e\u901a\u9053<\/span> NVIC_InitStruce.<\/span>NVIC_IRQChannelCmd =<\/span> ENABLE;<\/span>\/\/\u4f7f\u80fd<\/span> NVIC_InitStruce.<\/span>NVIC_IRQChannelPreemptionPriority=<\/span>2<\/span>;<\/span>\/\/\u8bbe\u7f6e\u4f18\u5148\u7ea7<\/span> NVIC_InitStruce.<\/span>NVIC_IRQChannelSubPriority=<\/span>2<\/span>;<\/span>\/\/\u8bbe\u7f6e\u5b50\u4f18\u5148\u7ea7<\/span> NVIC_Init<\/span>(<\/span>&<\/span>NVIC_InitStruce)<\/span>;<\/span> <\/code><\/pre>\n\u8fd9\u8fb9\u8981\u6ce8\u610f\uff0c\u5728\u8fd9\u540c\u65f6\u8981\u5728main.c\u4e2d\u5148\u5199\u4e0b\u8be5\u51fd\u6570NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);\/\/\u8bbe\u7f6eNVIC\u4e2d\u65ad\u5206\u7ec4\uff0c2\u4f4d\u62a2\u5360\u4f18\u5148\u7ea7\uff0c2\u4f4d\u54cd\u5e94\u4f18\u5148\u7ea7<\/code>\uff0c\u8bbe\u7f6e\u4f18\u5148\u7ea7\u540e\uff0c\u8fd9\u8fb9\u586b\u5199\u7684\u62a2\u5360\u4f18\u5148\u7ea7\u624d\u6709\u6548\u3002<\/p>\n\u7b2c\u516d\u6b65\uff1a \u7f16\u5199\u4e2d\u65ad\u670d\u52a1\u51fd\u6570&\u6e05\u9664\u4e2d\u65ad\u6807\u5fd7\u4f4d<\/h4>\n
\u8be5\u51fd\u6570\u5728\u542f\u52a8\u6587\u4ef6CORE\u6587\u4ef6\u5939\u4e0b\u7684startup_stm32f10x_hd.s\u4e2d\uff1aEXTI4_IRQHandler<\/code>
\u6545\u53ef\u5728exti,c\u6587\u4ef6\u4e2d\u7f16\u5199\u4e00\u4e0b\u7a0b\u5e8f\uff1a<\/p>\nvoid EXTI4_IRQHandler(void)<\/span>{ \n <\/span> delay_ms<\/span>(<\/span>10)<\/span>;\/\/\u9632\u6296\u5ef6\u65f6 if(KEY0 == 0)<\/span>{ \n <\/span> LED0 = !LED0;<\/span> LED1 = !LED1;<\/span> }<\/span> EXTI_ClearITPendingBit<\/span>(<\/span>EXTI_Line4)<\/span>;<\/span>\/\/\u624b\u52a8\u6e05\u9664\u6807\u5fd7\u4f4d\uff0cexti.h\u4e2d }<\/span> <\/code><\/pre>\n\u7a0b\u5e8f\u4ee3\u7801\u603b\u7ed3\uff1a<\/h3>\n
exti.c\u6587\u4ef6\uff1a<\/p>\n
#include<\/span> \"stm32f10x.h\"<\/span><\/span> #include<\/span> \"delay.h\"<\/span><\/span> #include<\/span> \"exti.h\"<\/span><\/span> void<\/span> EXTIX_Init<\/span>(<\/span>void<\/span>)<\/span>{ \n <\/span> GPIO_InitTypeDef GPIO_InitStruce;<\/span> RCC_APB2PeriphClockCmd<\/span>(<\/span>RCC_APB2Periph_GPIOA |<\/span>RCC_APB2Periph_GPIOE ,<\/span> ENABLE)<\/span>;<\/span>\/\/IO\u53e3\u65f6\u949f<\/span> GPIO_InitStruce.<\/span>GPIO_Mode=<\/span>GPIO_Mode_IPU;<\/span>\/\/\u4e0a\u62c9\u8f93\u5165<\/span> GPIO_InitStruce.<\/span>GPIO_Pin=<\/span>GPIO_Pin_4|<\/span>GPIO_Pin_3;<\/span>\/\/KEY0|KEY1<\/span> GPIO_InitStruce.<\/span>GPIO_Speed=<\/span>GPIO_Speed_50MHz;<\/span> GPIO_Init<\/span>(<\/span>GPIOE,<\/span> &<\/span>GPIO_InitStruce)<\/span>;<\/span> GPIO_InitStruce.<\/span>GPIO_Mode=<\/span>GPIO_Mode_IPD;<\/span>\/\/\u4e0b\u62c9\u8f93\u5165<\/span> GPIO_InitStruce.<\/span>GPIO_Pin=<\/span>GPIO_Pin_0;<\/span>;<\/span>\/\/KEY UP<\/span> GPIO_InitStruce.<\/span>GPIO_Speed=<\/span>GPIO_Speed_50MHz;<\/span> GPIO_Init<\/span>(<\/span>GPIOA,<\/span> &<\/span>GPIO_InitStruce)<\/span>;<\/span> RCC_APB2PeriphClockCmd<\/span>(<\/span>RCC_APB2Periph_AFIO ,<\/span> ENABLE)<\/span>;<\/span>\/\/IO\u53e3\u590d\u7528\u65f6\u949f<\/span> EXTI_InitTypeDef EXTI_InitStruce;<\/span> GPIO_EXTILineConfig<\/span>(<\/span>GPIO_PortSourceGPIOE,<\/span> GPIO_PinSource4)<\/span>;<\/span> EXTI_InitStruce.<\/span>EXTI_Line=<\/span>EXTI_Line4;<\/span> \/\/\u786e\u5b9a\u4e2d\u65ad\u7ebf<\/span> EXTI_InitStruce.<\/span>EXTI_LineCmd=<\/span>ENABLE;<\/span>\/\/\u4f7f\u80fd<\/span> EXTI_InitStruce.<\/span>EXTI_Mode=<\/span>EXTI_Mode_Interrupt;<\/span>\/\/\u6a21\u5f0f\uff1a\u4e2d\u65ad<\/span> EXTI_InitStruce.<\/span>EXTI_Trigger=<\/span>EXTI_Trigger_Falling;<\/span>\/\/\u89e6\u53d1\u65b9\u5f0f(\u6839\u636e\u6309\u952e\u7535\u8def\u56fe\uff0c\u9009\u62e9\u4e0b\u964d\u6cbf\u89e6\u53d1)<\/span> EXTI_Init<\/span>(<\/span>&<\/span>EXTI_InitStruce)<\/span>;<\/span> NVIC_InitTypeDef NVIC_InitStruce;<\/span> NVIC_InitStruce.<\/span>NVIC_IRQChannel=<\/span>EXTI4_IRQn;<\/span>\/\/\u8bbe\u7f6e\u901a\u9053<\/span> NVIC_InitStruce.<\/span>NVIC_IRQChannelCmd =<\/span> ENABLE;<\/span>\/\/\u4f7f\u80fd<\/span> NVIC_InitStruce