在线时间589 小时
UID3469866
注册时间2018-4-19
NXP金币3128
TA的每日心情 | 慵懒 2024-2-8 09:39 |
---|
签到天数: 217 天 [LV.7]常住居民III
版主
- 积分
- 7701
- 最后登录
- 2024-4-30
|
本帖最后由 az158 于 2024-1-19 20:36 编辑
今天写一个按键输入中断代码,对MCX的gpio部分进行一个初步的了解。
首先是配置io模式,现在并不能使用MCUXpresso Config Tools进行配置,只能手动编写了。
- const port_pin_config_t port0_6_pinC14_config = {/* Internal pull-up resistor is enabled */
- kPORT_PullUp,
- /* Low internal pull resistor value is selected. */
- kPORT_LowPullResistor,
- /* Fast slew rate is configured */
- kPORT_FastSlewRate,
- /* Passive input filter is disabled */
- kPORT_PassiveFilterDisable,
- /* Open drain output is disabled */
- kPORT_OpenDrainDisable,
- /* Low drive strength is configured */
- kPORT_LowDriveStrength,
- /* Pin is configured as PIO0_6 */
- kPORT_MuxAlt0,
- /* Digital input enabled */
- kPORT_InputBufferEnable,
- /* Digital input is not inverted */
- kPORT_InputNormal,
- /* Pin Control Register fields [15:0] are not locked */
- kPORT_UnlockRegister};
- /* PORT0_6 (pin C14) is configured as PIO0_6 */
- PORT_SetPinConfig(PORT0, 6U, &port0_6_pinC14_config);
复制代码 基本与LED的一样,就是配置了上拉。
接下来就是编写主程序代码。
- void BOARD_SW3_IRQ_HANDLER(void)
- {
- GPIO_GpioClearInterruptFlags(BOARD_SW3_GPIO, 1U << BOARD_SW3_GPIO_PIN);
- GPIO_PortToggle(BOARD_LED_GPIO, 1u << BOARD_LED_GPIO_PIN);
- SDK_ISR_EXIT_BARRIER;
- }
- int main(void)
- {
- gpio_pin_config_t sw_config = {
- kGPIO_DigitalInput,
- 0,
- };
- CLOCK_EnableClock(kCLOCK_Gpio0);
- CLOCK_EnableClock(kCLOCK_Gpio3);
-
- BOARD_InitPins();
- BOARD_PowerMode_OD();
- BOARD_InitBootClocks();
-
- LED_RED_INIT(LOGIC_LED_OFF);
-
- GPIO_SetPinInterruptConfig(BOARD_SW3_GPIO, BOARD_SW3_GPIO_PIN, kGPIO_InterruptFallingEdge);
- EnableIRQ(BOARD_SW3_IRQ);
- GPIO_PinInit(BOARD_SW3_GPIO, BOARD_SW3_GPIO_PIN, &sw_config);
-
- while(1){}
- }
复制代码 代码很简单,就是配置了下降沿中断,当检测到按键按下,就反转LED灯电平。
下载看看效果
收工
|
|