更多内容请访问:与华为官方共建的鸿蒙技术社区https://harmonyos.51cto.com/#zz参考官方教程:Hi3861开发板第一个示例程序一、目录结构规划在app下新增业务hello_world,其中hello_world.c为业务代码,BUILD.gn为编译脚本,具体规划目录结构如下:.└──applications└──sample└──wifi-iot└──app│──hello_world││──hello_world.c│└──BUILD.gn└──BUILD.gn2.hello_world.c源码/*业务代码架构1、任务处理函数HelloWorld_Task实现业务初始化,实现while(1)中的循环处理业务2、任务入口函数HelloWorld_Entry:实现任务的初始化,并注册任务处理函数3、调用鸿蒙SYS_RUN(HelloWorld_Entry);实现业务注册*/#include#include#include"ohos_init.h"#include"cmsis_os2.h"/*1。任务函数:hello_worldtask*/staticvoid*HelloWorld_Task(constchar*arg){(void)arg;printf("[HelloWorld]HelloWorld_Task()\n");while(1){//logiccodefortaskusleep(500000);//我们延迟}returnNULL;}/*2。任务入口函数:实现任务初始化*/staticvoidHelloWorld_Entry(void){osThreadAttr_tattr={0};printf([HelloWorld]HelloWorld_Entry()\n");attr.name="HelloWorld_Task";attr.attr_bits=0U;attr.cb_mem=空;attr.cb_size=0U;attr.stack_mem=NULL;attr.stack_size=1024;attr.priority=osPriorityNormal;if(osThreadNew((osThreadFunc_t)HelloWorld_Task,NULL,&attr)==NULL){printf("[HelloWorld]FaliedtocreateLedTask!\n");}}SYS_RUN(HelloWorld_Entry);3.业务代码编译脚本BUILD.gn路径:code\applications\sample\wifi-iot\app\hello_world\BUILD.gnstatic_library("hello_world_app"){sources=["hello_world.c"]include_dirs=["//utils/native/lite/include","//kernel/liteos_m/components/cmsis/2.0","//base/iot_hardware/interfaces/kits/wifiiot_lite",]}4。模块编译脚本BUILD.gn路径:code\applications\sample\wifi-iot\app\BUILD.gnimport("//build/lite/config/component/lite_component.gni")lite_component("app"){features=["startup","hello_world:hello_world_app",]}5、执行结果:6、总结,注意业务代码的项目路径,必须在code\applications\sample\wifi-iot\app\目录下,根据为业务创建新文件夹。一个业务可以理解为一个任务或者一个线程。比如OLED液晶显示器可以作为一个单独的业务,行车灯可以作为一个单独的业务。在后续的代码中,会继续在hello_world业务中加入简单的功能,比如LED跑灯、按键中断灯,复杂的功能(比如WIFI、OLED显示)会重启一个新的业务。了解更多请访问:与华为官方共建鸿蒙科技社区https://harmonyos.51cto.com/#zz