此笔记由个人整理
华为IOT LiteOS开发实战营
第三天
一、传感器
- 温湿度传感器:SHT30
- 光照强度传感器:BH1750
- LED植物灯
- 排风扇电机
二、具体步骤
- 创建工程,选择hello_world_demo
- 包含扩展板的头文件
#include <E53_IA1.h>
- 创建传感器采集任务
static int app_sensor_collect_entry()
{
}
- 调用扩展板驱动程序
void Init_E53_IA1(void);
void E53_IA1_Read_Data(void);
- 打印数据
printf("Lux:%d",(int)E53_IA1_Data.Lux);
printf("Humidity:%d",(int)E53_IA1_Data.Humidity);
printf("Temperature:%d",(int)E53_IA1_Data.Temperature);
- 在user_demo.mk中添加文件路径
#example for hello world
ifeq ($(CONFIG_USER_DEMO), "hello_world_demo")
user_demo_src = ${wildcard $(TARGET_DIR)/Demos/hello_world_demo/*.c}
user_demo_inc = -I $(TARGET_DIR)/Demos/hello_world_demo
user_hardware_src = ${wildcard $(TARGET_DIR)/Hardware/E53_IA1/*.c}
user_hardware_inc = -I ${wildcard $(TARGET_DIR)/Hardware/E53_IA1}
user_demo_defs = -D CONFIG_HELLO_WORLD_ENABLE=1
endif
- 移植lcd驱动,添加头文件
#include "lcd.h"
- 调用显示数据
LCD_ShowString(10, 140, 200, 16, 16, "Temperature:");
LCD_ShowNum(140, 140, (int)E53_IA1_Data.Temperature, 5, 16);
LCD_ShowString(10, 170, 200, 16, 16, "Humidity:");
LCD_ShowNum(140, 170, (int)E53_IA1_Data.Humidity, 5, 16);
LCD_ShowString(10, 200, 200, 16, 16, "Luminance:");
LCD_ShowNum(140, 200, (int)E53_IA1_Data.Lux, 5, 16);
- 在主函数中调用
int standard_app_demo_main()
{
osal_task_create("helloworld",app_hello_world_entry,NULL,0x400,NULL,2);
osal_task_create("sensor",app_sensor_entry,NULL,0x400,NULL,2);
return 0;
}
- 传感器采集任务
static int app_sensor_entry()
{
Init_E53_IA1();
while(1)
{
E53_IA1_Read_Data();
printf("Lux:%d",(int)E53_IA1_Data.Lux);
printf("Humidity:%d",(int)E53_IA1_Data.Humidity);
printf("Temperature:%d",(int)E53_IA1_Data.Temperature);
LCD_ShowString(10, 140, 200, 16, 16, "Temperature:");
LCD_ShowNum(140, 140, (int)E53_IA1_Data.Temperature, 5, 16);
LCD_ShowString(10, 170, 200, 16, 16, "Humidity:");
LCD_ShowNum(140, 170, (int)E53_IA1_Data.Humidity, 5, 16);
LCD_ShowString(10, 200, 200, 16, 16, "Luminance:");
LCD_ShowNum(140, 200, (int)E53_IA1_Data.Lux, 5, 16);
osal_task_sleep(2*1000);
}
}
- 结果