关于控制芯片SH1106的说明:
12864OLED显示屏是在某宝买的,以下图片是某店铺的说明:
内部电荷泵I2C接口:
SH1106既支持读写访问。R/W位是从地址的一部分。在i2c总线上传输任何数据之前,应该先处理响应的设备。SH1106预留了两个7位从地址(0111100和0111101)。通过将输入SA0连接到逻辑0(VSS)或逻辑1 (VDD1)来设置从地址的最小有效位。i2c总线协议如图7所示。该序列从I2C总线 主设备的开始条件开始,后面跟着从地址。具有相应地址的从设备应答,其他从机将忽略i2c总线传输。在确认之后,会有一个或多个命令来定义被寻址的从机的状态。命令字由一个控制字节组成,它定义了Co和D/C (见note1),加上一个数据字节(见图7)。最后一个控制字节被标记为一个清除的最重要的位,延续位Co。D /C位的状态定义了数据字节是被解释为命令还是被解释为RAM数据。控制字节和数据字节被总线上相应的从设备接收。在最后一个控制字节之后,根据D /C位设置的不同,数据分为显示数据字节或命令数据字节。如果将D/C位设置为’ 1 ‘,这些显示字节将存储在SRAM中,其地址由数据指针指定。数据指针自动更新,数据被写入到预定的SH1106设备。如果最后一个控制字节的D /C位被设置为’ 0 ',这些命令字节将被解码,设备的设置将根据接收到的命令改变。
每个字节之后的确认只由被寻址的从设备发出。在传输结束时,i2c总线主机发出一个停止条件§。如果R/ W位在从地址中被设置为1,芯片将根据在上次写访问期间发送的D /C位的从地址立即输出数据。如果在一个字节之后没有非应答,从设备停止向主机传送数据。
命令表:
注意:不要使用任何其他命令,否则可能导致系统故障
手册里提供了初始化的演示程序:
以下部分可以参考程序自己写:
这里说一下,我买的模块RST引脚已内置拉高。只有Vcc、Gnd、SDA、SCL这是个引脚。
下面说一下初始化命令的过程:
1.0xae | 显示关 |
---|---|
2.0x02 | 设置低列地址 |
3.0x10 | 设置高列地址 |
4.0x40 | 设置开始显示行 |
5.0xb0 | 设置页地址 |
6.0x81 | 设置对比度寄存器 |
0xff | 对比度数据(有0~255级对比度) |
7.0xa1 | 设置段重新映射(屏幕左右颠倒)) |
8.0xa6 | 设置正常显示 |
9.0xa8 | 多路分配模式设置 |
0x3f | 多路复用率数据 |
10. 0xad | 内置升压电荷泵设置 |
0x8b | 开启内置电荷泵(驱动OLED需要比较高的电压,我所买的模块Vpp没接出,所以要开启内置的电荷泵)OLED工作电压源:外部Vpp提供电压6.4v-14.0V;内部Vpp发生器提供电压6.4v-9.0V |
0x33 | 设置Vpp为9v(设置泵电压值Vpp(30H:6.4V;31H:7.4V;32H:8.0V;33H:9.0V) |
11.0xc8 | 设置COM输出扫描方向(屏幕上下颠倒) |
12.0xd3 | 显示偏移模式设置(SH1106仅支持垂直滚动)指定显示开始行到COM0-63之一的映射 |
0x00 | 无偏移 |
13.0xd5 | 分频比/振荡器频率模式设置(屏幕刷新频率) |
0x80 | 分频比/振荡器频率数据(0x80将时钟设置为100帧/秒) |
14.0xd9 | 无充电/预充电周期模式设置 |
0x1f | 无充电/预充电周期数据 |
15.0xda | COM引脚硬件配置模式设置,此命令用于设置通用信号垫配置。 |
0x12 | 参考文档,顺序:02H,替代:12H) |
16.0xdb | 取消级别模式设置 |
0x40 | VCOM=0.430VREF:00H, VCOM=0.770VREF:35H,VCOM=1*VREF:40H) |
17. 0xaf | 显示开 |
注意:
本人买的的模块RST是内部直接接高电平的,而官方给出的程序是有RST的,所以建议在开显示之前先清屏一下,不然打开就是这个样子。
如果你买的模块是有RST引脚的,就不用清屏,开始先让模块拉低一会就可以了
清屏函数: void i2c_SH1106_CLS(void);
先说下使用这块OLED出现的问题,文档提供的开始显示的列是从0x02开始的,显示也是从0x02开始的,所以写程序的时候开始都是从0x02开始,写 字符串i2c_SH1106_P8x16Str(0, 6,"abcdtfgWTF1234 ");和画图i2c_SH1106_DrawBMP(0,0,127,7,BMP);显示正常,但写i2c_SH1106_P6x8Str(0, 0,“0123456789”);这种小的字符串是,出现了乱码,把开始的列改成0x01,问题解决,开始显示的也是从第一个像素点开始的。我怀疑是我买的OLED有问题。
在发代码之前先来几张自己弄的XX图片:
这两张图片都是128*64像素的,将格式转成bmp的在取模就行了。
OLED显示的图片:(买的是蓝屏的,效果不够逼真,建议买白屏的)
i2c_master.h和i2c_master.c部分可以看我另一篇文档:
esp8266_I2C_master_修改-基于安信可编译器
i2c_OLED_fonts.h
/*
* i2c_OLED_fonts.h
*
* Created on: 2018年12月20日
* Author: 王杰龙
*/
#ifndef APP_INCLUDE_DRIVER_I2C_OLED_FONTS_H_
#define APP_INCLUDE_DRIVER_I2C_OLED_FONTS_H_
/************************************(6*8的点阵)************************************/
const unsigned char F6x8[][6] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,// sp,0
0x00, 0x00, 0x00, 0x2f, 0x00, 0x00,// !,1
0x00, 0x00, 0x07, 0x00, 0x07, 0x00,// ",2
0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14,// #,3
0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12,// $,4
0x00, 0x62, 0x64, 0x08, 0x13, 0x23,// %,5
0x00, 0x36, 0x49, 0x55, 0x22, 0x50,// &,6
0x00, 0x00, 0x05, 0x03, 0x00, 0x00,// ',7
0x00, 0x00, 0x1c, 0x22, 0x41, 0x00,// (,8
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
};
/****************************************(8*16的点阵)************************************/
const unsigned char F8X16[]=
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0
0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1
0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2
0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3
0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4
0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5
0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6
0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7
0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8
0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9
0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10
0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14
0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25
0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26
0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27
0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29
0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30
0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31
0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32
0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33
0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34
0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35
0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38
0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40
0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41
0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42
0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43
0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44
0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45
0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47
0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49
0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50
0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51
0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53
0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54
0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55
0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56
0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57
0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58
0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59
0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 60
0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61
0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63
0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65
0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66
0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67
0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69
0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71
0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72
0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73
0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74
0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75
0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77
0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79
0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80
0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81
0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83
0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84
0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86
0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87
0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89
0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90
0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91
0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92
0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93
0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//~ 94
};
#endif /* APP_INCLUDE_DRIVER_I2C_OLED_FONTS_H_ */
i2c_OLED_BMP.h
/*
* i2c_OLED_BMP.h
*
* Created on: 2018年12月20日
* Author: 王杰龙
*/
#ifndef APP_INCLUDE_DRIVER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0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
};
#endif /* APP_INCLUDE_DRIVER_I2C_OLED_BMP_H_ */
i2c_SH1106_oled.h
/*
* i2c_SH1106_oled.h
*
* Created on: 2018年12月20日
* Author: 王杰龙
*/
#ifndef APP_INCLUDE_DRIVER_I2C_SH1106_OLED_H_
#define APP_INCLUDE_DRIVER_I2C_SH1106_OLED_H_
#define SH1106_address 0x78 // D/C->GND
//#define i2c_SH1106_address 0x7a // D/C->Vcc
#define Brightness 0x0f //OLED亮度(0x00~0xff)
void i2c_SH1106_write(unsigned char Control,unsigned char Cmd_Da);//向显示控制寄存器中写命令command/写数据data
void i2c_SH1106_Init(void);//OLED初始化相关操作,user_main文件中开始必须初始化一次
void i2c_SH1106_SetPos(unsigned char x, unsigned char y); //设置屏幕上的显示位置
void i2c_SH1106_CLS(void);//清屏
void i2c_SH1106_P6x8Str(unsigned char x,unsigned char y,unsigned char ch[]);
void i2c_SH1106_ShowStr(unsigned char x, unsigned char y, unsigned char ch[], unsigned char TextSize);
void i2c_SH1106_P8x16Str(unsigned char x,unsigned char y,unsigned char ch[]);
void i2c_SH1106_DrawBMP(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,const unsigned char BMP[]);//画图
#endif /* APP_INCLUDE_DRIVER_I2C_SH1106_OLED_H_ */
i2c_SH1106_oled.c
/*
* i2c_SH1106_oled.c
*
* Created on: 2018年12月20日
* Author: 王杰龙
*/
#include "osapi.h"
#include "driver/i2c_SH1106_oled.h"
#include "driver/i2c_OLED_fonts.h"
#include "driver/i2c_master.h"
/*
* 功能:写OLED命令或是显示数据
* 参数:Control=0x00,写命令;Control=0x40,写显示数据
* 返回:无
*/
void ICACHE_FLASH_ATTR
i2c_SH1106_write(unsigned char Control,unsigned char Cmd_Da){//向显示控制寄存器中写命令command/写数据data
//启动i2c总线
i2c_master_start();
i2c_master_writeByte(SH1106_address&0xfe);//OLED从地址写模式
//检查i2c从机应答
if(!i2c_master_checkAck()) {
i2c_master_stop();//如果从设备未应答,将设备停止
return;
}
//写控制命令
i2c_master_writeByte(Control);
//检查i2c从机应答
if(!i2c_master_checkAck()) {
i2c_master_stop();
return;
}
//写数据到寄存器
i2c_master_writeByte(Cmd_Da);
//检查i2c从机应答
if(!i2c_master_checkAck()) {
i2c_master_stop();
return;
}
//i2c停止
i2c_master_stop();
}
/*
* 功能:初始化OLED参数
* 入口参数:无
* 返回:无
*/
void ICACHE_FLASH_ATTR
i2c_SH1106_Init(void){
i2c_SH1106_write(0x00,0xae);//显示关
/***************SH1106只有页地址模式*********************/
/********************** 这里可以不用初始化*************/
// i2c_SH1106_write(0x00,0x02);//设置低列地址
// i2c_SH1106_write(0x00,0x10);//设置高列地址
// i2c_SH1106_write(0x00,0xb0);//设置页地址
/***********************end*************/
i2c_SH1106_write(0x00,0x40);//设置开始显示行地址com0
i2c_SH1106_write(0x00,0x81);//设置对比度控制寄存器
i2c_SH1106_write(0x00,Brightness);//对比度(亮度)
i2c_SH1106_write(0x00,0xa1);//设置段重新映射(ADC) 0 to 127屏幕左右颠倒)
i2c_SH1106_write(0x00,0xa6);//设置正常显示
i2c_SH1106_write(0x00,0xa8);//多路分配模式设置(1 to 64)
i2c_SH1106_write(0x00,0x3F);//
i2c_SH1106_write(0x00,0xad);//直流-直流转换器电源控制方式设置
i2c_SH1106_write(0x00,0x8b);//内供Vcc
i2c_SH1106_write(0x00,0x33);//set Vpp 9v
i2c_SH1106_write(0x00,0xc8);//设置COM输出扫描方向(屏幕上下颠倒)
i2c_SH1106_write(0x00,0xd3);//显示偏移模式设置
i2c_SH1106_write(0x00,0x00);//无偏移
i2c_SH1106_write(0x00,0xd5);//分频比/振荡器频率模式设置
i2c_SH1106_write(0x00,0xf0);//分频比/振荡器频率数据设置
i2c_SH1106_write(0x00,0xd9);//无充电/预充电周期模式设置
i2c_SH1106_write(0x00,0x1f); //无充电/预充电周期数据设置
i2c_SH1106_write(0x00,0xda);//COM引脚硬件配置模式设置
i2c_SH1106_write(0x00,0x12);
i2c_SH1106_write(0x00,0xdb);//--set vcomh
i2c_SH1106_write(0x00,0x40);//
i2c_SH1106_CLS(); //清屏
i2c_SH1106_write(0x00,0xaf);//--开显示
}
/*
* 功能:填充某个字符的数据到SRAM
* 入口参数:fill_Data
* 说明:内部使用函数
* 返回:无
* */
static void ICACHE_FLASH_ATTR
i2c_OLED_Fill(unsigned char fill_Data){//屏幕填充
unsigned char m,n;
for(m=0;m<8;m++)
{
i2c_SH1106_write(0x00,0x02); //设置低列地址,从0x02开始
i2c_SH1106_write(0x00,0x10); //设置高列地址
i2c_SH1106_write(0x00,0xb0+m); //设置页开始地址
for(n=0;n<128;n++)
{
i2c_SH1106_write(0x40,fill_Data);
}
}
}
void ICACHE_FLASH_ATTR
i2c_SH1106_CLS(void){ //清屏
i2c_OLED_Fill(0x00);
}
/*
* 功能:设置显示数据的位置
* 入口参数:x取0~127,y取0~7,8页,128列
* 说明:买的1.2寸的OLED屏的显示起始地址为0x02,故不对之前的SRAM操作
* 返回:无
*/
void ICACHE_FLASH_ATTR
i2c_SH1106_SetPos(unsigned char x, unsigned char y){ //设置屏幕上的显示位置
i2c_SH1106_write(0x00,(x&0x0f)+0x01);//设置低列地址,从0x01开始
i2c_SH1106_write(0x00,((x&0xf0)>>4)|0x10);//设置高列地址
i2c_SH1106_write(0x00,0xb0+y);//设置页地址
}
/***************功能描述:显示6*8一组标准ASCII字符串 显示的坐标(x,y),x范围为0~127,y为页范围0~7****************/
void ICACHE_FLASH_ATTR
i2c_SH1106_P6x8Str(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++;}
i2c_SH1106_SetPos(x,y);
for(i=0;i<6;i++)
i2c_SH1106_write(0x40,F6x8[c][i]);
x+=6;
j++;
}
}
/*******************功能描述:显示8*16一组标准ASCII字符串 显示的坐标(x,y),x范围为0~127,y为页范围0~7****************/
void ICACHE_FLASH_ATTR
i2c_SH1106_P8x16Str(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>120){x=0;y++;}
i2c_SH1106_SetPos(x,y);
for(i=0;i<8;i++)
i2c_SH1106_write(0x40,F8X16[c*16+i]);
i2c_SH1106_SetPos(x,y+1);
for(i=0;i<8;i++)
i2c_SH1106_write(0x40,F8X16[c*16+i+8]);
x+=8;
j++;
}
}
//显示字符串的位置与字符串的大小
void ICACHE_FLASH_ATTR
i2c_SH1106_ShowStr(unsigned char x, unsigned char y, unsigned char ch[], unsigned char TextSize)
{
unsigned char c = 0,i = 0,j = 0;
switch(TextSize)
{
case 1://像素大小6x8
{
while(ch[j] != '\0')
{
c = ch[j] - 32;//比如空格的ASCII值为32d,减去32刚好是F6x8[0][6]
if(x > 126)//一行显示不完,到下一行显示
{
x = 0;
y++;
}
i2c_SH1106_SetPos(x,y);
for(i=0;i<6;i++)
i2c_SH1106_write(0x40,F6x8[c][i]);
x += 6;
j++;
}
}break;
case 2://像素大小8X16
{
while(ch[j] != '\0')
{
c = ch[j] - 32;
if(x > 120) //一行显示不完,到下一行显示
{
x = 0;
y+=2;
}
i2c_SH1106_SetPos(x,y);
for(i=0;i<8;i++)
i2c_SH1106_write(0x40,F8X16[c*16+i]);
i2c_SH1106_SetPos(x,y+1);
for(i=0;i<8;i++)
i2c_SH1106_write(0x40,F8X16[c*16+i+8]);
x += 8;
j++;
}
}break;
}
}
/*
* 功能:在选定的位置画图
* 入口参数:x取0~127,y取0~7,BMP[]所放图片的字符数组
* 返回:无
* */
void ICACHE_FLASH_ATTR
i2c_SH1106_DrawBMP(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,const unsigned char BMP[]){
unsigned int j=0;
unsigned char x,y;
for(y=y0;y<=y1;y++)
{
i2c_SH1106_SetPos(x0+0x01,y);//从0x02开始
for(x=x0;x<=x1;x++)
i2c_SH1106_write(0x40,BMP[j++]);//写显示的数据,数据指针自动更新。
}
}
user_main.c
#include "osapi.h"
#include "user_interface.h"
#include "driver/i2c_SH1106_oled.h"
#include "driver/i2c_OLED_BMP.h"
uint32 priv_param_start_sec;
/******************************************************************************
* FunctionName : user_rf_cal_sector_set
* Description : SDK just reversed 4 sectors, used for rf init data and paramters.
* We add this function to force users to set rf cal sector, since
* we don't know which sector is free in user's application.
* sector map for last several sectors : ABCCC
* A : rf cal
* B : rf init data
* C : sdk parameters
* Parameters : none
* Returns : rf cal sector
*******************************************************************************/
uint32 ICACHE_FLASH_ATTR
user_rf_cal_sector_set(void)
{
enum flash_size_map size_map = system_get_flash_size_map();
uint32 rf_cal_sec = 0;
switch (size_map) {
case FLASH_SIZE_4M_MAP_256_256:
rf_cal_sec = 128 - 5;
priv_param_start_sec = 0x3C;
break;
case FLASH_SIZE_8M_MAP_512_512:
rf_cal_sec = 256 - 5;
priv_param_start_sec = 0x7C;
break;
case FLASH_SIZE_16M_MAP_512_512:
rf_cal_sec = 512 - 5;
priv_param_start_sec = 0x7C;
break;
case FLASH_SIZE_16M_MAP_1024_1024:
rf_cal_sec = 512 - 5;
priv_param_start_sec = 0xFC;
break;
case FLASH_SIZE_32M_MAP_512_512:
rf_cal_sec = 1024 - 5;
priv_param_start_sec = 0x7C;
break;
case FLASH_SIZE_32M_MAP_1024_1024:
rf_cal_sec = 1024 - 5;
priv_param_start_sec = 0xFC;
break;
case FLASH_SIZE_64M_MAP_1024_1024:
rf_cal_sec = 2048 - 5;
priv_param_start_sec = 0xFC;
break;
case FLASH_SIZE_128M_MAP_1024_1024:
rf_cal_sec = 4096 - 5;
priv_param_start_sec = 0xFC;
break;
default:
rf_cal_sec = 0;
priv_param_start_sec = 0;
break;
}
return rf_cal_sec;
}
void ICACHE_FLASH_ATTR
user_rf_pre_init(void)
{
}
/******************************************************************************
* FunctionName : user_init
* Description : entry of user application, init user function here
* Parameters : none
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_init(void)
{
i2c_master_gpio_init();
os_delay_us(60000);
os_delay_us(60000);
ds_SHT30_write(0x27,0x37);//写命令
i2c_SH1106_Init();
i2c_SH1106_P6x8Str(0,1,"WTF? 23333");
i2c_SH1106_P8x16Str(30, 3,"WTF? 23333");
i2c_SH1106_ShowStr(121, 7, ".", 1);
os_delay_us(60000);
os_delay_us(60000);
os_delay_us(60000);
os_delay_us(60000);
os_delay_us(60000);
os_delay_us(60000);
os_delay_us(60000);
os_delay_us(60000);
i2c_SH1106_DrawBMP(0,0,127,7,BMP);
}
end!