鸿蒙开发板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 @ 2021-08-13 22:46  txwtech  阅读(590)  评论(0编辑  收藏  举报