鸿蒙开发板Hi3861_点亮LED开关实验——基于code-2.0-CANARY金丝雀windows下编译
鸿蒙开发板Hi3861_点亮LED开关实验
hellow world的程序
基于code-2.0-CANARY金丝雀windows下编译方法
https://www.cnblogs.com/txwtech/p/15041927.html
1.vscode 创建一个led_demo2文件夹
2. led_demo2文件夹下面在创建两个文件led2.c和BUILD.gn
led2.c内容:
#include <stdio.h> #include "ohos_init.h" #include "cmsis_os2.h" #include "iot_gpio.h" //#include "wifiiot_gpio_ex.h" //#define //static void LedTask(void *arg) static void LedTask(void *arg) { (void) arg; //GpioInit(9); IoTGpioInit(9); //IoSetFunc(9,IOT_GPIO_DIR_OUT); IoTGpioSetDir(9,IOT_GPIO_DIR_OUT); // osDelay(50); while(1) { IoTGpioSetOutputVal(9,IOT_GPIO_VALUE0); osDelay(100); printf("pin9 OFF\n"); //usleep(10000000); IoTGpioSetOutputVal(9,IOT_GPIO_VALUE1); osDelay(100); printf("pin9 ON\n"); // usleep(10000000); } } static void LedEntry(void) { osThreadAttr_t attr={0}; attr.name="LedTask"; attr.stack_size=4096; attr.priority=osPriorityNormal; if(osThreadNew(LedTask,NULL,&attr)==NULL) { printf("[LedEntry] create LedTask failed!\n"); } } SYS_RUN(LedTask);
BUILD.gn
static_library("led_demo2") { sources = [ "led2.c"] include_dirs = [ "//third_party/cmsis/CMSIS/RTOS2/Include", "//utils/native/lite/include", "//kernel/liteos_m/components/cmsis/2.0", "//base/iot_hardware/peripheral/interfaces/kits", ] }
app的目录的BUILD.gn
# Copyright (c) 2020 Huawei Device Co., Ltd. # 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. import("//build/lite/config/component/lite_component.gni") lite_component("app") { features = [ "led_demo2", ] }
编译成功
上传成功
串口打开,查看输出
LED变化与串口打印内容
欢迎讨论,相互学习。
cdtxw@foxmail.com
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
2019-08-13 捷达换电瓶多少钱?