基于NXP MCUXpresso SDK的GPIO控制与中断处理示例
<div id="yoCo-1736085835304" yne-bulb-block="heading" yne-bulb-level="4"><article data-content="[{"type":"block","id":"qCc6-1736082583134","name":"heading","data":{"version":1,"level":"h4","style":{"lineHeight":"1.7"}},"nodes":[{"type":"text","id":"fklv-1736082583135","leaves":[{"text":"引言","marks":[]}]}],"state":{}},{"type":"block","id":"6kkC-1736082584115","name":"paragraph","data":{"version":1,"style":{"lineHeight":"1.7"}},"nodes":[{"type":"text","id":"0Iqv-1736082584114","leaves":[{"text":"欢迎来到本次的技术分享!今天,我们将一起探讨一个基于NXP MCUXpresso SDK开发的GPIO(通用输入输出)控制与中断处理示例程序。这个程序展示了如何通过配置GPIO引脚来实现LED灯的闪烁以及按钮按下时的中断响应。","marks":[]}]}],"state":{}},{"type":"block","id":"urdJ-1736082787010","name":"heading","data":{"version":1,"level":"h4","style":{"lineHeight":"1.7"}},"nodes":[{"type":"text","id":"bmyu-1736082787009","leaves":[{"text":"程序概述","marks":[]}]}],"state":{}},{"type":"block","id":"yAJG-1736082788113","name":"paragraph","data":{"version":1,"style":{"lineHeight":"1.7"}},"nodes":[{"type":"text","id":"mhDr-1736082788112","leaves":[{"text":"该程序主要实现了以下功能:","marks":[]}]}],"state":{}},{"type":"block","id":"UJbS-1736082788115","name":"list-item","data":{"version":1,"listId":"7pCV-1736082788118","listLevel":1,"listType":"ordered","style":{"lineHeight":"1.7"}},"nodes":[{"type":"text","id":"sEDE-1736082788114","leaves":[{"text":"LED灯控制:通过GPIO引脚控制板载LED灯的闪烁。","marks":[]}]}],"state":{"index":1}},{"type":"block","id":"NA5p-1736082788117","name":"list-item","data":{"version":1,"listId":"7pCV-1736082788118","listLevel":1,"listType":"ordered","style":{"lineHeight":"1.7"}},"nodes":[{"type":"text","id":"Qe2i-1736082788116","leaves":[{"text":"按钮中断处理:配置GPIO引脚为中断输入,当按钮被按下时,触发中断并响应相应的动作(如切换LED灯状态)。","marks":[]}]}],"state":{"index":2}},{"type":"block","id":"bLbe-1736082793192","name":"heading","data":{"version":1,"level":"h4","style":{"lineHeight":"1.7"}},"nodes":[{"type":"text","id":"8FdB-1736082793191","leaves":[{"text":"关键组件与配置","marks":[]}]}],"state":{}},{"type":"block","id":"5CaP-1733974035579","name":"heading","data":{"level":"h5"},"nodes":[{"type":"text","id":"q4jo-1733974035580","leaves":[{"text":"外部中断号","marks":[{"type":"bold"}]}]}],"state":{}},{"type":"block","id":"r6jc-1736082273792","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"Zn17-1736082273790","leaves":[{"text":" 一组GPIO 可以使能2个中断","marks":[{"type":"bold"}]}]}],"state":{}},{"type":"block","id":"ulYT-1733469395843","name":"image","data":{"version":1,"url":"https://note.youdao.com/yws/res/10028/WEBRESOURCEe10891008202b479d99531197eecf755","width":736,"height":617,"fromIdentity":""},"nodes":[],"state":{"renderSource":"https://note.youdao.com/yws/res/10028/WEBRESOURCEe10891008202b479d99531197eecf755","initialSize":{"width":736,"height":617},"loading":false}},{"type":"block","id":"yvlW-1733469395848","name":"paragraph","data":{},"nodes":[{"type":"text","id":"R7l6-1733469395847","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"PvZ1-1733973921625","name":"paragraph","data":{},"nodes":[{"type":"text","id":"H6bW-1733973921623","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"VfNJ-1733973921786","name":"heading","data":{"level":"h5"},"nodes":[{"type":"text","id":"hS30-1733973921785","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"fvnp-1733974566847","name":"heading","data":{"level":"h5"},"nodes":[{"type":"text","id":"pjo1-1733974566845","leaves":[{"text":"ISF 中断状态标志","marks":[]}]}],"state":{}},{"type":"block","id":"2D4r-1733974186831","name":"paragraph","data":{},"nodes":[{"type":"text","id":"2ICq-1733974186830","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"48R7-1734066920189","name":"image","data":{"version":1,"url":"https://note.youdao.com/yws/res/10056/WEBRESOURCE048b0523cf086271e8ba5d83c5cb2624","width":671,"height":762,"fromIdentity":""},"nodes":[],"state":{"renderSource":"https://note.youdao.com/yws/res/10056/WEBRESOURCE048b0523cf086271e8ba5d83c5cb2624","initialSize":{"width":671,"height":762},"loading":false}},{"type":"block","id":"LuaW-1734067000468","name":"paragraph","data":{},"nodes":[{"type":"text","id":"nlMw-1734067000469","leaves":[{"text":"GPIO_PinGetInterruptFlag:","marks":[{"type":"fontSize","value":14},{"type":"fontFamily","value":"SimHei"},{"type":"bold"}]},{"text":"读单个引脚的中断状态标志","marks":[{"type":"color","value":"#2a2b2e"},{"type":"backgroundColor","value":"rgb(255, 255, 255)"},{"type":"fontSize","value":14},{"type":"fontFamily","value":"SimHei"},{"type":"bold"}]}]}],"state":{}},{"type":"block","id":"ubR5-1734067000467","name":"code","data":{"wrap":false,"language":"","theme":"default"},"nodes":[{"type":"block","id":"zD5f-1734067000466","name":"code-line","data":{},"nodes":[{"type":"text","id":"UxPq-1734067000464","leaves":[{"text":"","marks":[]}]}]},{"type":"block","id":"qbAp-1734067025855","name":"code-line","data":{},"nodes":[{"type":"text","id":"Y0a6-1734067025853","leaves":[{"text":"#define GPIO_ICR_ISF_SHIFT (24U)","marks":[]}]}]},{"type":"block","id":"SwRg-1734067026213","name":"code-line","data":{},"nodes":[{"type":"text","id":"HT3G-1734067026212","leaves":[{"text":"","marks":[]}]}]},{"type":"block","id":"46F7-1734067026399","name":"code-line","data":{},"nodes":[{"type":"text","id":"cDHK-1734067026398","leaves":[{"text":"/*!\r","marks":[]}]}]},{"type":"block","id":"IQ3c-1734067001938","name":"code-line","data":{},"nodes":[{"type":"text","id":"S8o9-1734067001937","leaves":[{"text":" * brief Read individual pin's interrupt status flag.\r","marks":[]}]}]},{"type":"block","id":"2zdy-1734067001940","name":"code-line","data":{},"nodes":[{"type":"text","id":"WzfL-1734067001939","leaves":[{"text":" *\r","marks":[]}]}]},{"type":"block","id":"AV6N-1734067001942","name":"code-line","data":{},"nodes":[{"type":"text","id":"dAoK-1734067001941","leaves":[{"text":" * param base GPIO peripheral base pointer. (GPIOA, GPIOB, GPIOC, and so on)\r","marks":[]}]}]},{"type":"block","id":"AwJN-1734067001944","name":"code-line","data":{},"nodes":[{"type":"text","id":"Shka-1734067001943","leaves":[{"text":" * param pin GPIO specific pin number.\r","marks":[]}]}]},{"type":"block","id":"zY1p-1734067001946","name":"code-line","data":{},"nodes":[{"type":"text","id":"BZYo-1734067001945","leaves":[{"text":" * return The current selected pin's interrupt status flag.\r","marks":[]}]}]},{"type":"block","id":"XeNI-1734067001948","name":"code-line","data":{},"nodes":[{"type":"text","id":"FTie-1734067001947","leaves":[{"text":" */\r","marks":[]}]}]},{"type":"block","id":"m7hW-1734067001950","name":"code-line","data":{},"nodes":[{"type":"text","id":"dmp1-1734067001949","leaves":[{"text":"uint8_t GPIO_PinGetInterruptFlag(GPIO_Type *base, uint32_t pin)\r","marks":[]}]}]},{"type":"block","id":"rtl9-1734067001952","name":"code-line","data":{},"nodes":[{"type":"text","id":"tLdX-1734067001951","leaves":[{"text":"{\r","marks":[]}]}]},{"type":"block","id":"8Ckd-1734067001954","name":"code-line","data":{},"nodes":[{"type":"text","id":"2j6K-1734067001953","leaves":[{"text":" return (uint8_t)((base->ICR & GPIO_ICR_ISF_MASK) >> GPIO_ICR_ISF_SHIFT);\r","marks":[]}]}]},{"type":"block","id":"O9eY-1734067001956","name":"code-line","data":{},"nodes":[{"type":"text","id":"EaPy-1734067001955","leaves":[{"text":"}","marks":[]}]}]}],"state":{}},{"type":"block","id":"0LpX-1734067000470","name":"paragraph","data":{},"nodes":[{"type":"text","id":"bkYT-1734067000471","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"Rfv7-1736055668229","name":"heading","data":{"version":1,"level":"h4","style":{"lineHeight":"1.7"}},"nodes":[{"type":"text","id":"MxAo-1736055668227","leaves":[{"text":"程序结构详解","marks":[]}]}],"state":{}},{"type":"block","id":"AbGE-1736084245127","name":"list-item","data":{"version":1,"listId":"Fd2e-1736084245994","listLevel":1,"listType":"ordered","style":{"lineHeight":"1.7"}},"nodes":[{"type":"text","id":"gmQV-1736084245128","leaves":[{"text":"头文件包含:","marks":[]}]}],"state":{"index":1}},{"type":"block","id":"o6fr-1736084245987","name":"list-item","data":{"version":1,"listId":"tNMT-1736084245995","listLevel":2,"listType":"unordered","style":{"lineHeight":"1.7"}},"nodes":[{"type":"text","id":"KGHi-1736084245986","leaves":[{"text":"包含了必要的头文件,如","marks":[]},{"text":"fsl_debug_console.h","marks":[{"type":"backgroundColor","value":"rgba(27, 31, 35, 0.05)"},{"type":"fontSize","value":12},{"type":"fontFamily","value":"Courier New"}]},{"text":"用于调试输出,","marks":[]},{"text":"fsl_gpio.h","marks":[{"type":"backgroundColor","value":"rgba(27, 31, 35, 0.05)"},{"type":"fontSize","value":12},{"type":"fontFamily","value":"Courier New"}]},{"text":"用于GPIO控制等。","marks":[]}]}],"state":{"index":1}},{"type":"block","id":"1MGx-1736084288707","name":"code","data":{"wrap":false,"language":"","theme":"default"},"nodes":[{"type":"block","id":"aJJS-1736084288706","name":"code-line","data":{},"nodes":[{"type":"text","id":"sNxK-1736084288705","leaves":[{"text":"#include \"fsl_debug_console.h\"\r","marks":[]}]}]},{"type":"block","id":"mEOd-1736084290281","name":"code-line","data":{},"nodes":[{"type":"text","id":"iHGy-1736084290280","leaves":[{"text":"#if defined(FSL_FEATURE_SOC_PORT_COUNT) && (FSL_FEATURE_SOC_PORT_COUNT)\r","marks":[]}]}]},{"type":"block","id":"heAZ-1736084290283","name":"code-line","data":{},"nodes":[{"type":"text","id":"XemU-1736084290282","leaves":[{"text":"#include \"fsl_port.h\"\r","marks":[]}]}]},{"type":"block","id":"D9bH-1736084290285","name":"code-line","data":{},"nodes":[{"type":"text","id":"kRIy-1736084290284","leaves":[{"text":"#endif\r","marks":[]}]}]},{"type":"block","id":"Ruvn-1736084290288","name":"code-line","data":{},"nodes":[{"type":"text","id":"h8of-1736084290287","leaves":[{"text":"#include \"fsl_gpio.h\"\r","marks":[]}]}]},{"type":"block","id":"f9C6-1736084290290","name":"code-line","data":{},"nodes":[{"type":"text","id":"0rRr-1736084290289","leaves":[{"text":"#include \"fsl_common.h\"\r","marks":[]}]}]},{"type":"block","id":"v2uh-1736084290292","name":"code-line","data":{},"nodes":[{"type":"text","id":"grik-1736084290291","leaves":[{"text":"#include \"pin_mux.h\"\r","marks":[]}]}]},{"type":"block","id":"8cW9-1736084290294","name":"code-line","data":{},"nodes":[{"type":"text","id":"qEvC-1736084290293","leaves":[{"text":"#include \"clock_config.h\"\r","marks":[]}]}]},{"type":"block","id":"zzah-1736084290296","name":"code-line","data":{},"nodes":[{"type":"text","id":"3Bva-1736084290295","leaves":[{"text":"#include \"board.h\"\r","marks":[]}]}]},{"type":"block","id":"WBUR-1736084290298","name":"code-line","data":{},"nodes":[{"type":"text","id":"K0LM-1736084290297","leaves":[{"text":" ","marks":[]}]}]}],"state":{}},{"type":"block","id":"oAmg-1736084245989","name":"list-item","data":{"version":1,"listId":"Fd2e-1736084245994","listLevel":1,"listType":"ordered","style":{"lineHeight":"1.7"}},"nodes":[{"type":"text","id":"jUec-1736084245988","leaves":[{"text":"宏定义与变量声明:","marks":[]}]}],"state":{"index":2}},{"type":"block","id":"qNxs-1736084245991","name":"list-item","data":{"version":1,"listId":"UsuB-1736084245996","listLevel":2,"listType":"unordered","style":{"lineHeight":"1.7"}},"nodes":[{"type":"text","id":"eqQr-1736084245990","leaves":[{"text":"定义了LED和按钮对应的GPIO引脚。","marks":[]}]}],"state":{"index":1}},{"type":"block","id":"Wa0x-1736084245993","name":"list-item","data":{"version":1,"listId":"UsuB-1736084245996","listLevel":2,"listType":"unordered","style":{"lineHeight":"1.7"}},"nodes":[{"type":"text","id":"ZrXF-1736084245992","leaves":[{"text":"声明了用于标记按钮按下状态的变量。","marks":[]}]}],"state":{"index":2}},{"type":"block","id":"5RIS-1736084353595","name":"code","data":{"wrap":false,"language":"","theme":"default"},"nodes":[{"type":"block","id":"KoyB-1736084353594","name":"code-line","data":{},"nodes":[{"type":"text","id":"QZ6U-1736084353593","leaves":[{"text":"volatile bool g_ButtonPress = false;\r","marks":[]}]}]},{"type":"block","id":"3d8s-1736084354681","name":"code-line","data":{},"nodes":[{"type":"text","id":"sE4J-1736084354680","leaves":[{"text":"volatile bool g_ButtonPress1 = false;\r","marks":[]}]}]},{"type":"block","id":"i4KF-1736084354683","name":"code-line","data":{},"nodes":[{"type":"text","id":"E35c-1736084354682","leaves":[{"text":"volatile bool g_ButtonPress2 = false;","marks":[]}]}]}],"state":{}},{"type":"block","id":"BEsd-1736084879944","name":"paragraph","data":{},"nodes":[{"type":"text","id":"hkfK-1736084879945","leaves":[{"text":"3.中断服务函数实现:","marks":[{"type":"color","value":"#05073b"},{"type":"backgroundColor","value":"rgb(253, 253, 254)"},{"type":"fontSize","value":15},{"type":"fontFamily","value":"Arial"}]}]}],"state":{}},{"type":"block","id":"iyj5-1736084879943","name":"code","data":{"wrap":false,"language":"","theme":"default"},"nodes":[{"type":"block","id":"IMW3-1736084879942","name":"code-line","data":{},"nodes":[{"type":"text","id":"wxTN-1736084879941","leaves":[{"text":"void BOARD_SW_IRQ_HANDLER(void)\r","marks":[]}]}]},{"type":"block","id":"XDvk-1736084904475","name":"code-line","data":{},"nodes":[{"type":"text","id":"x0XE-1736084904474","leaves":[{"text":"{\r","marks":[]}]}]},{"type":"block","id":"TAIJ-1736084904477","name":"code-line","data":{},"nodes":[{"type":"text","id":"Z6kC-1736084904476","leaves":[{"text":"\tif(GPIO_PinGetInterruptFlag(GPIO0,6))\r","marks":[]}]}]},{"type":"block","id":"IbPh-1736084904479","name":"code-line","data":{},"nodes":[{"type":"text","id":"IfGy-1736084904478","leaves":[{"text":"\t{\r","marks":[]}]}]},{"type":"block","id":"Lmbi-1736084904481","name":"code-line","data":{},"nodes":[{"type":"text","id":"BEva-1736084904480","leaves":[{"text":"\t #if (defined(FSL_FEATURE_PORT_HAS_NO_INTERRUPT) && FSL_FEATURE_PORT_HAS_NO_INTERRUPT) || \\\r","marks":[]}]}]},{"type":"block","id":"ctFQ-1736084904483","name":"code-line","data":{},"nodes":[{"type":"text","id":"YjpD-1736084904482","leaves":[{"text":" (!defined(FSL_FEATURE_SOC_PORT_COUNT))\r","marks":[]}]}]},{"type":"block","id":"shFF-1736084904485","name":"code-line","data":{},"nodes":[{"type":"text","id":"n5Wv-1736084904484","leaves":[{"text":" /* Clear external interrupt flag. */\r","marks":[]}]}]},{"type":"block","id":"UKDk-1736084904487","name":"code-line","data":{},"nodes":[{"type":"text","id":"yKIv-1736084904486","leaves":[{"text":" GPIO_GpioClearInterruptFlags(BOARD_SW_GPIO, 1U << BOARD_SW_GPIO_PIN);\r","marks":[]}]}]},{"type":"block","id":"Te72-1736084904489","name":"code-line","data":{},"nodes":[{"type":"text","id":"4H8D-1736084904488","leaves":[{"text":" #else\r","marks":[]}]}]},{"type":"block","id":"ltdO-1736084904491","name":"code-line","data":{},"nodes":[{"type":"text","id":"aRG4-1736084904490","leaves":[{"text":" /* Clear external interrupt flag. */\r","marks":[]}]}]},{"type":"block","id":"sqR8-1736084904493","name":"code-line","data":{},"nodes":[{"type":"text","id":"wKwg-1736084904492","leaves":[{"text":" GPIO_PortClearInterruptFlags(BOARD_SW_GPIO, 1U << BOARD_SW_GPIO_PIN);\r","marks":[]}]}]},{"type":"block","id":"V89f-1736084904495","name":"code-line","data":{},"nodes":[{"type":"text","id":"MBJE-1736084904494","leaves":[{"text":" #endif\r","marks":[]}]}]},{"type":"block","id":"0Wgg-1736084904497","name":"code-line","data":{},"nodes":[{"type":"text","id":"LKb2-1736084904496","leaves":[{"text":" /* Change state of button. */\r","marks":[]}]}]},{"type":"block","id":"2Boy-1736084904499","name":"code-line","data":{},"nodes":[{"type":"text","id":"FPa5-1736084904498","leaves":[{"text":" g_ButtonPress = true;\r","marks":[]}]}]},{"type":"block","id":"0qft-1736084904501","name":"code-line","data":{},"nodes":[{"type":"text","id":"b7VD-1736084904500","leaves":[{"text":"\t\r","marks":[]}]}]},{"type":"block","id":"wlHR-1736084904503","name":"code-line","data":{},"nodes":[{"type":"text","id":"N1gI-1736084904502","leaves":[{"text":"\t}\r","marks":[]}]}]},{"type":"block","id":"V3ex-1736084904505","name":"code-line","data":{},"nodes":[{"type":"text","id":"MdJ1-1736084904504","leaves":[{"text":"\t\r","marks":[]}]}]},{"type":"block","id":"nuOT-1736084904507","name":"code-line","data":{},"nodes":[{"type":"text","id":"mWeP-1736084904506","leaves":[{"text":"\tif(GPIO_PinGetInterruptFlag(GPIO0,29))\r","marks":[]}]}]},{"type":"block","id":"o5J2-1736084904509","name":"code-line","data":{},"nodes":[{"type":"text","id":"auf4-1736084904508","leaves":[{"text":"\t{\r","marks":[]}]}]},{"type":"block","id":"Mbrg-1736084904511","name":"code-line","data":{},"nodes":[{"type":"text","id":"da44-1736084904510","leaves":[{"text":"\t #if (defined(FSL_FEATURE_PORT_HAS_NO_INTERRUPT) && FSL_FEATURE_PORT_HAS_NO_INTERRUPT) || \\\r","marks":[]}]}]},{"type":"block","id":"keKF-1736084904513","name":"code-line","data":{},"nodes":[{"type":"text","id":"lEzK-1736084904512","leaves":[{"text":" (!defined(FSL_FEATURE_SOC_PORT_COUNT))\r","marks":[]}]}]},{"type":"block","id":"XVXv-1736084904515","name":"code-line","data":{},"nodes":[{"type":"text","id":"EgwE-1736084904514","leaves":[{"text":" /* Clear external interrupt flag. */\r","marks":[]}]}]},{"type":"block","id":"kpaW-1736084904517","name":"code-line","data":{},"nodes":[{"type":"text","id":"62qQ-1736084904516","leaves":[{"text":" GPIO_GpioClearInterruptFlags(GPIO0, 1U << 29);\r","marks":[]}]}]},{"type":"block","id":"Z8Ob-1736084904519","name":"code-line","data":{},"nodes":[{"type":"text","id":"Zp7q-1736084904518","leaves":[{"text":" #else\r","marks":[]}]}]},{"type":"block","id":"4HcW-1736084904521","name":"code-line","data":{},"nodes":[{"type":"text","id":"lPHP-1736084904520","leaves":[{"text":" /* Clear external interrupt flag. */\r","marks":[]}]}]},{"type":"block","id":"ce7c-1736084904523","name":"code-line","data":{},"nodes":[{"type":"text","id":"lgdJ-1736084904522","leaves":[{"text":" GPIO_PortClearInterruptFlags(BOARD_SW_GPIO, 1U << BOARD_SW_GPIO_PIN);\r","marks":[]}]}]},{"type":"block","id":"HXKq-1736084904525","name":"code-line","data":{},"nodes":[{"type":"text","id":"TPMw-1736084904524","leaves":[{"text":" #endif\r","marks":[]}]}]},{"type":"block","id":"ASJT-1736084904527","name":"code-line","data":{},"nodes":[{"type":"text","id":"aDrL-1736084904526","leaves":[{"text":" /* Change state of button. */\r","marks":[]}]}]},{"type":"block","id":"asWW-1736084904529","name":"code-line","data":{},"nodes":[{"type":"text","id":"sXi2-1736084904528","leaves":[{"text":" g_ButtonPress1 = true;\r","marks":[]}]}]},{"type":"block","id":"SKyJ-1736084904531","name":"code-line","data":{},"nodes":[{"type":"text","id":"XsjA-1736084904530","leaves":[{"text":"\t\r","marks":[]}]}]},{"type":"block","id":"tI1n-1736084904533","name":"code-line","data":{},"nodes":[{"type":"text","id":"h5BK-1736084904532","leaves":[{"text":"\t}\r","marks":[]}]}]},{"type":"block","id":"aBn8-1736084904535","name":"code-line","data":{},"nodes":[{"type":"text","id":"cNJQ-1736084904534","leaves":[{"text":"\t\r","marks":[]}]}]},{"type":"block","id":"dOsz-1736084904537","name":"code-line","data":{},"nodes":[{"type":"text","id":"wTsG-1736084904536","leaves":[{"text":"\tif(GPIO_PinGetInterruptFlag(GPIO1,23))\r","marks":[]}]}]},{"type":"block","id":"tEy9-1736084904539","name":"code-line","data":{},"nodes":[{"type":"text","id":"9vwe-1736084904538","leaves":[{"text":"\t{\r","marks":[]}]}]},{"type":"block","id":"dRgN-1736084904541","name":"code-line","data":{},"nodes":[{"type":"text","id":"Hluz-1736084904540","leaves":[{"text":"\t #if (defined(FSL_FEATURE_PORT_HAS_NO_INTERRUPT) && FSL_FEATURE_PORT_HAS_NO_INTERRUPT) || \\\r","marks":[]}]}]},{"type":"block","id":"RVij-1736084904543","name":"code-line","data":{},"nodes":[{"type":"text","id":"ASbm-1736084904542","leaves":[{"text":" (!defined(FSL_FEATURE_SOC_PORT_COUNT))\r","marks":[]}]}]},{"type":"block","id":"52gX-1736084904545","name":"code-line","data":{},"nodes":[{"type":"text","id":"vVGl-1736084904544","leaves":[{"text":" /* Clear external interrupt flag. */\r","marks":[]}]}]},{"type":"block","id":"yWQM-1736084904547","name":"code-line","data":{},"nodes":[{"type":"text","id":"pi8j-1736084904546","leaves":[{"text":" GPIO_GpioClearInterruptFlags(GPIO1, 1U << 23);\r","marks":[]}]}]},{"type":"block","id":"GxJE-1736084904549","name":"code-line","data":{},"nodes":[{"type":"text","id":"GMat-1736084904548","leaves":[{"text":" #else\r","marks":[]}]}]},{"type":"block","id":"Y7t2-1736084904551","name":"code-line","data":{},"nodes":[{"type":"text","id":"RmOV-1736084904550","leaves":[{"text":" /* Clear external interrupt flag. */\r","marks":[]}]}]},{"type":"block","id":"oY1x-1736084904553","name":"code-line","data":{},"nodes":[{"type":"text","id":"gqep-1736084904552","leaves":[{"text":" GPIO_PortClearInterruptFlags(BOARD_SW_GPIO, 1U << BOARD_SW_GPIO_PIN);\r","marks":[]}]}]},{"type":"block","id":"Qlhg-1736084904555","name":"code-line","data":{},"nodes":[{"type":"text","id":"r9wX-1736084904554","leaves":[{"text":" #endif\r","marks":[]}]}]},{"type":"block","id":"j64H-1736084904557","name":"code-line","data":{},"nodes":[{"type":"text","id":"OgRy-1736084904556","leaves":[{"text":" /* Change state of button. */\r","marks":[]}]}]},{"type":"block","id":"yayz-1736084904559","name":"code-line","data":{},"nodes":[{"type":"text","id":"COMi-1736084904558","leaves":[{"text":" g_ButtonPress2 = true;\r","marks":[]}]}]},{"type":"block","id":"Ns7b-1736084904561","name":"code-line","data":{},"nodes":[{"type":"text","id":"kNT7-1736084904560","leaves":[{"text":"\t\r","marks":[]}]}]},{"type":"block","id":"hpxf-1736084904563","name":"code-line","data":{},"nodes":[{"type":"text","id":"XRBc-1736084904562","leaves":[{"text":"\t}\r","marks":[]}]}]},{"type":"block","id":"UzNZ-1736084904565","name":"code-line","data":{},"nodes":[{"type":"text","id":"yn71-1736084904564","leaves":[{"text":"\r","marks":[]}]}]},{"type":"block","id":"T2UC-1736084904567","name":"code-line","data":{},"nodes":[{"type":"text","id":"Ge4a-1736084904566","leaves":[{"text":" SDK_ISR_EXIT_BARRIER;\r","marks":[]}]}]},{"type":"block","id":"oQdw-1736084904569","name":"code-line","data":{},"nodes":[{"type":"text","id":"RmjL-1736084904568","leaves":[{"text":"}\r","marks":[]}]}]},{"type":"block","id":"Q9Mn-1736084904571","name":"code-line","data":{},"nodes":[{"type":"text","id":"q8VO-1736084904570","leaves":[{"text":"","marks":[]}]}]}],"state":{}},{"type":"block","id":"Y1Ha-1736055668504","name":"paragraph","data":{},"nodes":[{"type":"text","id":"GMex-1736055668502","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"eARf-1736085263467","name":"paragraph","data":{},"nodes":[{"type":"text","id":"yEiQ-1736085263465","leaves":[{"text":"4.主函数实现:","marks":[{"type":"color","value":"#05073b"},{"type":"backgroundColor","value":"rgb(253, 253, 254)"},{"type":"fontSize","value":15},{"type":"fontFamily","value":"Arial"}]}]}],"state":{}},{"type":"block","id":"fmz8-1736085268508","name":"code","data":{"wrap":false,"language":"","theme":"default"},"nodes":[{"type":"block","id":"yLHT-1736085268507","name":"code-line","data":{},"nodes":[{"type":"text","id":"lMyL-1736085268506","leaves":[{"text":"int main(void)\r","marks":[]}]}]},{"type":"block","id":"pid3-1736085269828","name":"code-line","data":{},"nodes":[{"type":"text","id":"xbNW-1736085269827","leaves":[{"text":"{\r","marks":[]}]}]},{"type":"block","id":"lRuE-1736085269830","name":"code-line","data":{},"nodes":[{"type":"text","id":"DVj5-1736085269829","leaves":[{"text":" /* Define the init structure for the output LED pin*/\r","marks":[]}]}]},{"type":"block","id":"TECg-1736085269832","name":"code-line","data":{},"nodes":[{"type":"text","id":"7NUt-1736085269831","leaves":[{"text":" gpio_pin_config_t led_config = {\r","marks":[]}]}]},{"type":"block","id":"H2fE-1736085269834","name":"code-line","data":{},"nodes":[{"type":"text","id":"AzQw-1736085269833","leaves":[{"text":" kGPIO_DigitalOutput,\r","marks":[]}]}]},{"type":"block","id":"YwuZ-1736085269836","name":"code-line","data":{},"nodes":[{"type":"text","id":"FJAb-1736085269835","leaves":[{"text":" 0,\r","marks":[]}]}]},{"type":"block","id":"19xb-1736085269838","name":"code-line","data":{},"nodes":[{"type":"text","id":"HfhF-1736085269837","leaves":[{"text":" };\r","marks":[]}]}]},{"type":"block","id":"PfUJ-1736085269840","name":"code-line","data":{},"nodes":[{"type":"text","id":"WA2h-1736085269839","leaves":[{"text":"\t\t\r","marks":[]}]}]},{"type":"block","id":"BKt3-1736085269842","name":"code-line","data":{},"nodes":[{"type":"text","id":"Tc6D-1736085269841","leaves":[{"text":"\t\t /* Define the init structure for the input switch pin */\r","marks":[]}]}]},{"type":"block","id":"QOnJ-1736085269844","name":"code-line","data":{},"nodes":[{"type":"text","id":"CZeG-1736085269843","leaves":[{"text":" gpio_pin_config_t sw_config = {\r","marks":[]}]}]},{"type":"block","id":"2sEr-1736085269846","name":"code-line","data":{},"nodes":[{"type":"text","id":"qvgv-1736085269845","leaves":[{"text":" kGPIO_DigitalInput,\r","marks":[]}]}]},{"type":"block","id":"yuGr-1736085269848","name":"code-line","data":{},"nodes":[{"type":"text","id":"a0Ak-1736085269847","leaves":[{"text":" 0,\r","marks":[]}]}]},{"type":"block","id":"JDgq-1736085269850","name":"code-line","data":{},"nodes":[{"type":"text","id":"YZHR-1736085269849","leaves":[{"text":" };\r","marks":[]}]}]},{"type":"block","id":"7Q3I-1736085269852","name":"code-line","data":{},"nodes":[{"type":"text","id":"4pRk-1736085269851","leaves":[{"text":"\r","marks":[]}]}]},{"type":"block","id":"THKx-1736085269854","name":"code-line","data":{},"nodes":[{"type":"text","id":"ouEG-1736085269853","leaves":[{"text":" /* Board pin, clock, debug console init */\r","marks":[]}]}]},{"type":"block","id":"JLqi-1736085269856","name":"code-line","data":{},"nodes":[{"type":"text","id":"nr89-1736085269855","leaves":[{"text":" /* attach FRO 12M to FLEXCOMM4 (debug console) */\r","marks":[]}]}]},{"type":"block","id":"ypy1-1736085269858","name":"code-line","data":{},"nodes":[{"type":"text","id":"eZ0K-1736085269857","leaves":[{"text":" CLOCK_SetClkDiv(kCLOCK_DivFlexcom4Clk, 1u);\r","marks":[]}]}]},{"type":"block","id":"ipRY-1736085269860","name":"code-line","data":{},"nodes":[{"type":"text","id":"V4Hs-1736085269859","leaves":[{"text":" CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);\r","marks":[]}]}]},{"type":"block","id":"pKki-1736085269862","name":"code-line","data":{},"nodes":[{"type":"text","id":"OquH-1736085269861","leaves":[{"text":"\r","marks":[]}]}]},{"type":"block","id":"Ka7i-1736085269864","name":"code-line","data":{},"nodes":[{"type":"text","id":"76iu-1736085269863","leaves":[{"text":" /* enable clock for GPIO*/\r","marks":[]}]}]},{"type":"block","id":"UeOM-1736085269866","name":"code-line","data":{},"nodes":[{"type":"text","id":"sOVI-1736085269865","leaves":[{"text":" CLOCK_EnableClock(kCLOCK_Gpio0);\r","marks":[]}]}]},{"type":"block","id":"orYL-1736085269868","name":"code-line","data":{},"nodes":[{"type":"text","id":"JXnt-1736085269867","leaves":[{"text":"\t\tCLOCK_EnableClock(kCLOCK_Gpio1);\r","marks":[]}]}]},{"type":"block","id":"wTqR-1736085269870","name":"code-line","data":{},"nodes":[{"type":"text","id":"v2tq-1736085269869","leaves":[{"text":"\r","marks":[]}]}]},{"type":"block","id":"cyQm-1736085269872","name":"code-line","data":{},"nodes":[{"type":"text","id":"mJcX-1736085269871","leaves":[{"text":" BOARD_InitPins();\r","marks":[]}]}]},{"type":"block","id":"uTF0-1736085269874","name":"code-line","data":{},"nodes":[{"type":"text","id":"rGov-1736085269873","leaves":[{"text":" BOARD_InitBootClocks();\r","marks":[]}]}]},{"type":"block","id":"dL7G-1736085269876","name":"code-line","data":{},"nodes":[{"type":"text","id":"0IUt-1736085269875","leaves":[{"text":" BOARD_InitDebugConsole();\r","marks":[]}]}]},{"type":"block","id":"VGHM-1736085269878","name":"code-line","data":{},"nodes":[{"type":"text","id":"8Lax-1736085269877","leaves":[{"text":"\r","marks":[]}]}]},{"type":"block","id":"Q0ye-1736085269880","name":"code-line","data":{},"nodes":[{"type":"text","id":"Ie4R-1736085269879","leaves":[{"text":" /* Print a note to terminal. */\r","marks":[]}]}]},{"type":"block","id":"bXMD-1736085269882","name":"code-line","data":{},"nodes":[{"type":"text","id":"p72N-1736085269881","leaves":[{"text":" PRINTF(\"\\r\\n GPIO Driver example\\r\\n\");\r","marks":[]}]}]},{"type":"block","id":"PNf1-1736085269884","name":"code-line","data":{},"nodes":[{"type":"text","id":"Ch55-1736085269883","leaves":[{"text":" PRINTF(\"\\r\\n The LED is blinking.\\r\\n\");\r","marks":[]}]}]},{"type":"block","id":"4kJi-1736085269886","name":"code-line","data":{},"nodes":[{"type":"text","id":"dah3-1736085269885","leaves":[{"text":" \r","marks":[]}]}]},{"type":"block","id":"Nu3J-1736085269888","name":"code-line","data":{},"nodes":[{"type":"text","id":"I9Uq-1736085269887","leaves":[{"text":"\t\tGPIO_SetPinInterruptConfig(BOARD_SW_GPIO, BOARD_SW_GPIO_PIN, kGPIO_InterruptFallingEdge);\r","marks":[]}]}]},{"type":"block","id":"refa-1736085269890","name":"code-line","data":{},"nodes":[{"type":"text","id":"2teS-1736085269889","leaves":[{"text":"\t\tGPIO_SetPinInterruptConfig(GPIO0, 29, kGPIO_InterruptFallingEdge);\r","marks":[]}]}]},{"type":"block","id":"dppd-1736085269893","name":"code-line","data":{},"nodes":[{"type":"text","id":"vjhL-1736085269892","leaves":[{"text":"\t\tGPIO_SetPinInterruptChannel(GPIO0, 29,kGPIO_InterruptOutput0);\r","marks":[]}]}]},{"type":"block","id":"h7l7-1736085269895","name":"code-line","data":{},"nodes":[{"type":"text","id":"c7GZ-1736085269894","leaves":[{"text":"\t\t\r","marks":[]}]}]},{"type":"block","id":"0oxN-1736085269897","name":"code-line","data":{},"nodes":[{"type":"text","id":"PUf1-1736085269896","leaves":[{"text":"\t\tGPIO_SetPinInterruptConfig(GPIO1, 23, kGPIO_InterruptFallingEdge);\r","marks":[]}]}]},{"type":"block","id":"eknO-1736085269899","name":"code-line","data":{},"nodes":[{"type":"text","id":"nDQX-1736085269898","leaves":[{"text":"\t\tGPIO_SetPinInterruptChannel(GPIO1, 23,kGPIO_InterruptOutput0);\r","marks":[]}]}]},{"type":"block","id":"IqDB-1736085269901","name":"code-line","data":{},"nodes":[{"type":"text","id":"oNr6-1736085269900","leaves":[{"text":"\t\t\r","marks":[]}]}]},{"type":"block","id":"5VjN-1736085269903","name":"code-line","data":{},"nodes":[{"type":"text","id":"HwcC-1736085269902","leaves":[{"text":"\t\t\r","marks":[]}]}]},{"type":"block","id":"OYiF-1736085269905","name":"code-line","data":{},"nodes":[{"type":"text","id":"fAly-1736085269904","leaves":[{"text":"\t\tEnableIRQ(BOARD_SW_IRQ);\r","marks":[]}]}]},{"type":"block","id":"8jT2-1736085269907","name":"code-line","data":{},"nodes":[{"type":"text","id":"hCJS-1736085269906","leaves":[{"text":"\t\tEnableIRQ(GPIO10_IRQn);\r","marks":[]}]}]},{"type":"block","id":"QQ4y-1736085269909","name":"code-line","data":{},"nodes":[{"type":"text","id":"pEWo-1736085269908","leaves":[{"text":" GPIO_PinInit(BOARD_SW_GPIO, BOARD_SW_GPIO_PIN, &sw_config);\r","marks":[]}]}]},{"type":"block","id":"dUr2-1736085269911","name":"code-line","data":{},"nodes":[{"type":"text","id":"37Tk-1736085269910","leaves":[{"text":" GPIO_PinInit(GPIO0, 29, &sw_config);\r","marks":[]}]}]},{"type":"block","id":"lmnU-1736085269913","name":"code-line","data":{},"nodes":[{"type":"text","id":"DtJO-1736085269912","leaves":[{"text":"\t\tGPIO_PinInit(GPIO1, 23, &sw_config);\r","marks":[]}]}]},{"type":"block","id":"QFGs-1736085269915","name":"code-line","data":{},"nodes":[{"type":"text","id":"vN9q-1736085269914","leaves":[{"text":"\t\tGPIO_PinInit(BOARD_LED_GPIO, BOARD_LED_GPIO_PIN, &led_config);\r","marks":[]}]}]},{"type":"block","id":"is0X-1736085269917","name":"code-line","data":{},"nodes":[{"type":"text","id":"FRYw-1736085269916","leaves":[{"text":"\t\tGPIO_PinInit(GPIO0, 25, &led_config);\r","marks":[]}]}]},{"type":"block","id":"vqqf-1736085269919","name":"code-line","data":{},"nodes":[{"type":"text","id":"VAh8-1736085269918","leaves":[{"text":" GPIO_PinInit(GPIO0, 26, &led_config);\r","marks":[]}]}]},{"type":"block","id":"XXvU-1736085269921","name":"code-line","data":{},"nodes":[{"type":"text","id":"umXo-1736085269920","leaves":[{"text":"\r","marks":[]}]}]},{"type":"block","id":"WgAf-1736085269923","name":"code-line","data":{},"nodes":[{"type":"text","id":"MVE4-1736085269922","leaves":[{"text":"\r","marks":[]}]}]},{"type":"block","id":"wUcA-1736085269925","name":"code-line","data":{},"nodes":[{"type":"text","id":"hUg1-1736085269924","leaves":[{"text":" while (1)\r","marks":[]}]}]},{"type":"block","id":"a5Ey-1736085269927","name":"code-line","data":{},"nodes":[{"type":"text","id":"ypIG-1736085269926","leaves":[{"text":" {\r","marks":[]}]}]},{"type":"block","id":"fb3B-1736085269929","name":"code-line","data":{},"nodes":[{"type":"text","id":"8o9W-1736085269928","leaves":[{"text":"// delay();\r","marks":[]}]}]},{"type":"block","id":"w3Pm-1736085269931","name":"code-line","data":{},"nodes":[{"type":"text","id":"gU0A-1736085269930","leaves":[{"text":"// GPIO_PortToggle(BOARD_LED_GPIO, 1u << BOARD_LED_GPIO_PIN);\r","marks":[]}]}]},{"type":"block","id":"vcQ9-1736085269933","name":"code-line","data":{},"nodes":[{"type":"text","id":"fdC6-1736085269932","leaves":[{"text":"//\t\t\t GPIO_PortToggle(GPIO0, 1u << 25);\r","marks":[]}]}]},{"type":"block","id":"p9uc-1736085269935","name":"code-line","data":{},"nodes":[{"type":"text","id":"F2LO-1736085269934","leaves":[{"text":"//\t\t\t GPIO_PortToggle(GPIO0, 1u << 26);\r","marks":[]}]}]},{"type":"block","id":"Wdqp-1736085269937","name":"code-line","data":{},"nodes":[{"type":"text","id":"UT1D-1736085269936","leaves":[{"text":"\t\t\t\r","marks":[]}]}]},{"type":"block","id":"6isC-1736085269939","name":"code-line","data":{},"nodes":[{"type":"text","id":"jGMs-1736085269938","leaves":[{"text":"\t\t\t if (g_ButtonPress)\r","marks":[]}]}]},{"type":"block","id":"1KN1-1736085269941","name":"code-line","data":{},"nodes":[{"type":"text","id":"6Y6Y-1736085269940","leaves":[{"text":" {\r","marks":[]}]}]},{"type":"block","id":"qJH2-1736085269943","name":"code-line","data":{},"nodes":[{"type":"text","id":"7jeS-1736085269942","leaves":[{"text":" PRINTF(\" %s is pressed \\r\\n\", BOARD_SW_NAME);\r","marks":[]}]}]},{"type":"block","id":"4WLs-1736085269945","name":"code-line","data":{},"nodes":[{"type":"text","id":"7zpi-1736085269944","leaves":[{"text":" /* Toggle LED. */\r","marks":[]}]}]},{"type":"block","id":"MQAy-1736085269947","name":"code-line","data":{},"nodes":[{"type":"text","id":"xczo-1736085269946","leaves":[{"text":" GPIO_PortToggle(BOARD_LED_GPIO, 1U << BOARD_LED_GPIO_PIN);\r","marks":[]}]}]},{"type":"block","id":"4s1U-1736085269949","name":"code-line","data":{},"nodes":[{"type":"text","id":"TmjK-1736085269948","leaves":[{"text":" /* Reset state of button. */\r","marks":[]}]}]},{"type":"block","id":"UuZE-1736085269951","name":"code-line","data":{},"nodes":[{"type":"text","id":"l31Y-1736085269950","leaves":[{"text":" g_ButtonPress = false;\r","marks":[]}]}]},{"type":"block","id":"HAp6-1736085269953","name":"code-line","data":{},"nodes":[{"type":"text","id":"TD9C-1736085269952","leaves":[{"text":" }\r","marks":[]}]}]},{"type":"block","id":"RsPD-1736085269955","name":"code-line","data":{},"nodes":[{"type":"text","id":"K7OG-1736085269954","leaves":[{"text":"\t\t\t\t\r","marks":[]}]}]},{"type":"block","id":"UJiD-1736085269957","name":"code-line","data":{},"nodes":[{"type":"text","id":"QDoJ-1736085269956","leaves":[{"text":"\t\t\t\t if (g_ButtonPress1)\r","marks":[]}]}]},{"type":"block","id":"5kRB-1736085269959","name":"code-line","data":{},"nodes":[{"type":"text","id":"tm8A-1736085269958","leaves":[{"text":" {\r","marks":[]}]}]},{"type":"block","id":"gp95-1736085269961","name":"code-line","data":{},"nodes":[{"type":"text","id":"PEmH-1736085269960","leaves":[{"text":" PRINTF(\" %s is pressed \\r\\n\", \"GPIO0_29\");\r","marks":[]}]}]},{"type":"block","id":"QUGd-1736085269963","name":"code-line","data":{},"nodes":[{"type":"text","id":"UfFp-1736085269962","leaves":[{"text":" /* Toggle LED. */\r","marks":[]}]}]},{"type":"block","id":"gqW4-1736085269965","name":"code-line","data":{},"nodes":[{"type":"text","id":"fNib-1736085269964","leaves":[{"text":" GPIO_PortToggle(GPIO0, 1u << 25);\r","marks":[]}]}]},{"type":"block","id":"3vOv-1736085269967","name":"code-line","data":{},"nodes":[{"type":"text","id":"cYjn-1736085269966","leaves":[{"text":" /* Reset state of button. */\r","marks":[]}]}]},{"type":"block","id":"CPiC-1736085269969","name":"code-line","data":{},"nodes":[{"type":"text","id":"UwmJ-1736085269968","leaves":[{"text":" g_ButtonPress1 = false;\r","marks":[]}]}]},{"type":"block","id":"6XRY-1736085269971","name":"code-line","data":{},"nodes":[{"type":"text","id":"4UFH-1736085269970","leaves":[{"text":" }\r","marks":[]}]}]},{"type":"block","id":"AjPR-1736085269973","name":"code-line","data":{},"nodes":[{"type":"text","id":"olKW-1736085269972","leaves":[{"text":"\t\t\t\t\r","marks":[]}]}]},{"type":"block","id":"oO3v-1736085269975","name":"code-line","data":{},"nodes":[{"type":"text","id":"gsBc-1736085269974","leaves":[{"text":"\t\t\t\tif (g_ButtonPress2)\r","marks":[]}]}]},{"type":"block","id":"byF4-1736085269977","name":"code-line","data":{},"nodes":[{"type":"text","id":"hEBw-1736085269976","leaves":[{"text":" {\r","marks":[]}]}]},{"type":"block","id":"9UCj-1736085269979","name":"code-line","data":{},"nodes":[{"type":"text","id":"zvjT-1736085269978","leaves":[{"text":" PRINTF(\" %s is pressed \\r\\n\", \"GPIO0_23\");\r","marks":[]}]}]},{"type":"block","id":"AU90-1736085269981","name":"code-line","data":{},"nodes":[{"type":"text","id":"v3AF-1736085269980","leaves":[{"text":" /* Toggle LED. */\r","marks":[]}]}]},{"type":"block","id":"sJnu-1736085269983","name":"code-line","data":{},"nodes":[{"type":"text","id":"wGRZ-1736085269982","leaves":[{"text":" GPIO_PortToggle(GPIO0, 1u << 26);\r","marks":[]}]}]},{"type":"block","id":"494W-1736085269985","name":"code-line","data":{},"nodes":[{"type":"text","id":"upl5-1736085269984","leaves":[{"text":" /* Reset state of button. */\r","marks":[]}]}]},{"type":"block","id":"JG6B-1736085269987","name":"code-line","data":{},"nodes":[{"type":"text","id":"2kFq-1736085269986","leaves":[{"text":" g_ButtonPress2 = false;\r","marks":[]}]}]},{"type":"block","id":"gXTg-1736085269989","name":"code-line","data":{},"nodes":[{"type":"text","id":"OQBz-1736085269988","leaves":[{"text":" }\r","marks":[]}]}]},{"type":"block","id":"aJUI-1736085269991","name":"code-line","data":{},"nodes":[{"type":"text","id":"bqKh-1736085269990","leaves":[{"text":" }\r","marks":[]}]}]},{"type":"block","id":"Ir5q-1736085269993","name":"code-line","data":{},"nodes":[{"type":"text","id":"BtUT-1736085269992","leaves":[{"text":"}\r","marks":[]}]}]},{"type":"block","id":"MCFO-1736085269995","name":"code-line","data":{},"nodes":[{"type":"text","id":"Dw6s-1736085269994","leaves":[{"text":"","marks":[]}]}]}],"state":{}}]">
<p> </p>
<p>5abca5892f45a06eeeed506b9a4b77c6<br />
</p>
<p><strong>引言</strong></p>
<p>欢迎来到本次的技术分享!今天,我们将一起探讨一个基于NXP MCUXpresso SDK开发的GPIO(通用输入输出)控制与中断处理示例程序。这个程序展示了如何通过配置GPIO引脚来实现LED灯的闪烁以及按钮按下时的中断响应。</p>
<p><strong>程序概述</strong></p>
<p>该程序主要实现了以下功能:</p>
<ol yne-block-type="list">
<li>LED灯控制:通过GPIO引脚控制板载LED灯的闪烁。</li>
<li>按钮中断处理:配置GPIO引脚为中断输入,当按钮被按下时,触发中断并响应相应的动作(如切换LED灯状态)。</li>
</ol>
<p><strong>关键组件与配置</strong></p>
<article data-content="[{"type":"block","id":"5CaP-1733974035579","name":"heading","data":{"level":"h5"},"nodes":[{"type":"text","id":"q4jo-1733974035580","leaves":[{"text":"外部中断号","marks":[{"type":"bold"}]}]}],"state":{}},{"type":"block","id":"r6jc-1736082273792","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"Zn17-1736082273790","leaves":[{"text":" 一组GPIO 可以使能2个中断","marks":[{"type":"bold"}]}]}],"state":{}}]">
<p>外部中断号</p>
<p>一组GPIO 可以使能2个中断</p>
</article>
</article>
</div>
<div id="Aqow-1736085835316" yne-bulb-block="heading" yne-bulb-level="4"> </div>
<div yne-bulb-block="heading" yne-bulb-level="4">
<article data-content="[{"type":"block","id":"fvnp-1733974566847","name":"heading","data":{"level":"h5"},"nodes":[{"type":"text","id":"pjo1-1733974566845","leaves":[{"text":"ISF 中断状态标志","marks":[{"type":"bold"},{"type":"fontSize","value":16}]}]}]}]">
<p>ISF 中断状态标志</p>
</article>
</div>
<div yne-bulb-block="heading" yne-bulb-level="4"> </div>
<div yne-bulb-block="heading" yne-bulb-level="4">
<article data-content="[{"type":"block","id":"LuaW-1734067000468","name":"paragraph","data":{},"nodes":[{"type":"text","id":"nlMw-1734067000469","leaves":[{"text":"GPIO_PinGetInterruptFlag:","marks":[{"type":"fontSize","value":14},{"type":"fontFamily","value":"SimHei"},{"type":"bold"}]},{"text":"读单个引脚的中断状态标志","marks":[{"type":"color","value":"#2a2b2e"},{"type":"backgroundColor","value":"rgb(255, 255, 255)"},{"type":"fontSize","value":14},{"type":"fontFamily","value":"SimHei"},{"type":"bold"}]}]}],"state":{}}]">
<p>GPIO_PinGetInterruptFlag:读单个引脚的中断状态标志</p>
<p> </p>
<pre>
<code>
#define GPIO_ICR_ISF_SHIFT (24U)
/*!
* brief Read individual pin's interrupt status flag.
*
* param base GPIO peripheral base pointer. (GPIOA, GPIOB, GPIOC, and so on)
* param pin GPIO specific pin number.
* return The current selected pin's interrupt status flag.
*/
uint8_t GPIO_PinGetInterruptFlag(GPIO_Type *base, uint32_t pin)
{
return (uint8_t)((base->ICR & GPIO_ICR_ISF_MASK) >> GPIO_ICR_ISF_SHIFT);
}</code></pre>
<article data-content="[{"type":"block","id":"Rfv7-1736055668229","name":"heading","data":{"version":1,"level":"h4","style":{"lineHeight":"1.7"}},"nodes":[{"type":"text","id":"MxAo-1736055668227","leaves":[{"text":"程序结构详解","marks":[]}]}],"state":{}},{"type":"block","id":"AbGE-1736084245127","name":"list-item","data":{"version":1,"listId":"Fd2e-1736084245994","listLevel":1,"listType":"ordered","style":{"lineHeight":"1.7"}},"nodes":[{"type":"text","id":"gmQV-1736084245128","leaves":[{"text":"头文件包含:","marks":[]}]}],"state":{"index":1}},{"type":"block","id":"o6fr-1736084245987","name":"list-item","data":{"version":1,"listId":"tNMT-1736084245995","listLevel":2,"listType":"unordered","style":{"lineHeight":"1.7"}},"nodes":[{"type":"text","id":"KGHi-1736084245986","leaves":[{"text":"包含了必要的头文件,如","marks":[]},{"text":"fsl_debug_console.h","marks":[{"type":"backgroundColor","value":"rgba(27, 31, 35, 0.05)"},{"type":"fontSize","value":12},{"type":"fontFamily","value":"Courier New"}]},{"text":"用于调试输出,","marks":[]},{"text":"fsl_gpio.h","marks":[{"type":"backgroundColor","value":"rgba(27, 31, 35, 0.05)"},{"type":"fontSize","value":12},{"type":"fontFamily","value":"Courier New"}]},{"text":"用于GPIO控制等。","marks":[]}]}],"state":{}}]">
<p>程序结构详解</p>
<ol yne-block-type="list">
<li>头文件包含:</li>
</ol>
<ul yne-block-type="list">
<li>包含了必要的头文件,如fsl_debug_console.h用于调试输出,fsl_gpio.h用于GPIO控制等。</li>
</ul>
<pre>
<code>#include "fsl_debug_console.h"
#if defined(FSL_FEATURE_SOC_PORT_COUNT) && (FSL_FEATURE_SOC_PORT_COUNT)
#include "fsl_port.h"
#endif
#include "fsl_gpio.h"
#include "fsl_common.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "board.h"</code></pre>
<p> </p>
<p> </p>
<p> </p>
<p>2.宏定义与变量声明:</p>
</article>
</article>
</div>
<div yne-bulb-block="heading" yne-bulb-level="4">
<article data-content="[{"type":"block","id":"oAmg-1736084245989","name":"list-item","data":{"version":1,"listId":"Fd2e-1736084245994","listLevel":1,"listType":"ordered","style":{"lineHeight":"1.7"}},"nodes":[{"type":"text","id":"jUec-1736084245988","leaves":[{"text":"宏定义与变量声明:","marks":[]}]}],"state":{}}]">
<article data-content="[{"type":"block","id":"qNxs-1736084245991","name":"list-item","data":{"version":1,"listId":"UsuB-1736084245996","listLevel":2,"listType":"unordered","style":{"lineHeight":"1.7"}},"nodes":[{"type":"text","id":"eqQr-1736084245990","leaves":[{"text":"定义了LED和按钮对应的GPIO引脚。","marks":[]}]}],"state":{}},{"type":"block","id":"Wa0x-1736084245993","name":"list-item","data":{"version":1,"listId":"UsuB-1736084245996","listLevel":2,"listType":"unordered","style":{"lineHeight":"1.7"}},"nodes":[{"type":"text","id":"ZrXF-1736084245992","leaves":[{"text":"声明了用于标记按钮按下状态的变量。","marks":[]}]}],"state":{}}]">
<article data-content="[{"type":"block","id":"BEsd-1736084879944","name":"paragraph","data":{},"nodes":[{"type":"text","id":"hkfK-1736084879945","leaves":[{"text":"3.中断服务函数实现:","marks":[{"type":"color","value":"#05073b"},{"type":"backgroundColor","value":"rgb(253, 253, 254)"},{"type":"fontSize","value":15},{"type":"fontFamily","value":"Arial"}]}]}],"state":{}}]">
<article data-content="[{"type":"block","id":"qNxs-1736084245991","name":"list-item","data":{"version":1,"listId":"UsuB-1736084245996","listLevel":2,"listType":"unordered","style":{"lineHeight":"1.7"}},"nodes":[{"type":"text","id":"eqQr-1736084245990","leaves":[{"text":"定义了LED和按钮对应的GPIO引脚。","marks":[]}]}],"state":{}},{"type":"block","id":"Wa0x-1736084245993","name":"list-item","data":{"version":1,"listId":"UsuB-1736084245996","listLevel":2,"listType":"unordered","style":{"lineHeight":"1.7"}},"nodes":[{"type":"text","id":"ZrXF-1736084245992","leaves":[{"text":"声明了用于标记按钮按下状态的变量。","marks":[]}]}],"state":{}}]">
<p> </p>
<ol>
<li>定义了LED和按钮对应的GPIO引脚。</li>
<li>声明了用于标记按钮按下状态的变量。</li>
</ol>
</article>
<p>3.中断服务函数实现:</p>
<pre>
<code>*!
* <a href="home.php?mod=space&uid=159083" target="_blank">@brief </a> Interrupt service fuction of switch.
*
* This function toggles the LED
*/
void BOARD_SW_IRQ_HANDLER(void)
{
if(GPIO_PinGetInterruptFlag(GPIO0,6))
{
#if (defined(FSL_FEATURE_PORT_HAS_NO_INTERRUPT) && FSL_FEATURE_PORT_HAS_NO_INTERRUPT) || \
(!defined(FSL_FEATURE_SOC_PORT_COUNT))
/* Clear external interrupt flag. */
GPIO_GpioClearInterruptFlags(BOARD_SW_GPIO, 1U << BOARD_SW_GPIO_PIN);
#else
/* Clear external interrupt flag. */
GPIO_PortClearInterruptFlags(BOARD_SW_GPIO, 1U << BOARD_SW_GPIO_PIN);
#endif
/* Change state of button. */
g_ButtonPress = true;
}
if(GPIO_PinGetInterruptFlag(GPIO0,29))
{
#if (defined(FSL_FEATURE_PORT_HAS_NO_INTERRUPT) && FSL_FEATURE_PORT_HAS_NO_INTERRUPT) || \
(!defined(FSL_FEATURE_SOC_PORT_COUNT))
/* Clear external interrupt flag. */
GPIO_GpioClearInterruptFlags(GPIO0, 1U << 29);
#else
/* Clear external interrupt flag. */
GPIO_PortClearInterruptFlags(BOARD_SW_GPIO, 1U << BOARD_SW_GPIO_PIN);
#endif
/* Change state of button. */
g_ButtonPress1 = true;
}
if(GPIO_PinGetInterruptFlag(GPIO1,23))
{
#if (defined(FSL_FEATURE_PORT_HAS_NO_INTERRUPT) && FSL_FEATURE_PORT_HAS_NO_INTERRUPT) || \
(!defined(FSL_FEATURE_SOC_PORT_COUNT))
/* Clear external interrupt flag. */
GPIO_GpioClearInterruptFlags(GPIO1, 1U << 23);
#else
/* Clear external interrupt flag. */
GPIO_PortClearInterruptFlags(BOARD_SW_GPIO, 1U << BOARD_SW_GPIO_PIN);
#endif
/* Change state of button. */
g_ButtonPress2 = true;
}
SDK_ISR_EXIT_BARRIER;
}
void GPIO10_IRQHandler(void)
{
if(GPIO_PinGetInterruptFlag(GPIO1,23))
{
/* Clear external interrupt flag. */
GPIO_GpioClearInterruptFlags(GPIO1, 1U << 23);
/* Change state of button. */
g_ButtonPress2 = true;
}
SDK_ISR_EXIT_BARRIER;
}</code></pre>
<p> </p>
<p> </p>
<p> </p>
<article data-content="[{"type":"block","id":"Y1Ha-1736055668504","name":"paragraph","data":{},"nodes":[{"type":"text","id":"GMex-1736055668502","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"eARf-1736085263467","name":"paragraph","data":{},"nodes":[{"type":"text","id":"yEiQ-1736085263465","leaves":[{"text":"4.主函数实现:","marks":[{"type":"color","value":"#05073b"},{"type":"backgroundColor","value":"rgb(253, 253, 254)"},{"type":"fontSize","value":15},{"type":"fontFamily","value":"Arial"}]}]}],"state":{}}]">
<p>4.主函数实现:</p>
</article>
<pre>
<code>/*!
* @brief Main function
*/
int main(void)
{
/* Define the init structure for the output LED pin*/
gpio_pin_config_t led_config = {
kGPIO_DigitalOutput,
0,
};
/* Define the init structure for the input switch pin */
gpio_pin_config_t sw_config = {
kGPIO_DigitalInput,
0,
};
/* Board pin, clock, debug console init */
/* attach FRO 12M to FLEXCOMM4 (debug console) */
CLOCK_SetClkDiv(kCLOCK_DivFlexcom4Clk, 1u);
CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
/* enable clock for GPIO*/
CLOCK_EnableClock(kCLOCK_Gpio0);
CLOCK_EnableClock(kCLOCK_Gpio1);
BOARD_InitPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
/* Print a note to terminal. */
PRINTF("\r\n GPIO Driver example\r\n");
PRINTF("\r\n The LED is blinking.\r\n");
GPIO_SetPinInterruptConfig(BOARD_SW_GPIO, BOARD_SW_GPIO_PIN, kGPIO_InterruptFallingEdge);
GPIO_SetPinInterruptConfig(GPIO0, 29, kGPIO_InterruptFallingEdge);
GPIO_SetPinInterruptChannel(GPIO0, 29,kGPIO_InterruptOutput0);
GPIO_SetPinInterruptConfig(GPIO1, 23, kGPIO_InterruptFallingEdge);
GPIO_SetPinInterruptChannel(GPIO1, 23,kGPIO_InterruptOutput0);
EnableIRQ(BOARD_SW_IRQ);
EnableIRQ(GPIO10_IRQn);
GPIO_PinInit(BOARD_SW_GPIO, BOARD_SW_GPIO_PIN, &sw_config);
GPIO_PinInit(GPIO0, 29, &sw_config);
GPIO_PinInit(GPIO1, 23, &sw_config);
GPIO_PinInit(BOARD_LED_GPIO, BOARD_LED_GPIO_PIN, &led_config);
GPIO_PinInit(GPIO0, 25, &led_config);
GPIO_PinInit(GPIO0, 26, &led_config);
while (1)
{
// delay();
// GPIO_PortToggle(BOARD_LED_GPIO, 1u << BOARD_LED_GPIO_PIN);
// GPIO_PortToggle(GPIO0, 1u << 25);
// GPIO_PortToggle(GPIO0, 1u << 26);
if (g_ButtonPress)
{
PRINTF(" %s is pressed \r\n", BOARD_SW_NAME);
/* Toggle LED. */
GPIO_PortToggle(BOARD_LED_GPIO, 1U << BOARD_LED_GPIO_PIN);
/* Reset state of button. */
g_ButtonPress = false;
}
if (g_ButtonPress1)
{
PRINTF(" %s is pressed \r\n", "GPIO0_29");
/* Toggle LED. */
GPIO_PortToggle(GPIO0, 1u << 25);
/* Reset state of button. */
g_ButtonPress1 = false;
}
if (g_ButtonPress2)
{
PRINTF(" %s is pressed \r\n", "GPIO0_23");
/* Toggle LED. */
GPIO_PortToggle(GPIO0, 1u << 26);
/* Reset state of button. */
g_ButtonPress2 = false;
}
}
}
</code></pre>
</article>
<p>附:源文件</p>
<div></div>
</article>
</article>
</div>
<p>不同的IDE其实用的解释器都是一样的,只不过写法不同,这个是需要适应的地方</p>
页:
[1]