TA的每日心情 | 奋斗 2023-5-10 20:09 |
---|
签到天数: 1742 天 连续签到: 1 天 [LV.Master]伴坛终老
|
在OKdo E1开发板上,配置了3个LED灯,其原理图如图1所示。 图1 LED灯原理图
由此可知LED灯与MCU的连接关系为: LEDR---PIO1_4 LEDB---PIO1_6 LEDG---PIO1_7
为便于相关引脚的设置,故编写了一个LED灯的配置函数: - void LEDS_InitPins(void)
- {
- /* Enables the clock for the I/O controller.: Enable Clock. */
- CLOCK_EnableClock(kCLOCK_Iocon);
- /* Enables the clock for the GPIO1 module */
- CLOCK_EnableClock(kCLOCK_Gpio1);
- gpio_pin_config_t LED_BULE_config = {
- .pinDirection = kGPIO_DigitalOutput,
- .outputLogic = 0U
- };
- /* Initialize GPIO functionality on pin PIO1_4 (pin 1) */
- GPIO_PinInit(GPIO, 1U, 4U, 1u <<4U);
- GPIO_PinInit(GPIO, 1U, 6U, 1u <<6U);
- GPIO_PinInit(GPIO, 1U, 7U, 1u <<7U);
- const uint32_t port0_pin10_config = (/* Pin is configured as SWO */
- IOCON_PIO_FUNC6 |
- /* No addition pin function */
- IOCON_PIO_MODE_INACT |
- /* Standard mode, output slew rate control is enabled */
- IOCON_PIO_SLEW_STANDARD |
- /* Input function is not inverted */
- IOCON_PIO_INV_DI |
- /* Enables digital function */
- IOCON_PIO_DIGITAL_EN |
- /* Open drain is disabled */
- IOCON_PIO_OPENDRAIN_DI |
- /* Analog switch is disabled */
- IOCON_PIO_ASW_DIS_DI);
- /* PORT0 PIN10 (coords: 21) is configured as SWO */
- IOCON_PinMuxSet(IOCON, 0U, 10U, port0_pin10_config);
- const uint32_t LEDS = (/* Pin is configured as PIO1_4 */
- IOCON_PIO_FUNC0 |
- /* Selects pull-up function */
- IOCON_PIO_MODE_PULLUP |
- /* Standard mode, output slew rate control is enabled */
- IOCON_PIO_SLEW_STANDARD |
- /* Input function is not inverted */
- IOCON_PIO_INV_DI |
- /* Enables digital function */
- IOCON_PIO_DIGITAL_EN |
- /* Open drain is disabled */
- IOCON_PIO_OPENDRAIN_DI);
- /* PORT1 PIN4 (coords: 1) is configured as PIO1_4 */
- IOCON_PinMuxSet(IOCON, 1U, 4U, LEDS);
- IOCON_PinMuxSet(IOCON, 1U, 6U, LEDS);
- IOCON_PinMuxSet(IOCON, 1U, 7U, LEDS);
- }
复制代码
控制LED灯依次点亮的主程序如下: - int main(void)
- {
- /* Init output LED GPIO. */
- GPIO_PortInit(GPIO, 1U);
- /* set BOD VBAT level to 1.65V */
- POWER_SetBodVbatLevel(kPOWER_BodVbatLevel1650mv, kPOWER_BodHystLevel50mv, false);
- LEDS_InitPins();
- SystemCoreClockUpdate();
- /* Set systick reload value to generate 1ms interrupt */
- if (SysTick_Config(SystemCoreClock / 1000U))
- {
- while (1)
- {
- }
- }
- while (1)
- {
- GPIO_PortClear(GPIO, 1U, 1u <<4U);//RED
- SysTick_DelayTicks(1000U);
- GPIO_PortSet(GPIO, 1U, 1u <<4U);
- SysTick_DelayTicks(1000U);
- GPIO_PortClear(GPIO, 1U, 1u <<6U);//BLUE
- SysTick_DelayTicks(1000U);
- GPIO_PortSet(GPIO, 1U, 1u <<6U);
- SysTick_DelayTicks(1000U);
- GPIO_PortClear(GPIO, 1U, 1u <<7U);//GREEN
- SysTick_DelayTicks(1000U);
- GPIO_PortSet(GPIO, 1U, 1u <<7U);
- SysTick_DelayTicks(1000U);
- }
- }
复制代码
编译下载后,其运行效果如图2所示。 图2 LED灯控制效果
目标代码:
|
|