在线时间888 小时
UID3067179
注册时间2014-10-23
NXP金币2309
TA的每日心情 | 开心 5 小时前 |
---|
签到天数: 1481 天 连续签到: 1 天 [LV.10]以坛为家III
版主
  
- 积分
- 8652
- 最后登录
- 2025-7-27
|
使用官网的SDK创建项目工程,并点亮开发板上的RGB全彩LED灯。
一、硬件部分
开发板上RGB灯连接到芯片的P3_2~P3_4引脚
二、程序部分
2.1、led.c
- #include "main.h"
- /* Define the init structure for the output LED pin*/
- gpio_pin_config_t led_config = {
- kGPIO_DigitalOutput,
- 0,
- };
- void init_led(void)
- {
-
-
- CLOCK_EnableClock(kCLOCK_Port3);
-
- //LED_GREEN
- const port_pin_config_t port3_2_pinF14_config = {/* Internal pull-up/down resistor is disabled */
- kPORT_PullDisable,
- /* 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 PIO3_4 */
- 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};
- /* PORT3_2 (pin F14) is configured as PIO3_2 */
- PORT_SetPinConfig(PORT3, 2U, &port3_2_pinF14_config);
-
- //LED_BLUE
- const port_pin_config_t port3_3_pinF14_config = {/* Internal pull-up/down resistor is disabled */
- kPORT_PullDisable,
- /* 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 PIO3_4 */
- 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};
- /* PORT3_3 (pin F14) is configured as PIO3_3 */
- PORT_SetPinConfig(PORT3, 3U, &port3_3_pinF14_config);
-
- //LED_RED
- const port_pin_config_t port3_4_pinF14_config = {/* Internal pull-up/down resistor is disabled */
- kPORT_PullDisable,
- /* 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 PIO3_4 */
- 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};
- /* PORT3_4 (pin F14) is configured as PIO3_4 */
- PORT_SetPinConfig(PORT3, 4U, &port3_4_pinF14_config);
-
- GPIO_PinInit(LED_RED_GPIO, LED_RED_GPIO_PIN, &led_config);
- GPIO_PinInit(LED_GREEN_GPIO, LED_GREEN_GPIO_PIN, &led_config);
- GPIO_PinInit(LED_BLUE_GPIO, LED_BLUE_GPIO_PIN, &led_config);
-
- led_red_off();
- led_green_off();
- led_blue_off();
-
- }
复制代码
2.2、led.h
- #ifndef __LED_H
- #define __LED_H
- #define LED_RED_GPIO GPIO3
- #define LED_RED_GPIO_PIN 4U
- #define LED_BLUE_GPIO GPIO3
- #define LED_BLUE_GPIO_PIN 3U
- #define LED_GREEN_GPIO GPIO3
- #define LED_GREEN_GPIO_PIN 2U
- #define led_red_on() GPIO_PortClear(LED_RED_GPIO, 1u << LED_RED_GPIO_PIN)
- #define led_red_off() GPIO_PortSet(LED_RED_GPIO, 1u << LED_RED_GPIO_PIN)
- #define led_red_tog() GPIO_PortToggle(LED_RED_GPIO, 1u << LED_RED_GPIO_PIN)
- #define led_green_on() GPIO_PortClear(LED_GREEN_GPIO, 1u << LED_GREEN_GPIO_PIN)
- #define led_green_off() GPIO_PortSet(LED_GREEN_GPIO, 1u << LED_GREEN_GPIO_PIN)
- #define led_green_tog() GPIO_PortToggle(LED_GREEN_GPIO, 1u << LED_GREEN_GPIO_PIN)
- #define led_blue_on() GPIO_PortClear(LED_BLUE_GPIO, 1u << LED_BLUE_GPIO_PIN)
- #define led_blue_off() GPIO_PortSet(LED_BLUE_GPIO, 1u << LED_BLUE_GPIO_PIN)
- #define led_blue_tog() GPIO_PortToggle(LED_BLUE_GPIO, 1u << LED_BLUE_GPIO_PIN)
- void init_led(void);
- #endif
复制代码
2.3、main.c
- #include "main.h"
- /*******************************************************************************
- * Definitions
- ******************************************************************************/
- #define BOARD_LED_GPIO BOARD_LED_RED_GPIO
- #define BOARD_LED_GPIO_PIN BOARD_LED_RED_GPIO_PIN
- /*******************************************************************************
- * Prototypes
- ******************************************************************************/
- /*!
- * @brief delay a while.
- */
- void delay(void);
- /*******************************************************************************
- * Variables
- ******************************************************************************/
- /*******************************************************************************
- * Code
- ******************************************************************************/
- void delay(void)
- {
- volatile uint32_t i = 0;
- for (i = 0; i < 0x3fffff; ++i)
- {
- __asm("NOP"); /* delay */
- }
- }
- /*!
- * @brief Main function
- */
- int main(void)
- {
- /* 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_Gpio3);
- BOARD_InitPins();
- BOARD_PowerMode_OD();
- BOARD_InitBootClocks();
- BOARD_InitDebugConsole();
-
- init_led();
- /* Print a note to terminal. */
- PRINTF("\r\n GPIO Driver example\r\n");
- PRINTF("\r\n The LED is blinking.\r\n");
- while (1)
- {
-
- led_red_on();
- led_green_off();
- led_blue_off();
- delay();
- led_red_off();
- led_green_on();
- led_blue_off();
- delay();
- led_red_off();
- led_green_off();
- led_blue_on();
- delay();
- }
- }
复制代码
2.4、项目文件
mcx_n947_prj.rar
(5.97 MB, 下载次数: 6)
|
|