查看“OLED显示屏使用”的源代码
←
OLED显示屏使用
跳转至:
导航
、
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
== 目的 == 了解Microduino OLED,并掌握如何驱动OLED显示屏。 == 设备 == *'''[[Microduino-OLED/zh]]''' Microduino-Oled是基于SSD1306的0.96吋128x64 OLED显示模块。采用I2C接口,3.3V 电源供电。像素为128*64(128列*64行)。 *'''[[Microduino-CoreSTM32/zh]]''' Microduino-CoreSTM32小巧精悍,其内核来自于ARM公司具有突破性的Cortex-M3内核的32位闪存微控制器。该内核是专门设计于满足集高性能、低功耗、实时应用、具有竞争性价格于一体的嵌入式领域的要求。 *'''[[Microduino-Weather/zh|Microduino-Weather扩展板]] ''' Microduino Weather模块集成了三种传感器,分别是光照强度传感器(TSL2561),数字气压传感器(BMP180),数字温湿度传感器(AM2321)。采用I2C接口与核心相连。广泛用于气象监测。 * 其他硬件设备 :*OLED转接线 一根 :*USB数据线 一根 [[File:advance9_1.jpg|600px|center|thumb]] == 文档 == *12864Oled显示屏:2864HSWEG01 '''[[File:2864HSWEG01.pdf]]''' *驱动芯片:SSD1306 '''[[File:SSD1306-Revision 1.1.pdf]]''' == 原理图 == === I2C接口 === I2C(Inter-Integrated Circuit)总线是由PHILIPS公司开发的两线式串行总线。I2C 串行总线有两根信号线:一根双向的数据线 SDA;另一根是时钟线 SCL。所有接到 I2C 总线上的设备的串行数据都接到总线的 SDA 线,各设备的时钟线 SCL接到总线的 SCL,每个设备都有唯一的地址。 '''I2C通讯接法如下:''' [[File:advance9_2.jpg|600px|center|thumb]] ''' 原理图 :''' [[File:advance9_3.jpg|600px|center|thumb]] 本讲实际接线采用了[[Microduino-Weather/zh|Microduino Weather]]模块,将OLED转接线直接插在[[Microduino-Weather/zh|Microduino Weather]]模块上即可。 [[File:advance9_4.jpg|600px|center|thumb]] '''注意:OLED转接线不要用错。SCL接[[Microduino-CoreSTM32/zh]]的SCL,SDA接[[Microduino-CoreSTM32/zh]]的SDA,''' == 程序 == 用到的库:Wire库 <source lang="cpp"> #include <Wire.h> unsigned char show1[]= { 0x00,0x03,0x05,0x09,0x11,0xFF,0x11,0x89,0x05,0xC3,0x00,0xE0,0x00,0xF0,0x00,0xF8, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x44,0x28,0xFF,0x11,0xAA,0x44,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x83,0x01,0x38,0x44,0x82,0x92, 0x92,0x74,0x01,0x83,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x44,0xFF,0x01,0x7D, 0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x7D,0x01,0xFF,0x00, 0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00, 0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x3F,0x03,0x03, 0xF3,0x13,0x11,0x11,0x11,0x11,0x11,0x11,0x01,0xF1,0x11,0x61,0x81,0x01,0x01,0x01, 0x81,0x61,0x11,0xF1,0x01,0x01,0x01,0x01,0x41,0x41,0xF1,0x01,0x01,0x01,0x01,0x01, 0xC1,0x21,0x11,0x11,0x11,0x11,0x21,0xC1,0x01,0x01,0x01,0x01,0x41,0x41,0xF1,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x11,0x11,0x11,0x11,0x11,0xD3,0x33, 0x03,0x03,0x3F,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xE0,0x00,0x00, 0x7F,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x7F,0x00,0x00,0x01,0x06,0x18,0x06, 0x01,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x40,0x40,0x7F,0x40,0x40,0x00,0x00,0x00, 0x1F,0x20,0x40,0x40,0x40,0x40,0x20,0x1F,0x00,0x00,0x00,0x00,0x40,0x40,0x7F,0x40, 0x40,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x40,0x30,0x0C,0x03,0x00,0x00, 0x00,0x00,0xE0,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x07,0x06,0x06, 0x06,0x06,0x04,0x04,0x04,0x84,0x44,0x44,0x44,0x84,0x04,0x04,0x84,0x44,0x44,0x44, 0x84,0x04,0x04,0x04,0x84,0xC4,0x04,0x04,0x04,0x04,0x84,0x44,0x44,0x44,0x84,0x04, 0x04,0x04,0x04,0x04,0x84,0x44,0x44,0x44,0x84,0x04,0x04,0x04,0x04,0x04,0x84,0x44, 0x44,0x44,0x84,0x04,0x04,0x84,0x44,0x44,0x44,0x84,0x04,0x04,0x04,0x04,0x06,0x06, 0x06,0x06,0x07,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x10,0x18,0x14,0x12,0x11,0x00,0x00,0x0F,0x10,0x10,0x10, 0x0F,0x00,0x00,0x00,0x10,0x1F,0x10,0x00,0x00,0x00,0x08,0x10,0x12,0x12,0x0D,0x00, 0x00,0x18,0x00,0x00,0x0D,0x12,0x12,0x12,0x0D,0x00,0x00,0x18,0x00,0x00,0x10,0x18, 0x14,0x12,0x11,0x00,0x00,0x10,0x18,0x14,0x12,0x11,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80, 0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x7F,0x03,0x0C,0x30,0x0C,0x03,0x7F,0x00,0x00,0x38,0x54,0x54,0x58,0x00,0x00, 0x7C,0x04,0x04,0x78,0x00,0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xAA,0xAA,0xAA, 0x28,0x08,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x03,0x0C,0x30,0x0C,0x03,0x7F, 0x00,0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00,0x7F,0x02,0x04,0x08,0x10,0x7F,0x00 }; void setup() { Wire.begin(18,19);//18--SDA 19--SCL SerialUSB.println(" I2C Initializing... "); Initial_OLED(); SerialUSB.println(" OLED 42242Initializing... "); delay(5); } void loop() { fill_picture(0xff); delay(1000); fill_picture(0xf0); delay(1000); picture_1();//display a picture delay(1000); } void Write_IIC_Command(unsigned char IIC_Command) { Wire.beginTransmission(0x3C); //slave address 011110+SA0+RW - 0x3C or 0x3D Wire.send(0x00); //write command Wire.send(IIC_Command); Wire.endTransmission(); } void Write_IIC_Data(unsigned char IIC_Data) { Wire.beginTransmission(0x3C); Wire.send(0x40); //write data Wire.send(IIC_Data); Wire.endTransmission(); } void Initial_OLED() { Write_IIC_Command(0xAE); //display off Write_IIC_Command(0x20); //Set Memory Addressing Mode Write_IIC_Command(0x10); //00,Horizontal Addressing Mode;01,Vertical Addressing Mode;10,Page Addressing Mode (RESET);11,Invalid Write_IIC_Command(0xb0); //Set Page Start Address for Page Addressing Mode,0-7 Write_IIC_Command(0xc8); //Set COM Output Scan Direction Write_IIC_Command(0x00); //---set low column address Write_IIC_Command(0x10); //---set high column address Write_IIC_Command(0x40); //--set start line address Write_IIC_Command(0x81); //--set contrast control register Write_IIC_Command(0x7f); Write_IIC_Command(0xa1); //--set segment re-map 0 to 127 Write_IIC_Command(0xa6); //--set normal display Write_IIC_Command(0xa8); //--set multiplex ratio(1 to 64) Write_IIC_Command(0x3F); // Write_IIC_Command(0xa4); //0xa4,Output follows RAM content;0xa5,Output ignores RAM content Write_IIC_Command(0xd3); //-set display offset Write_IIC_Command(0x00); //-not offset Write_IIC_Command(0xd5); //--set display clock divide ratio/oscillator frequency Write_IIC_Command(0xf0); //--set divide ratio Write_IIC_Command(0xd9); //--set pre-charge period Write_IIC_Command(0x22); // Write_IIC_Command(0xda); //--set com pins hardware configuration Write_IIC_Command(0x12); Write_IIC_Command(0xdb); //--set vcomh Write_IIC_Command(0x20); Write_IIC_Command(0x8d); //--set DC-DC enable Write_IIC_Command(0x14); // Write_IIC_Command(0xaf); //--turn on oled panel } void fill_picture(unsigned char fill_Data) { unsigned char m,n; for(m=0;m<8;m++) { Write_IIC_Command(0xb0+m); //page0-page1 Write_IIC_Command(0x00); //low column start address Write_IIC_Command(0x10); //high column start address for(n=0;n<128;n++) { Write_IIC_Data(fill_Data); } } } void picture_1() { unsigned char x,y; unsigned int i=0; for(y=0;y<8;y++) { Write_IIC_Command(0xb0+y); Write_IIC_Command(0x00); Write_IIC_Command(0x10); for(x=0;x<128;x++) { Write_IIC_Data(show1[i++]); } } } </source> ''' 程序说明:''' *程序实现了两次刷屏和一次图片的循环显示。 *本教程需要使用Wire库,在初始化I2C时不能用Wire.begin()初始化,因为库里默认的SDA和SCL为20和21引脚,需要用Wire.begin(18,19)初始化,或者在Wire.h文件中的引脚定义改为18和19。 *Initial_OLED()为初始化OLED显示屏。 *show1[]数组保存一张图片,在picture_1()调用显示。 == 调试 == 步骤一:连接好电路。 步骤二:复制程序代码到Maple IDE编译。 步骤三:下载程序代码,观察OLED显示屏的变化。 == 结果 == == 视频 == 视频地址:
返回至
OLED显示屏使用
。
导航菜单
个人工具
创建账户
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
Welcome
首页
创客大赛
大赛详情
3D打印
安装月球车
图形化编程
操控月球车
升级月球车
编程工具下载
软件下载
Arduino
Processing
Mixly
Scratch
模块套件
Microduino 102
mCookie 102
mCookie 202
mCookie 302
IBC
其他
应用套件
四轴飞行器
平衡车
小车CUBE
音乐播放器
刷卡音乐播放器
wifi气象站
彩虹音乐触摸灯
分贝检测仪
迎门汇报
LED点阵时钟
LED点阵屏幕
硬件
mCookie
Sensor
Microduino
MicroWrt
MicroNux
MicroRobot-Core
MicroRobot-CoreESP
ideaBoard
ideaBox
MicroMV
MicroAI
帮助
常见问题
帮助
工具
链入页面
相关更改
特殊页面
页面信息