Hi3861 OpenHarmony嵌入式应用入门--0.96寸液晶屏 iic驱动ssd1306

使用iic驱动ssd1306,代码来源hihope\hispark_pegasus\demo\12_ssd1306

本样例提供了一个HarmonyOS IoT硬件接口的SSD1306 OLED屏驱动库,其功能如下:

  • 内置了128*64 bit的内存缓冲区,支持全屏刷新;
  • 优化了屏幕刷新速率,实测最大帧率10fps;
  • libm_port

是从musl libc中抽取的 sin和 cos的实现;

  • 用于规避链接Hi3861 SDK中的libm_flash.a报错的问题;
  • gif2imgs.py

可用于将gif动图中的帧分离出来;

  • 依赖 pillow 包,可以使用 pip install pillow 命令安装;
  • img2code.py

可用于将图片转为C数组,每个字节表示8个像素;

  • 依赖 opecv-python 包,可以使用 pip install opencv-python 命令安装;
  • 使用Harmony OS的IoT硬件接口;
  • 接口简洁易于使用、易于移植;
  • 内置了测试程序,可直接进行测试;

硬件原理图

IO口定义

I2C API

API名称

说明

I2cInit (WifiIotI2cIdx id, unsigned int baudrate)

用指定的波特速率初始化I2C设备

I2cDeinit (WifiIotI2cIdx id)

取消初始化I2C设备

I2cWrite (WifiIotI2cIdx id, unsigned short deviceAddr, const WifiIotI2cData *i2cData)

将数据写入I2C设备

I2cRead (WifiIotI2cIdx id, unsigned short deviceAddr, const WifiIotI2cData *i2cData)

从I2C设备中读取数据

I2cWriteread (WifiIotI2cIdx id, unsigned short deviceAddr, const WifiIotI2cData *i2cData)

向I2C设备发送数据并接收数据响应

I2cRegisterResetBusFunc (WifiIotI2cIdx id, WifiIotI2cFunc pfn)

注册I2C设备回调

I2cSetBaudrate (WifiIotI2cIdx id, unsigned int baudrate)

设置I2C设备的波特率

ssd1306 API

API名称

说明

void ssd1306_Init(void)

初始化

void ssd1306_Fill(SSD1306_COLOR color)

以指定的颜色填充屏幕

void ssd1306_SetCursor(uint8_t x, uint8_t y)

定位光标

void ssd1306_UpdateScreen(void)

更新屏幕内容

char ssd1306_DrawChar(char ch, FontDef Font, SSD1306_COLOR color)

在屏幕缓冲区绘制1个字符

char ssd1306_DrawString(char* str, FontDef Font, SSD1306_COLOR color)

将完整字符串写入屏幕缓冲区

void ssd1306_DrawPixel(uint8_t x, uint8_t y, SSD1306_COLOR color)

在屏幕缓冲区中绘制一个像素

void ssd1306_DrawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, SSD1306_COLOR color)

用Bresenhem算法画直线

void ssd1306_DrawPolyline(const SSD1306_VERTEX *par_vertex, uint16_t par_size, SSD1306_COLOR color)

绘制多段线

void ssd1306_DrawRectangle(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, SSD1306_COLOR color)

绘制矩形

void ssd1306_DrawArc(uint8_t x, uint8_t y, uint8_t radius, uint16_t start_angle, uint16_t sweep, SSD1306_COLOR color)

绘图角度

void ssd1306_DrawCircle(uint8_t par_x, uint8_t par_y, uint8_t par_r, SSD1306_COLOR color)

用Bresenhem算法画圆

void ssd1306_DrawBitmap(const uint8_t* bitmap, uint32_t size)

绘图位图

void ssd1306_DrawRegion(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t* data, uint32_t size, uint32_t stride)

绘制区域

修改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",
    "base_06_ssd1306:base_ssd1306_example",
  ]
}

将D:\DevEcoProjects\test\src\vendor\hihope\hispark_pegasus\demo\12_ssd1306文件复制到D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\base_06_ssd1306中

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

#Copyright (C) 2021 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.

import("//build/lite/config/component/lite_component.gni")

lite_component("base_ssd1306_example") {
    features = [
        "ssd1306:oled_ssd1306",
        "examples:oled_test",
        "//third_party/libm_port:libm_port"
    ]
}

目录结构

│  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
│  │
│  └─base_06_ssd1306
│      │  BUILD.gn
│      │  gif2imgs.py
│      │  img2code.py
│      │  LICENSE
│      │  README.md
│      │  requirements.txt
│      │
│      ├─examples
│      │      BUILD.gn
│      │      ssd1306_demo.c
│      │      ssd1306_tests.c
│      │      ssd1306_tests.h
│      │
│      └─ssd1306
│              BUILD.gn
│              ssd1306.c
│              ssd1306.h
│              ssd1306_conf.h
│
└─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_A1_2024-06-20.pdf
    │
    └─figures

进行编译,编译好如下

烧写进开发板,运行效果如下

  • 27
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 0.96OLED是一种小型的有机发光二极管显示屏。它是一种高亮度、高对比度、高分辨率的显示屏,适用于各种应用场合。IIC驱动程序则是操作系统或电路板与其它设备之间的通信协议,它可以进行数据传输和控制信号的交互。因此,编写0.96OLEDIIC驱动程序就是要实现电路板与显示屏之间的通信交互,使显示屏能够正确地显示图像和文字。 在编写0.96OLEDIIC驱动程序时,应首先了解其IIC接口的相关规范,包括SCL时钟速率、SDA数据线的电平和传输协议等。其次,需要了解OLED屏幕的显示控制指令,以便能够控制屏幕的显示效果。最后,就是编写具体的IIC驱动程序,主要包括向OLED发送指令和数据信息,以及控制屏幕的显示效果。 在具体的编写过程中,需要注意一些问题。首先,要确保发送的指令和数据信息能够正确地被OLED屏幕接收和解析,以便实现正确的显示效果。其次,要考虑不同操作系统和电路板的兼容性,以确保程序的可移植性和通用性。此外,还需要对程序进行不断测试和优化,以提高程序的稳定性和运行效率。 总之,编写0.96OLEDIIC驱动程序需要有一定的电子组装和编程知识,但也是一种具有挑战性和实用性的任务。通过不断地学习和实践,我们可以掌握其编写技巧,为各种应用场合提供高品质的显示屏幕。 ### 回答2: 0.96oled是一种小型显示屏,由于其小巧、高清和低功耗特点,被广泛应用于各种便携式电子产品中。而其iic驱动程序则是控制该显示屏的重要部分。 iic驱动程序的主要作用是通过iic总线与显示屏通信,将需要显示的图像或数据发送到oled屏幕上。在编写iic驱动程序时,需要考虑以下几个关键因素: 首先,需要明确o了屏幕的iic地址。通常,该地址为0x3C或0x3D。然后,还需要通过iic总线初始化oled屏幕,并设置其显示模式、亮度和对比度等参数。 其次,需要将设计好的图像或数据转换成oled屏幕能够识别的格式,并通过iic总线发送到屏幕上。这通常需要使用一些特殊的函数和库,例如Adafruit或u8g2等。 最后,需要考虑屏幕的尺和分辨率,以保证显示效果清晰和稳定。此外,还需要在程序中加入一些延迟、清屏和休眠等功能,以降低功耗和延长oled屏幕的使用寿命。 总之,编写0.96olediic驱动程序需要考虑诸多因素,但只要掌握一定的知识和经验,就能轻松完成该任务,让oled屏幕在各种应用场景中发挥出其优异的性能和效果。 ### 回答3: IIC是一种串行通信总线协议,也称为I2C(Inter-Integrated Circuit)。IIC协议可以实现多个设备之间的通信,这些设备可以是不同的芯片或者模块。对于0.96OLED显示屏来说,我们需要使用IIC驱动程序来使其正常显示。 IIC协议中传输的数据是通过使用SCL和SDA两个线路进行同步传输的,其中SCL线路用于时钟信号的传输,SDA线路用于数据的传输。在将OLED屏幕连接到单片机或者开发板之后,我们需要根据OLED的型号和接线方式编写相应的IIC驱动程序。 在编写IIC驱动程序之前,需要先确定OLED显示屏的IIC地址,多数情况下该地址为0x3C或者0x3D。然后,我们需要根据OLED屏幕的接口协议编写读取和写入数据的函数。对于写入数据函数,通常的流程如下:首先启动IIC总线,然后发送OLED屏幕的IIC地址,接着发送控制字节和具体的数据,最后释放IIC总线。对于读取数据函数,流程类似,只需要在发送IIC地址之后,向OLED屏幕发送读取命令即可。 需要注意的是,不同厂商的OLED屏幕可能存在接口协议的差异,因此在编写IIC驱动程序时需要了解具体的厂商数据手册和接口定义。同时,在实际使用过程中,还需要根据具体的应用场景对IIC驱动程序进行优化和改进,以实现更高效的数据传输和显示效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值