鸿蒙开发板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变化与串口打印内容

 

posted @   txwtech  阅读(651)  评论(0编辑  收藏  举报
编辑推荐:
· 基于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 捷达换电瓶多少钱?
点击右上角即可分享
微信分享提示