{"id":7047,"date":"2024-07-19T23:01:01","date_gmt":"2024-07-19T15:01:01","guid":{"rendered":""},"modified":"2024-07-19T23:01:01","modified_gmt":"2024-07-19T15:01:01","slug":"STM32\u7cbe\u82f1\u7248\uff08\u6b63\u70b9\u539f\u5b50STM32F103ZET6\u5f00\u53d1\u677f\uff09\u5b66\u4e60\u7bc79\u2014\u2014\u5916\u90e8\u4e2d\u65ad","status":"publish","type":"post","link":"https:\/\/mushiming.com\/7047.html","title":{"rendered":"STM32\u7cbe\u82f1\u7248\uff08\u6b63\u70b9\u539f\u5b50STM32F103ZET6\u5f00\u53d1\u677f\uff09\u5b66\u4e60\u7bc79\u2014\u2014\u5916\u90e8\u4e2d\u65ad"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

\u5916\u90e8\u4e2d\u65ad\u6982\u8ff0<\/h3>\n

\u2003\u2003STM32\u7684\u6bcf\u4e2aIO\u90fd\u53ef\u4ee5\u4f5c\u4e3a\u5916\u90e8\u4e2d\u65ad\u8f93\u5165\u3002
\u2003\u2003STM32\u7684\u4e2d\u65ad\u63a7\u5236\u5668\u652f\u630119\u4e2a\u5916\u90e8\u4e2d\u65ad\/\u4e8b\u4ef6\u8bf7\u6c42\uff1a
\u2003\u2003\u2003\u2003\u7ebf0~15<\/strong>\uff1a\u5bf9\u5e94\u5916\u90e8IO\u53e3\u7684\u8f93\u5165\u4e2d\u65ad\u3002<\/mark>
\u2003\u2003\u2003\u2003\u7ebf16<\/strong>\uff1a\u8fde\u63a5\u5230PVD\u8f93\u51fa\u3002
\u2003\u2003\u2003\u2003\u7ebf17<\/strong>\uff1a\u8fde\u63a5\u5230RTC\u95f9\u949f\u4e8b\u4ef6\u3002
\u2003\u2003\u2003\u2003\u7ebf18<\/strong>\uff1a\u8fde\u63a5\u5230USB\u5524\u9192\u4e8b\u4ef6\u3002<\/p>\n

\u2003\u2003\u6bcf\u4e2a\u5916\u90e8\u4e2d\u65ad\u7ebf\u53ef\u4ee5\u72ec\u7acb\u7684\u914d\u7f6e\u89e6\u53d1\u65b9\u5f0f<\/strong>\uff08\u4e0a\u5347\u6cbf\uff0c\u4e0b\u964d\u6cbf\u6216\u8005\u53cc\u8fb9\u6cbf\u89e6\u53d1\uff09\uff0c\u89e6\u53d1\/\u5c4f\u853d\uff0c\u4e13\u7528\u7684\u72b6\u6001\u4f4d\u3002<\/p>\n

\u2003\u2003\u4ece\u4e0a\u9762\u53ef\u4ee5\u770b\u51fa\uff0cSTM32\u4f9bIO\u4f7f\u7528\u7684\u4e2d\u65ad\u7ebf\u53ea\u670916\u4e2a\uff0c\u4f46\u662fSTM32F10x\u7cfb\u5217\u7684IO\u53e3\u591a\u8fbe\u4e0a\u767e\u4e2a\uff0cSTM32F103ZET6(112),
STM32F103RCT6(51)\uff0c\u90a3\u4e48\u4e2d\u65ad\u7ebf\u600e\u4e48\u8ddfio\u53e3\u5bf9\u5e94\u5462\uff1f<\/p>\n

\u5916\u90e8\u4e2d\u65ad\u901a\u7528I\/O\u6620\u50cf<\/h3>\n

\"STM32\u7cbe\u82f1\u7248\uff08\u6b63\u70b9\u539f\u5b50STM32F103ZET6\u5f00\u53d1\u677f\uff09\u5b66\u4e60\u7bc79\u2014\u2014\u5916\u90e8\u4e2d\u65ad
\u2003\u2003\u901a\u8fc7\u8be5\u56fe\u53ef\u77e5\uff0c\u6bcf\u4e00\u4e2a\u4e2d\u65ad\u7ebf\u90fd\u5bf9\u5e94\u4e867\u7ec4\u4e2d\u7684\u5bf9\u5e94\u7f16\u53f7\u7684IO\u53e3\uff08\u8fd9\u8fb9\u4ee5ZET6\uff1a112\u4e2aIO=16\u4e2a * 7\u7ec4\uff09\u3002
\u2003\u2003\u2003\u2003\u6709\u5982\u4e0b\u5173\u7cfb\uff1a
\u2003\u2003\u2003\u2003\u2003\u2003GPIOx.0\u6620\u5c04\u5230EXTI0
\u2003\u2003\u2003\u2003\u2003\u2003GPIOx.1\u6620\u5c04\u5230EXTI1
\u2003\u2003\u2003\u2003\u2003\u2003\u2026
\u2003\u2003\u2003\u2003\u2003\u2003GPIOx.15\u6620\u5c04\u5230EXTI15
\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
\"STM32\u7cbe\u82f1\u7248\uff08\u6b63\u70b9\u539f\u5b50STM32F103ZET6\u5f00\u53d1\u677f\uff09\u5b66\u4e60\u7bc79\u2014\u2014\u5916\u90e8\u4e2d\u65ad
\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>\n

LED<\/h4>\n

\"STM32\u7cbe\u82f1\u7248\uff08\u6b63\u70b9\u539f\u5b50STM32F103ZET6\u5f00\u53d1\u677f\uff09\u5b66\u4e60\u7bc79\u2014\u2014\u5916\u90e8\u4e2d\u65ad<\/p>\n

\u6309\u952e<\/h4>\n

\"STM32\u7cbe\u82f1\u7248\uff08\u6b63\u70b9\u539f\u5b50STM32F103ZET6\u5f00\u53d1\u677f\uff09\u5b66\u4e60\u7bc79\u2014\u2014\u5916\u90e8\u4e2d\u65ad<\/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>\n

void 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.<\/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> GPIO_InitTypeDef GPIO_InitStructure;<\/span> RCC_APB2PeriphClockCmd<\/span>(<\/span>RCC_APB2Periph_GPIOB|<\/span>RCC_APB2Periph_GPIOE,<\/span> ENABLE)<\/span>;<\/span> GPIO_InitStructure.<\/span>GPIO_Mode=<\/span> GPIO_Mode_Out_PP;<\/span> \/\/\u6a21\u5f0f\u9009\u62e9\u63a8\u633d\u8f93\u51fa<\/span> GPIO_InitStructure.<\/span>GPIO_Pin=<\/span>GPIO_Pin_5;<\/span> \/\/\u5f15\u811a\u9009\u62e95<\/span> GPIO_InitStructure.<\/span>GPIO_Speed=<\/span>GPIO_Speed_50MHz;<\/span> \/\/\u901f\u5ea6\u65cb\u8f6c50MHz<\/span> GPIO_Init<\/span>(<\/span>GPIOB,<\/span> &<\/span>GPIO_InitStructure)<\/span>;<\/span> \/\/\u7b2c\u4e00\u4e2a\u53c2\u6570GPIOB<\/span> \/\/\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u4e00\u4e2a\u7ed3\u6784\u4f53\u53d8\u91cf\uff0c\u8981\u7528&\u53bb\u53d6\uff0c\u4e14\u8be5\u7ed3\u6784\u4f53\u4e2d\u6709\u4e09\u4e2a\u53d8\u91cf<\/span> \/\/\u8981\u6839\u636eassert_param\u4e2d\u53bb\u786e\u5b9a\u8981\u586b\u5199\u4ec0\u4e48\u6837\u7684\u683c\u5f0f\u6570\u503c\u3002<\/span> GPIO_SetBits<\/span>(<\/span>GPIOB,<\/span> GPIO_Pin_5)<\/span>;<\/span> GPIO_InitStructure.<\/span>GPIO_Mode=<\/span> GPIO_Mode_Out_PP;<\/span> \/\/\u6a21\u5f0f\u9009\u62e9\u63a8\u633d\u8f93\u51fa<\/span> GPIO_InitStructure.<\/span>GPIO_Pin=<\/span>GPIO_Pin_5;<\/span> \/\/\u5f15\u811a\u9009\u62e95<\/span> GPIO_InitStructure.<\/span>GPIO_Speed=<\/span>GPIO_Speed_50MHz;<\/span> \/\/\u901f\u5ea6\u65cb\u8f6c50MHz<\/span> GPIO_Init<\/span>(<\/span>GPIOE,<\/span> &<\/span>GPIO_InitStructure)<\/span>;<\/span> \/\/\u7b2c\u4e00\u4e2a\u53c2\u6570GPIOE <\/span> \/\/\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u4e00\u4e2a\u7ed3\u6784\u4f53\u53d8\u91cf\uff0c\u8981\u7528&\u53bb\u53d6\uff0c\u4e14\u8be5\u7ed3\u6784\u4f53\u4e2d\u6709\u4e09\u4e2a\u53d8\u91cf<\/span> \/\/\u8981\u6839\u636eassert_param\u4e2d\u53bb\u786e\u5b9a\u8981\u586b\u5199\u4ec0\u4e48\u6837\u7684\u683c\u5f0f\u6570\u503c\u3002<\/span> GPIO_SetBits<\/span>(<\/span>GPIOE,<\/span> GPIO_Pin_5)<\/span>;<\/span> }<\/span> void<\/span> EXTI4_IRQHandler<\/span>(<\/span>void<\/span>)<\/span>{ \n   <\/span> delay_ms<\/span>(<\/span>10<\/span>)<\/span>;<\/span>\/\/\u9632\u6296\u5ef6\u65f6<\/span> if<\/span>(<\/span>KEY0 ==<\/span> 0<\/span>)<\/span>{ \n   <\/span> LED0 =<\/span> !<\/span>LED0;<\/span> LED1 =<\/span> !<\/span>LED1;<\/span> }<\/span> EXTI_ClearITPendingBit<\/span>(<\/span>EXTI_Line4)<\/span>;<\/span>\/\/\u624b\u52a8\u6e05\u9664\u6807\u5fd7\u4f4d\uff0cexti.h\u4e2d<\/span> }<\/span> <\/code><\/pre>\n

exti.h<\/p>\n

#ifndef<\/span> __EXIT_H<\/span> #define<\/span> __EXIT_H<\/span> #include<\/span> \"sys.h\"<\/span><\/span> void<\/span> EXTIX_Init<\/span>(<\/span>void<\/span>)<\/span>;<\/span> \/\/\u5916\u90e8\u4e2d\u65ad\u521d\u59cb\u5316<\/span> #define<\/span> KEY0 GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_4)<\/span> #define<\/span> KEY1 GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_3)<\/span> #define<\/span> WK_UP GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)<\/span> #define<\/span> LED0 PBout(5) <\/span>\/\/ DS0<\/span> #define<\/span> LED1 PEout(5) <\/span>\/\/ DS1<\/span> #endif<\/span><\/span> <\/code><\/pre>\n

main.c<\/p>\n

#include \"stm32f10x.h\" \/\/stm32\u5fc5\u8981\u7684\u5934\u6587\u4ef6 #include \"delay.h\" #include \"exti.h\" int main(void)<\/span>{ \n   <\/span> delay_init<\/span>(<\/span>)<\/span>;<\/span> NVIC_PriorityGroupConfig<\/span>(<\/span>NVIC_PriorityGroup_2)<\/span>;<\/span>\/\/\u8bbe\u7f6eNVIC\u4e2d\u65ad\u5206\u7ec4\uff0c2\u4f4d\u62a2\u5360\u4f18\u5148\u7ea7\uff0c2\u4f4d\u54cd\u5e94\u4f18\u5148\u7ea7 EXTIX_Init<\/span>(<\/span>)<\/span>;<\/span> LED0 = 0;<\/span> GPIO_SetBits<\/span>(<\/span>GPIOB, GPIO_Pin_5)<\/span>;<\/span> GPIO_SetBits<\/span>(<\/span>GPIOE, GPIO_Pin_5)<\/span>; while(1)<\/span>{ \n   <\/span> delay_ms<\/span>(<\/span>1000)<\/span>;<\/span> }<\/span> }<\/span> <\/code><\/pre>\n

\u5b9e\u9a8c\u6210\u679c<\/h3>\n

\u6309\u4e0b\u6309\u952eKEY0\u5b9e\u73b0\u4e24\u4e2aLED\u7684\u70b9\u4eae\u4e0e\u7184\u706d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"STM32\u7cbe\u82f1\u7248\uff08\u6b63\u70b9\u539f\u5b50STM32F103ZET6\u5f00\u53d1\u677f\uff09\u5b66\u4e60\u7bc79\u2014\u2014\u5916\u90e8\u4e2d\u65ad\u5916\u90e8\u4e2d\u65ad\u6982\u8ff0\u2003\u2003STM32\u7684\u6bcf\u4e2aIO\u90fd\u53ef\u4ee5\u4f5c\u4e3a\u5916\u90e8\u4e2d\u65ad\u8f93\u5165","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7047"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=7047"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7047\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=7047"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=7047"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=7047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}