简介
在上一篇文章中我们已经对环境进行了搭建,并且构建了固件。那么本章节我们将对应原理图来Toggle LED灯。
根据原理图得知,此块开发板上搭载的是一个RGBLED灯珠,其中使用LED0, LED1和LED2分别控制三颗LED的点亮。
根据代码的宏定义得知, LED1 是 红色, LED1是绿色,LED2是蓝色。
/****************************************************************************** * * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by * Analog Devices, Inc.), * Copyright (C) 2023-2024 Analog Devices, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ******************************************************************************/ /** * @file main.c * @brief Hello World! * @details This example uses the UART to print to a terminal and flashes an LED. */ /***** Includes *****/ #include <stdio.h> #include <stdint.h> #include "mxc_device.h" #include "led.h" #include "board.h" #include "mxc_delay.h" /***** Definitions *****/ /***** Globals *****/ /***** Functions *****/ // ***************************************************************************** int main(void) { int count = 0; printf("Hello World!\n"); while (1) { LED_On(LED1); MXC_Delay(500000); LED_Off(LED1); MXC_Delay(500000); printf("count : %d\n", count++); } }
原本的代码中之后LED1的点亮,我们把其他的也加上去
int main(void) { int count = 0; printf("Hello World!\n"); while (1) { LED_On(LED1); MXC_Delay(500000); LED_Off(LED1); MXC_Delay(500000); LED_On(LED2); MXC_Delay(500000); LED_Off(LED2); MXC_Delay(500000); LED_On(LED3); MXC_Delay(500000); LED_Off(LED3); MXC_Delay(500000); printf("count : %d\n", count++); } }
然后使用Ctrl+ shif + b 打开构建选项,选择构建。
构建完成。
然后进行烧录。
烧录成功,接下来我们来看下效果,