IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 嵌入式 -> RT_Thread学习笔记(6) OLED驱动移植 IIC -> 正文阅读

[嵌入式]RT_Thread学习笔记(6) OLED驱动移植 IIC

RT THREAD OLED IIC驱动移植

1.硬件环境

在这里插入图片描述

MCU:STM32F103C8T6

OLED:SSD1306 0.96

关键用u8g2的话内存开销太大了,所以正好学习一下IIC驱动


2.程序开发

2.1 开启IIC

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-HTMgc0wO-1625904982998)(https://note.youdao.com/yws/res/2/WEBRESOURCE205552f156293d564bed747aa3a47f22)][外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-PVvQnVzm-1625904982999)(https://note.youdao.com/yws/res/d/WEBRESOURCE732f85cd041e92ec3c1cd3db725069bd)]
在这里插入图片描述

记得下载后在MSH中查看是否真的开启了IIC总线

2.2程序移植

首先需要明确一点 rtt和传统驱动的区别

rtthread把地址和读写位是分开的,底层发送的数据是将地址左移1位再或上读写位,如果你发0xa0,左移后再或上写,这个数据不对了,应该发0x50左移后变成0xa0再或上写就对了,相关的解释网址如下:

https://club.rt-thread.org/ask/question/8065.html

其实我当时在驱动AT24C256的时候是十分困惑的,为什么在文档里写的0xa0为什么在程序中要设置为0x50,直到我自己真正动手驱动的时候才知道了原因

所以既然OLED的从机地址是0x78,对应0111 1000

那我们右移一位 0011 1100变成0x3c


然后在整个驱动的过程中最终要的还是写指令的操作,代码如下:

static rt_err_t WriteCmd(struct rt_i2c_bus_device *bus, rt_uint8_t data)
{
    rt_uint8_t buf[2];
    struct rt_i2c_msg msgs;

    buf[0] = 0x00;
    buf[1] = data;


    msgs.addr = OLED_ADDR;
    msgs.flags = RT_I2C_WR;
    msgs.buf = buf;
    msgs.len = 2;

    /* 调用I2C设备接口传输数据 */
    if (rt_i2c_transfer(bus, &msgs, 1) == 1)
    {
        return RT_EOK;
    }
    else
    {
        return -RT_ERROR;
    }
}

static rt_err_t WriteDat(struct rt_i2c_bus_device *bus, rt_uint8_t data)
{
    rt_uint8_t buf[2];
    struct rt_i2c_msg msgs;

    buf[0] = 0x40;
    buf[1] = data;


    msgs.addr = OLED_ADDR;
    msgs.flags = RT_I2C_WR;
    msgs.buf = buf;
    msgs.len = 2;

    /* 调用I2C设备接口传输数据 */
    if (rt_i2c_transfer(bus, &msgs, 1) == 1)
    {
        return RT_EOK;
    }
    else
    {
        return -RT_ERROR;
    }
}

初始化函数

void OLED_INIT(void)
{
    rt_thread_mdelay(100);

    WriteCmd(i2c_bus,0xAE); //display off
    WriteCmd(i2c_bus,0x20); //Set Memory Addressing Mode
    WriteCmd(i2c_bus,0x10); //00,Horizontal Addressing Mode;01,Vertical Addressing Mode;10,Page Addressing Mode (RESET);11,Invalid
    WriteCmd(i2c_bus,0xb0); //Set Page Start Address for Page Addressing Mode,0-7
    WriteCmd(i2c_bus,0xc8); //Set COM Output Scan Direction
    WriteCmd(i2c_bus,0x00); //---set low column address
    WriteCmd(i2c_bus,0x10); //---set high column address
    WriteCmd(i2c_bus,0x40); //--set start line address
    WriteCmd(i2c_bus,0x81); //--set contrast control register
    WriteCmd(i2c_bus,0xff); //亮度调节 0x00~0xff
    WriteCmd(i2c_bus,0xa1); //--set segment re-map 0 to 127
    WriteCmd(i2c_bus,0xa6); //--set normal display
    WriteCmd(i2c_bus,0xa8); //--set multiplex ratio(1 to 64)
    WriteCmd(i2c_bus,0x3F); //
    WriteCmd(i2c_bus,0xa4); //0xa4,Output follows RAM content;0xa5,Output ignores RAM content
    WriteCmd(i2c_bus,0xd3); //-set display offset
    WriteCmd(i2c_bus,0x00); //-not offset
    WriteCmd(i2c_bus,0xd5); //--set display clock divide ratio/oscillator frequency
    WriteCmd(i2c_bus,0xf0); //--set divide ratio
    WriteCmd(i2c_bus,0xd9); //--set pre-charge period
    WriteCmd(i2c_bus,0x22); //
    WriteCmd(i2c_bus,0xda); //--set com pins hardware configuration
    WriteCmd(i2c_bus,0x12);
    WriteCmd(i2c_bus,0xdb); //--set vcomh
    WriteCmd(i2c_bus,0x20); //0x20,0.77xVcc
    WriteCmd(i2c_bus,0x8d); //--set DC-DC enable
    WriteCmd(i2c_bus,0x14); //
    WriteCmd(i2c_bus,0xaf); //--turn on oled panel

}

下载程序后看到一片花就对了

其余相关函数都放进来了

//全屏填充
void OLED_FILL(unsigned char fill_data)
{
    unsigned char m,n;
    for(m=0;m<8;m++){
        WriteCmd(i2c_bus,0xb0+m);
        WriteCmd(i2c_bus,0x00);
        WriteCmd(i2c_bus,0x10);

        for(n=0;n<128;n++){
            WriteDat(i2c_bus,fill_data);
        }
    }
}

//OLED清屏
void OLED_CLS(void)
{
    OLED_FILL(0x00);
}




void OLED_SetPos(unsigned char x, unsigned char y) //设置起始点坐标
{
    WriteCmd(i2c_bus,0xb0+y);
    WriteCmd(i2c_bus,((x&0xf0)>>4)|0x10);
    WriteCmd(i2c_bus,(x&0x0f)|0x01);
}


const unsigned char F6x8[][6] =
{
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// sp
    {0x00, 0x00, 0x00, 0x2f, 0x00, 0x00},// !
    {0x00, 0x00, 0x07, 0x00, 0x07, 0x00},// "
    {0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14},// #
    {0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12},// $
    {0x00, 0x62, 0x64, 0x08, 0x13, 0x23},// %
    {0x00, 0x36, 0x49, 0x55, 0x22, 0x50},// &
    {0x00, 0x00, 0x05, 0x03, 0x00, 0x00},// '
    {0x00, 0x00, 0x1c, 0x22, 0x41, 0x00},// (
    {0x00, 0x00, 0x41, 0x22, 0x1c, 0x00},// )
    {0x00, 0x14, 0x08, 0x3E, 0x08, 0x14},// *
    {0x00, 0x08, 0x08, 0x3E, 0x08, 0x08},// +
    {0x00, 0x00, 0x00, 0xA0, 0x60, 0x00},// ,
    {0x00, 0x08, 0x08, 0x08, 0x08, 0x08},// -
    {0x00, 0x00, 0x60, 0x60, 0x00, 0x00},// .
    {0x00, 0x20, 0x10, 0x08, 0x04, 0x02},// /
    {0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E},// 0
    {0x00, 0x00, 0x42, 0x7F, 0x40, 0x00},// 1
    {0x00, 0x42, 0x61, 0x51, 0x49, 0x46},// 2
    {0x00, 0x21, 0x41, 0x45, 0x4B, 0x31},// 3
    {0x00, 0x18, 0x14, 0x12, 0x7F, 0x10},// 4
    {0x00, 0x27, 0x45, 0x45, 0x45, 0x39},// 5
    {0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30},// 6
    {0x00, 0x01, 0x71, 0x09, 0x05, 0x03},// 7
    {0x00, 0x36, 0x49, 0x49, 0x49, 0x36},// 8
    {0x00, 0x06, 0x49, 0x49, 0x29, 0x1E},// 9
    {0x00, 0x00, 0x36, 0x36, 0x00, 0x00},// :
    {0x00, 0x00, 0x56, 0x36, 0x00, 0x00},// ;
    {0x00, 0x08, 0x14, 0x22, 0x41, 0x00},// <
    {0x00, 0x14, 0x14, 0x14, 0x14, 0x14},// =
    {0x00, 0x00, 0x41, 0x22, 0x14, 0x08},// >
    {0x00, 0x02, 0x01, 0x51, 0x09, 0x06},// ?
    {0x00, 0x32, 0x49, 0x59, 0x51, 0x3E},// @
    {0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C},// A
    {0x00, 0x7F, 0x49, 0x49, 0x49, 0x36},// B
    {0x00, 0x3E, 0x41, 0x41, 0x41, 0x22},// C
    {0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C},// D
    {0x00, 0x7F, 0x49, 0x49, 0x49, 0x41},// E
    {0x00, 0x7F, 0x09, 0x09, 0x09, 0x01},// F
    {0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A},// G
    {0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F},// H
    {0x00, 0x00, 0x41, 0x7F, 0x41, 0x00},// I
    {0x00, 0x20, 0x40, 0x41, 0x3F, 0x01},// J
    {0x00, 0x7F, 0x08, 0x14, 0x22, 0x41},// K
    {0x00, 0x7F, 0x40, 0x40, 0x40, 0x40},// L
    {0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F},// M
    {0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F},// N
    {0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E},// O
    {0x00, 0x7F, 0x09, 0x09, 0x09, 0x06},// P
    {0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E},// Q
    {0x00, 0x7F, 0x09, 0x19, 0x29, 0x46},// R
    {0x00, 0x46, 0x49, 0x49, 0x49, 0x31},// S
    {0x00, 0x01, 0x01, 0x7F, 0x01, 0x01},// T
    {0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F},// U
    {0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F},// V
    {0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F},// W
    {0x00, 0x63, 0x14, 0x08, 0x14, 0x63},// X
    {0x00, 0x07, 0x08, 0x70, 0x08, 0x07},// Y
    {0x00, 0x61, 0x51, 0x49, 0x45, 0x43},// Z
    {0x00, 0x00, 0x7F, 0x41, 0x41, 0x00},// [
    {0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55},// 55
    {0x00, 0x00, 0x41, 0x41, 0x7F, 0x00},// ]
    {0x00, 0x04, 0x02, 0x01, 0x02, 0x04},// ^
    {0x00, 0x40, 0x40, 0x40, 0x40, 0x40},// _
    {0x00, 0x00, 0x01, 0x02, 0x04, 0x00},// '
    {0x00, 0x20, 0x54, 0x54, 0x54, 0x78},// a
    {0x00, 0x7F, 0x48, 0x44, 0x44, 0x38},// b
    {0x00, 0x38, 0x44, 0x44, 0x44, 0x20},// c
    {0x00, 0x38, 0x44, 0x44, 0x48, 0x7F},// d
    {0x00, 0x38, 0x54, 0x54, 0x54, 0x18},// e
    {0x00, 0x08, 0x7E, 0x09, 0x01, 0x02},// f
    {0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C},// g
    {0x00, 0x7F, 0x08, 0x04, 0x04, 0x78},// h
    {0x00, 0x00, 0x44, 0x7D, 0x40, 0x00},// i
    {0x00, 0x40, 0x80, 0x84, 0x7D, 0x00},// j
    {0x00, 0x7F, 0x10, 0x28, 0x44, 0x00},// k
    {0x00, 0x00, 0x41, 0x7F, 0x40, 0x00},// l
    {0x00, 0x7C, 0x04, 0x18, 0x04, 0x78},// m
    {0x00, 0x7C, 0x08, 0x04, 0x04, 0x78},// n
    {0x00, 0x38, 0x44, 0x44, 0x44, 0x38},// o
    {0x00, 0xFC, 0x24, 0x24, 0x24, 0x18},// p
    {0x00, 0x18, 0x24, 0x24, 0x18, 0xFC},// q
    {0x00, 0x7C, 0x08, 0x04, 0x04, 0x08},// r
    {0x00, 0x48, 0x54, 0x54, 0x54, 0x20},// s
    {0x00, 0x04, 0x3F, 0x44, 0x40, 0x20},// t
    {0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C},// u
    {0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C},// v
    {0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C},// w
    {0x00, 0x44, 0x28, 0x10, 0x28, 0x44},// x
    {0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C},// y
    {0x00, 0x44, 0x64, 0x54, 0x4C, 0x44},// z
    {0x14, 0x14, 0x14, 0x14, 0x14, 0x14}// horiz lines
};

void OLED_ShowStr(unsigned char x, unsigned char y, unsigned char ch[])
{
    unsigned char c = 0,i = 0,j = 0;
    while(ch[j] != '\0')
    {
        c = ch[j] - 32;
        if(x > 126)
        {
            x = 0;
            y++;
        }
        OLED_SetPos(x,y);
        for(i=0;i<6;i++)
            WriteDat(i2c_bus,F6x8[c][i]);
        x += 6;
        j++;
    }
}


2.3程序执行效果

在这里插入图片描述

3.所有代码

因为我是放到mian.c中测试用的,有需求的话自行封装

/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-07-10     RT-Thread    first version
 */

#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>


#define DBG_TAG "main"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>

#define OLED_I2C_BUS_NAME "i2c1"
#define OLED_ADDR 0x3c //从机地址 0011 1100 原来是0x78 记得右移1位

static struct rt_i2c_bus_device *i2c_bus=RT_NULL;



static rt_err_t WriteCmd(struct rt_i2c_bus_device *bus, rt_uint8_t data)
{
    rt_uint8_t buf[2];
    struct rt_i2c_msg msgs;

    buf[0] = 0x00;
    buf[1] = data;


    msgs.addr = OLED_ADDR;
    msgs.flags = RT_I2C_WR;
    msgs.buf = buf;
    msgs.len = 2;

    /* 调用I2C设备接口传输数据 */
    if (rt_i2c_transfer(bus, &msgs, 1) == 1)
    {
        return RT_EOK;
    }
    else
    {
        return -RT_ERROR;
    }
}

static rt_err_t WriteDat(struct rt_i2c_bus_device *bus, rt_uint8_t data)
{
    rt_uint8_t buf[2];
    struct rt_i2c_msg msgs;

    buf[0] = 0x40;
    buf[1] = data;


    msgs.addr = OLED_ADDR;
    msgs.flags = RT_I2C_WR;
    msgs.buf = buf;
    msgs.len = 2;

    /* 调用I2C设备接口传输数据 */
    if (rt_i2c_transfer(bus, &msgs, 1) == 1)
    {
        return RT_EOK;
    }
    else
    {
        return -RT_ERROR;
    }
}

void OLED_INIT(void)
{
    rt_thread_mdelay(100);

    WriteCmd(i2c_bus,0xAE); //display off
    WriteCmd(i2c_bus,0x20); //Set Memory Addressing Mode
    WriteCmd(i2c_bus,0x10); //00,Horizontal Addressing Mode;01,Vertical Addressing Mode;10,Page Addressing Mode (RESET);11,Invalid
    WriteCmd(i2c_bus,0xb0); //Set Page Start Address for Page Addressing Mode,0-7
    WriteCmd(i2c_bus,0xc8); //Set COM Output Scan Direction
    WriteCmd(i2c_bus,0x00); //---set low column address
    WriteCmd(i2c_bus,0x10); //---set high column address
    WriteCmd(i2c_bus,0x40); //--set start line address
    WriteCmd(i2c_bus,0x81); //--set contrast control register
    WriteCmd(i2c_bus,0xff); //亮度调节 0x00~0xff
    WriteCmd(i2c_bus,0xa1); //--set segment re-map 0 to 127
    WriteCmd(i2c_bus,0xa6); //--set normal display
    WriteCmd(i2c_bus,0xa8); //--set multiplex ratio(1 to 64)
    WriteCmd(i2c_bus,0x3F); //
    WriteCmd(i2c_bus,0xa4); //0xa4,Output follows RAM content;0xa5,Output ignores RAM content
    WriteCmd(i2c_bus,0xd3); //-set display offset
    WriteCmd(i2c_bus,0x00); //-not offset
    WriteCmd(i2c_bus,0xd5); //--set display clock divide ratio/oscillator frequency
    WriteCmd(i2c_bus,0xf0); //--set divide ratio
    WriteCmd(i2c_bus,0xd9); //--set pre-charge period
    WriteCmd(i2c_bus,0x22); //
    WriteCmd(i2c_bus,0xda); //--set com pins hardware configuration
    WriteCmd(i2c_bus,0x12);
    WriteCmd(i2c_bus,0xdb); //--set vcomh
    WriteCmd(i2c_bus,0x20); //0x20,0.77xVcc
    WriteCmd(i2c_bus,0x8d); //--set DC-DC enable
    WriteCmd(i2c_bus,0x14); //
    WriteCmd(i2c_bus,0xaf); //--turn on oled panel

}

//全屏填充
void OLED_FILL(unsigned char fill_data)
{
    unsigned char m,n;
    for(m=0;m<8;m++){
        WriteCmd(i2c_bus,0xb0+m);
        WriteCmd(i2c_bus,0x00);
        WriteCmd(i2c_bus,0x10);

        for(n=0;n<128;n++){
            WriteDat(i2c_bus,fill_data);
        }
    }
}

//OLED清屏
void OLED_CLS(void)
{
    OLED_FILL(0x00);
}




void OLED_SetPos(unsigned char x, unsigned char y) //设置起始点坐标
{
    WriteCmd(i2c_bus,0xb0+y);
    WriteCmd(i2c_bus,((x&0xf0)>>4)|0x10);
    WriteCmd(i2c_bus,(x&0x0f)|0x01);
}


const unsigned char F6x8[][6] =
{
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// sp
    {0x00, 0x00, 0x00, 0x2f, 0x00, 0x00},// !
    {0x00, 0x00, 0x07, 0x00, 0x07, 0x00},// "
    {0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14},// #
    {0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12},// $
    {0x00, 0x62, 0x64, 0x08, 0x13, 0x23},// %
    {0x00, 0x36, 0x49, 0x55, 0x22, 0x50},// &
    {0x00, 0x00, 0x05, 0x03, 0x00, 0x00},// '
    {0x00, 0x00, 0x1c, 0x22, 0x41, 0x00},// (
    {0x00, 0x00, 0x41, 0x22, 0x1c, 0x00},// )
    {0x00, 0x14, 0x08, 0x3E, 0x08, 0x14},// *
    {0x00, 0x08, 0x08, 0x3E, 0x08, 0x08},// +
    {0x00, 0x00, 0x00, 0xA0, 0x60, 0x00},// ,
    {0x00, 0x08, 0x08, 0x08, 0x08, 0x08},// -
    {0x00, 0x00, 0x60, 0x60, 0x00, 0x00},// .
    {0x00, 0x20, 0x10, 0x08, 0x04, 0x02},// /
    {0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E},// 0
    {0x00, 0x00, 0x42, 0x7F, 0x40, 0x00},// 1
    {0x00, 0x42, 0x61, 0x51, 0x49, 0x46},// 2
    {0x00, 0x21, 0x41, 0x45, 0x4B, 0x31},// 3
    {0x00, 0x18, 0x14, 0x12, 0x7F, 0x10},// 4
    {0x00, 0x27, 0x45, 0x45, 0x45, 0x39},// 5
    {0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30},// 6
    {0x00, 0x01, 0x71, 0x09, 0x05, 0x03},// 7
    {0x00, 0x36, 0x49, 0x49, 0x49, 0x36},// 8
    {0x00, 0x06, 0x49, 0x49, 0x29, 0x1E},// 9
    {0x00, 0x00, 0x36, 0x36, 0x00, 0x00},// :
    {0x00, 0x00, 0x56, 0x36, 0x00, 0x00},// ;
    {0x00, 0x08, 0x14, 0x22, 0x41, 0x00},// <
    {0x00, 0x14, 0x14, 0x14, 0x14, 0x14},// =
    {0x00, 0x00, 0x41, 0x22, 0x14, 0x08},// >
    {0x00, 0x02, 0x01, 0x51, 0x09, 0x06},// ?
    {0x00, 0x32, 0x49, 0x59, 0x51, 0x3E},// @
    {0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C},// A
    {0x00, 0x7F, 0x49, 0x49, 0x49, 0x36},// B
    {0x00, 0x3E, 0x41, 0x41, 0x41, 0x22},// C
    {0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C},// D
    {0x00, 0x7F, 0x49, 0x49, 0x49, 0x41},// E
    {0x00, 0x7F, 0x09, 0x09, 0x09, 0x01},// F
    {0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A},// G
    {0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F},// H
    {0x00, 0x00, 0x41, 0x7F, 0x41, 0x00},// I
    {0x00, 0x20, 0x40, 0x41, 0x3F, 0x01},// J
    {0x00, 0x7F, 0x08, 0x14, 0x22, 0x41},// K
    {0x00, 0x7F, 0x40, 0x40, 0x40, 0x40},// L
    {0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F},// M
    {0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F},// N
    {0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E},// O
    {0x00, 0x7F, 0x09, 0x09, 0x09, 0x06},// P
    {0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E},// Q
    {0x00, 0x7F, 0x09, 0x19, 0x29, 0x46},// R
    {0x00, 0x46, 0x49, 0x49, 0x49, 0x31},// S
    {0x00, 0x01, 0x01, 0x7F, 0x01, 0x01},// T
    {0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F},// U
    {0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F},// V
    {0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F},// W
    {0x00, 0x63, 0x14, 0x08, 0x14, 0x63},// X
    {0x00, 0x07, 0x08, 0x70, 0x08, 0x07},// Y
    {0x00, 0x61, 0x51, 0x49, 0x45, 0x43},// Z
    {0x00, 0x00, 0x7F, 0x41, 0x41, 0x00},// [
    {0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55},// 55
    {0x00, 0x00, 0x41, 0x41, 0x7F, 0x00},// ]
    {0x00, 0x04, 0x02, 0x01, 0x02, 0x04},// ^
    {0x00, 0x40, 0x40, 0x40, 0x40, 0x40},// _
    {0x00, 0x00, 0x01, 0x02, 0x04, 0x00},// '
    {0x00, 0x20, 0x54, 0x54, 0x54, 0x78},// a
    {0x00, 0x7F, 0x48, 0x44, 0x44, 0x38},// b
    {0x00, 0x38, 0x44, 0x44, 0x44, 0x20},// c
    {0x00, 0x38, 0x44, 0x44, 0x48, 0x7F},// d
    {0x00, 0x38, 0x54, 0x54, 0x54, 0x18},// e
    {0x00, 0x08, 0x7E, 0x09, 0x01, 0x02},// f
    {0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C},// g
    {0x00, 0x7F, 0x08, 0x04, 0x04, 0x78},// h
    {0x00, 0x00, 0x44, 0x7D, 0x40, 0x00},// i
    {0x00, 0x40, 0x80, 0x84, 0x7D, 0x00},// j
    {0x00, 0x7F, 0x10, 0x28, 0x44, 0x00},// k
    {0x00, 0x00, 0x41, 0x7F, 0x40, 0x00},// l
    {0x00, 0x7C, 0x04, 0x18, 0x04, 0x78},// m
    {0x00, 0x7C, 0x08, 0x04, 0x04, 0x78},// n
    {0x00, 0x38, 0x44, 0x44, 0x44, 0x38},// o
    {0x00, 0xFC, 0x24, 0x24, 0x24, 0x18},// p
    {0x00, 0x18, 0x24, 0x24, 0x18, 0xFC},// q
    {0x00, 0x7C, 0x08, 0x04, 0x04, 0x08},// r
    {0x00, 0x48, 0x54, 0x54, 0x54, 0x20},// s
    {0x00, 0x04, 0x3F, 0x44, 0x40, 0x20},// t
    {0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C},// u
    {0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C},// v
    {0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C},// w
    {0x00, 0x44, 0x28, 0x10, 0x28, 0x44},// x
    {0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C},// y
    {0x00, 0x44, 0x64, 0x54, 0x4C, 0x44},// z
    {0x14, 0x14, 0x14, 0x14, 0x14, 0x14}// horiz lines
};

void OLED_ShowStr(unsigned char x, unsigned char y, unsigned char ch[])
{
    unsigned char c = 0,i = 0,j = 0;
    while(ch[j] != '\0')
    {
        c = ch[j] - 32;
        if(x > 126)
        {
            x = 0;
            y++;
        }
        OLED_SetPos(x,y);
        for(i=0;i<6;i++)
            WriteDat(i2c_bus,F6x8[c][i]);
        x += 6;
        j++;
    }
}
int main(void)
{
    rt_err_t result=RT_NULL;
    i2c_bus=(struct rt_i2c_bus_device *)rt_device_find("i2c1");
    if(i2c_bus==RT_NULL){
        rt_kprintf("no device \n");
    }else{
        rt_kprintf("find device \n");

        //初始化程序段
        OLED_INIT();
        OLED_CLS();

        OLED_ShowStr(0,3,"i am king");
    }


    return RT_EOK;
}


相关操作不应该全部放在main.c里面,本文仅做测试。
学习了一下还是挺爽的,下期再见

  嵌入式 最新文章
基于高精度单片机开发红外测温仪方案
89C51单片机与DAC0832
基于51单片机宠物自动投料喂食器控制系统仿
《痞子衡嵌入式半月刊》 第 68 期
多思计组实验实验七 简单模型机实验
CSC7720
启明智显分享| ESP32学习笔记参考--PWM(脉冲
STM32初探
STM32 总结
【STM32】CubeMX例程四---定时器中断(附工
上一篇文章      下一篇文章      查看所有文章
加:2021-07-11 16:46:50  更:2021-07-11 16:47:20 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年12日历 -2024/12/27 9:56:58-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码
数据统计