当前位置: 首页 > news >正文

金融网站织梦模板免费下载做企业竞争模拟的网站

金融网站织梦模板免费下载,做企业竞争模拟的网站,用ps做商城网站好做吗,重庆网站建设坤思特这篇文章是讲解的pwm控制三色灯的部分,这部分也是后续全彩智能灯的基础。 硬件原理如下 IO管脚定义在hi-12f_v1.1.2-规格书-20211202.pdf文档中 GPIO API API名称 说明 unsigned int IoTGpioInit(unsigned int id); GPIO模块初始化 hi_u32 hi_io_set_func(hi_i…

这篇文章是讲解的pwm控制三色灯的部分,这部分也是后续全彩智能灯的基础。

硬件原理如下

IO管脚定义在hi-12f_v1.1.2-规格书-20211202.pdf文档中

GPIO API

API名称

说明

unsigned int IoTGpioInit(unsigned int id);

GPIO模块初始化

hi_u32 hi_io_set_func(hi_io_name id, hi_u8 val);

配置某个IO的复用功能

unsigned int IoTPwmInit(unsigned int port);

初始化一个PWM设备

unsigned int IoTPwmStart(unsigned int port, unsigned short duty, unsigned int freq);

根据给定的输出频率和占空比从指定端口启动PWM信号输出。

unsigned int IoTPwmStop(unsigned int port);

停止来自指定端口的PWM信号输出。

在官方给的代码中IoTPwmStart占空比参数范围为1-99,也就是不能达到全灭和全亮的程度。所以对源码进行修改。

修改D:\DevEcoProjects\test\src\device\hisilicon\hispark_pegasus\hi3861_adapter\hals\iot_hardware\wifiiot_lite\hal_iot_pwm.c

unsigned int IoTPwmStart(unsigned int port, unsigned short duty, unsigned int freq)
{unsigned short hiDuty;unsigned short hiFreq;if ((freq == 0) || (duty > DUTY_MAX)) {return IOT_FAILURE;}if ((CLK_160M / freq) > SHORT_MAX) {return IOT_FAILURE;}hiFreq = (unsigned short)(CLK_160M / freq);hiDuty = (duty * hiFreq) / DUTY_MAX;return hi_pwm_start((hi_pwm_port)port, hiDuty, hiFreq);
}

使其支持0和100.

修改D:\DevEcoProjects\test\src\device\hisilicon\hispark_pegasus\sdk_liteos\platform\drivers\pwm\hi_pwm.c

hi_u32 hi_pwm_start(hi_pwm_port port, hi_u16 duty, hi_u16 freq)
{hi_u32 ret;if ((pwm_check_port(port) != HI_ERR_SUCCESS) || (freq == 0)|| (duty > freq)) {return HI_ERR_PWM_INVALID_PARAMETER;}if (pwm_is_init(port) == HI_FALSE) {return HI_ERR_PWM_NO_INIT;}ret = pwm_lock(port);if (ret != HI_ERR_SUCCESS) {return ret;}pwm_set_enable(port, HI_TRUE);pwm_set_freq(port, freq);pwm_set_duty(port, duty);pwm_take_effect(port);return pwm_unlock(port);
}

同样是使其支持0和100.

以上就是对源码的修改。下面是测试代码部分。

修改D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\BUILD.gn文件

# Copyright (c) 2023 Beijing HuaQing YuanJian Education Technology 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("demo") {features = [#"base_00_helloworld:base_helloworld_example",#"base_01_led:base_led_example",#"base_02_loopkey:base_loopkey_example",#"base_03_irqkey:base_irqkey_example",#"base_04_adc:base_adc_example","base_05_pwm:base_pwm_example",]
}

创建D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\base_05_pwm文件夹

文件夹中创建D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\base_05_pwm\base_pwm_example.c文件D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\base_05_pwm\BUILD.gn文件

# Copyright (c) 2023 Beijing HuaQing YuanJian Education Technology 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. static_library("base_pwm_example") {sources = ["base_pwm_example.c",]include_dirs = ["//utils/native/lite/include","//kernel/liteos_m/kal/cmsis","//base/iot_hardware/peripheral/interfaces/kits","//vendor/hqyj/fs_hi3861/common/bsp/include"]
}
/** Copyright (C) 2023 HiHope Open Source Organization .* 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.*/#include <stdio.h>
#include <unistd.h>#include "cmsis_os2.h"
#include "hi_io.h"
#include "iot_errno.h"
#include "iot_gpio.h"
#include "iot_pwm.h"
#include "ohos_init.h"#define RED_LED_PIN_NAME HI_IO_NAME_GPIO_10
#define RED_LED_PIN_FUNCTION WIFI_IOT_IO_FUNC_GPIO_10_GPIO
#define GREEN_LED_PIN_NAME HI_IO_NAME_GPIO_2
#define GREEN_LED_PIN_FUNCTION WIFI_IOT_IO_FUNC_GPIO_2_GPIO
#define BLUE_LED_PIN_NAME HI_IO_NAME_GPIO_7
#define BLUE_LED_PIN_FUNCTION WIFI_IOT_IO_FUNC_GPIO_7_GPIO#define PWM_FREQ_DIVITION 64000
#define DELAY_US 30000
#define STACK_SIZE (4096)
#define PWM0_PORT_NUM (0)
#define PWM1_PORT_NUM (1)
#define PWM2_PORT_NUM (2)static void PWMLedDemoTask(void)
{// pwm占空比记录变量unsigned short duty0 = 0, duty1 = 40, duty2 = 80;// 记录占空比是增加还是减少hi_bool duty0_increase = HI_TRUE;hi_bool duty1_increase = HI_TRUE;hi_bool duty2_increase = HI_TRUE;// 炫彩灯板的红灯hi_io_set_func(RED_LED_PIN_NAME, HI_IO_FUNC_GPIO_10_PWM1_OUT);hi_io_set_func(GREEN_LED_PIN_NAME, HI_IO_FUNC_GPIO_2_PWM2_OUT);hi_io_set_func(BLUE_LED_PIN_NAME, HI_IO_FUNC_GPIO_7_PWM0_OUT);IoTPwmInit(PWM0_PORT_NUM);IoTPwmInit(PWM1_PORT_NUM);IoTPwmInit(PWM2_PORT_NUM);while (1) {// use PWM control RED LED brightness// 蓝灯呼吸代码IoTPwmStart(PWM0_PORT_NUM, duty0, PWM_FREQ_DIVITION);if (duty0_increase) {duty0++;if (duty0 > 100) {// 自增超过100后需要进行自减duty0_increase = HI_FALSE;duty0 = 99;}} else {duty0--;if (duty0 == 0) {// 自减到0后需要进行自增duty0_increase = HI_TRUE;}}// 红灯呼吸代码IoTPwmStart(PWM1_PORT_NUM, duty1, PWM_FREQ_DIVITION);if (duty1_increase) {duty1++;if (duty1 > 100) {duty1_increase = HI_FALSE;duty1 = 99;}} else {duty1--;if (duty1 == 0) {duty1_increase = HI_TRUE;}}// 绿灯呼吸代码IoTPwmStart(PWM2_PORT_NUM, duty2, PWM_FREQ_DIVITION);if (duty2_increase) {duty2++;if (duty2 > 100) {duty2_increase = HI_FALSE;duty2 = 99;}} else {duty2--;if (duty2 == 0) {duty2_increase = HI_TRUE;}}usleep(DELAY_US);}
}static void PWMLedDemo(void)
{osThreadAttr_t attr;// set Red LED pin to GPIO functionIoTGpioInit(RED_LED_PIN_NAME);attr.name = "PWMLedDemoTask";attr.attr_bits = 0U;attr.cb_mem = NULL;attr.cb_size = 0U;attr.stack_mem = NULL;attr.stack_size = STACK_SIZE;attr.priority = osPriorityNormal;if (osThreadNew(PWMLedDemoTask, NULL, &attr) == NULL) {printf("[ColorfulLightDemo] Falied to create PWMLedDemoTask!\n");}
}
APP_FEATURE_INIT(PWMLedDemo);

目录结构

│  config.json
│
├─common
│  └─bsp
│      ├─include
│      └─src
├─demo
│  │  BUILD.gn
│  │
│  ├─base_00_helloworld
│  │      base_helloworld_example.c
│  │      BUILD.gn
│  │
│  ├─base_01_led
│  │      base_led_example.c
│  │      BUILD.gn
│  │
│  ├─base_02_loopkey
│  │      base_loopkey_example.c
│  │      BUILD.gn
│  │
│  ├─base_03_irqkey
│  │      base_irqkey_example.c
│  │      BUILD.gn
│  │
│  ├─base_04_adc
│  │      base_adc_example.c
│  │      BUILD.gn
│  │
│  └─base_05_pwm
│          base_pwm_example.c
│          BUILD.gn
│
└─doc│  HarmonyOS开发板实验指导书 v2.1.pdf│  华清远见 FS_Hi3861开发指导.md│  华清远见 FS_Hi3861新手入门手册.md│├─board│      FS-Hi3861-V4.2.pdf│      FS-Hi3861QDB-V3.2.pdf│      hi-12f_kit_v1.1.0规格书-20211025.pdf│      hi-12f_v1.1.2-规格书-20211202.pdf│      nodemcu-hi-07s_12f-kit_v1.1-20210913.pdf│      RTplay2.01_2024-06-14.pdf│└─figures

使用build,编译成功后,使用upload进行烧录。

运行效果如下,三色灯颜色会变化。

http://www.yayakq.cn/news/198039/

相关文章:

  • 市桥有经验的网站建设深圳软件定制公司
  • 网站上有声的文章是怎么做的网站一直显示建设中
  • 接做网站需要问什么条件电商平台的优势有哪些
  • 企业可以做哪些网站建什么类型个人网站比较好
  • 网站建设捌金手指花总十一WordPress更换域名之后
  • aspcms 网站栏目管理无锡微信网站定制
  • 域名已有服务器也有怎么做网站全球互联网企业排名
  • 郑州做网站狼牙wordpress去掉导航栏
  • 纯净软件网站推荐成都网站建设麦格思
  • 泰州专业做网站公司中国金融互联网协会官网
  • 西安杰商网络网站建设wordpress完整搬家
  • 常见的旅游网络营销方式seo网络营销公司
  • 建设公司网站的申请网站建设服务目标
  • 网站建设经验心得专业做室内设计的网站有哪些
  • 个人 可以做社交网站企业宣传网
  • 男女做暖暖的试看网站漫画网站ui标准
  • 做网站什么商品好室内设计素材网站推荐
  • 文创设计.net 网站优化
  • 小说网站排名人气wordpress做菜鸟教程
  • 广告公司网站东莞智通人才网登录
  • 邢台网站推广公司只做男生穿搭的网站
  • 龙岩做网站的公司wordpress都可以干什么
  • 固安企业网站建设找外国女朋友的网站建设
  • 怎么在网站视频做字幕桂林两江四湖属于哪个区
  • 微网站外链wordpress mega
  • 廊坊网站建设精灵wordpress 调试环境
  • 网站建设需求调研施工企业既搞建筑安装又搞建筑材料销售其应纳税种为
  • 顺德做网站shundeit湖南平台网站建设设计
  • 自己做的网站怎么发布上请人做外贸网站应注意什么问题
  • 网站搭建用什么语言wordpress数据文件路径