文章目录
一 oled显示软硬件准备工作
1 硬件准备
在了解以下内容时,可以先学习一下上一节I2C内容,能更好的理解下面内容
链接: 上一章节I2C内容
1.1 51单片机
只要是51类型都可以,开发板也可实现。
1.2 oled屏幕(0.96寸)四针脚(VCC GND SCL SDA)单色双色都可
1.3 杜邦线若干 (用来连接屏幕和单片机)
买母对母头 尽量多准备一些
2.软件准备
在了解以下内容时,可以先学习一下上一节I2C内容,能更好的理解下面内容
链接: 上一章节I2C内容
2.1 Keil C51
编译环境 接触过单片机会了解一些
2.2 取模工具
将图片和文字转化成代码
2.3开发文档手册
所有软件及开发手册,不了解的可以评论
二 对OLED写命令,写数据
在了解以下内容时,可以先学习一下上一节I2C内容,能更好的理解下面内容
链接: 上一章节I2C内容
2.1对oled写入
根据上图,来写代码
1.start
2.写入slave address
3.ack
4..写入controlbyte
5.ack
6.写入databyte
7.ack
8.写入stop
再写入slave address时,我们需要参考书册
从属地址遵循识别使用的开始条件。通过将SA0更改为低或高(D/C引脚充当SA0),从属地址为“b01111100”或“b0111101”作为SA0)(翻译内容)
slave address中
SA0我们可以置为0或1为从机地址
通过将R/W#位设置为逻辑“0”来建立写模式(翻译内容)
我们RW#需要写入0 设置为写入模式
则slave address 为 01111000
这样我们就设置好了oled地址和写入模式
2.2 对oled写入命令
在完成对oled slave address后 对control byte进行设置
对于co和D/c的写入我们需要参考手册
如果co设置为0,则后面只包含数据
D/c设置为0,为命令模式
1.start
2.写入slave address
3.ack
4..写入controlbyte
5.ack
6.写入databyte
7.ack
8.写入stop
根据如上序列写代码:
void Oled_Write_Cmd(char cmd)
{
strat();
send_byte(0x78);//写入slave address写入从机地址 0111 1000
ack();
send_byte(0x00);//control byte写入从机地址 0111 1000
ack();
send_byte(cmd);//写入控制命令
ack();
stop();
}
2.3 对oled写入数据
void Oled_Write_data(char datadata)
{
strat();
send_byte(0x78);//写入slave address写入从机地址 0111 1000
ack();
send_byte(0x40);//(0)(1)000000写入数据
ack();
send_byte(datadata);//写入数据
ack();
stop();
}
三 oled显示图片
3.1 oled 页寻址模式
通过参考手册可以看出 当A1 A0 为10时,为页寻址模式
当x2 x1 x0三个数可以表示八种情况 可以分别表示八页 第0页为1011 0000 16禁止为0x08;
其中一页为8个像素点
列可以由两组数表示 8为数为128个组合 表示128列 第0列为 0000 0000 和 0001 0000
十六进制表示为0x00和0x10
3.2 取模软件使用
3.2.1 输入文字
在文字输入区输入HELLO WORLD 然后按住shift+回车
3.2.2 设置文字大小
打开参数设置,设置成上图所示。
再打开其他选项,设置成上图所示
3.3.3
点击取模方式,打开c51取模
3.3 oled显示文字
由于字体是8*16大小,则需要显示两页。具体如下
生成A字符
#include <REGX51.H>
#include <intrins.h>
sbit scl = P0^1;
sbit sda = P0^3;
void strat()
{
scl = 1;
sda = 1;
_nop_();//此函数为空函数,耗时5微妙
sda = 0;
_nop_();
}
void stop()
{
scl = 1;
sda = 0;
_nop_();
sda = 1;
_nop_();
}
char ack()
{
char flag;
sda = 1;
scl = 1;
_nop_();
flag = sda;
_nop_();
scl = 0;
_nop_();
return flag;
}
void send_byte(char sendata)
{
int i;
for(i=0;i<8;i++){
scl = 0;
sda = sendata & 0x80;
_nop_();
scl = 1;
_nop_();
scl = 0;
_nop_();
sendata = sendata << 1;}
}
/*1. start()
2. 写入 b0111 1000 0x78
3. ACK
4. cotrol byte: (0)(0)000000 写入命令 (0)(1)000000写入数据
5. ACK
6. 写入指令/数据
7. ACK
8. STOP */
void Oled_Write_Cmd(char cmd)
{
strat();
send_byte(0x78);
ack();
send_byte(0x00);
ack();
send_byte(cmd);
ack();
stop();
}
void Oled_Write_data(char datadata)
{
strat();
send_byte(0x78);
ack();
send_byte(0x40);
ack();
send_byte(datadata);
ack();
stop();
}
void Oled_Init()//初始化 不需要学习根据文档手册写
{
Oled_Write_Cmd(0xAE);//--display off
Oled_Write_Cmd(0x00);//---set low column address
Oled_Write_Cmd(0x10);//---set high column address
Oled_Write_Cmd(0x40);//--set start line address
Oled_Write_Cmd(0xB0);//--set page address
Oled_Write_Cmd(0x81); // contract control
Oled_Write_Cmd(0xFF);//--128
Oled_Write_Cmd(0xA1);//set segment remap
Oled_Write_Cmd(0xA6);//--normal / reverse
Oled_Write_Cmd(0xA8);//--set multiplex ratio(1 to 64)
Oled_Write_Cmd(0x3F);//--1/32 duty
Oled_Write_Cmd(0xC8);//Com scan direction
Oled_Write_Cmd(0xD3);//-set display offset
Oled_Write_Cmd(0x00);//
Oled_Write_Cmd(0xD5);//set osc division
Oled_Write_Cmd(0x80);//
Oled_Write_Cmd(0xD8);//set area color mode off
Oled_Write_Cmd(0x05);//
Oled_Write_Cmd(0xD9);//Set Pre-Charge Period
Oled_Write_Cmd(0xF1);//
Oled_Write_Cmd(0xDA);//set com pin configuartion
Oled_Write_Cmd(0x12);//
Oled_Write_Cmd(0xDB);//set Vcomh
Oled_Write_Cmd(0x30);//
Oled_Write_Cmd(0x8D);//set charge pump enable
Oled_Write_Cmd(0x14);//
Oled_Write_Cmd(0xAF);//--turn on oled panel }
}
void Oled_Clear() //清屏函数
{
int i,j;
for(i=0;i<8;i++){
Oled_Write_Cmd(0xB0+i);
Oled_Write_Cmd(0x00);
Oled_Write_Cmd(0x10);
for(j = 0;j<128;j++){
Oled_Write_data(0);
}
}
}
char a1[] = {0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00};//上八为
char a2[] = {0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20};/下八为
//此部分需要取模
int main()
{
int i;
Oled_Init();
Oled_Write_Cmd(0x20);
Oled_Write_Cmd(0x02);//页寻址模式
Oled_Clear();
Oled_Write_Cmd(0xB0);//第0页
Oled_Write_Cmd(0x00);
Oled_Write_Cmd(0x10);//第0列
for(i=0;i<8;i++){
Oled_Write_data(a1[i]);
}
Oled_Write_Cmd(0xB1);//第1页
Oled_Write_Cmd(0x00);
Oled_Write_Cmd(0x10);//第0列
for(i=0;i<8;i++){
Oled_Write_data(a2[i]);
}
while(1);
}
效果如图
3.4显示图片
3.4.1 画图
用画图方式打开
点击调整大小
像素128*64
进行绘图
3.5取模显示图片:
画完后保存为单色为图
打开图像图标
选择打开图片:
c51取模
#include <REGX51.H>
#include <REGX51.H>
#include <intrins.h>
sbit scl = P0^1;
sbit sda = P0^3;
void strat()
{
scl = 1;
sda = 1;
_nop_();
sda = 0;
_nop_();
}
void stop()
{
scl = 1;
sda = 0;
_nop_();
sda = 1;
_nop_();
}
char ack()
{
char flag;
sda = 1;
scl = 1;
_nop_();
flag = sda;
_nop_();
scl = 0;
_nop_();
return flag;
}
void send_byte(char sendata)
{
int i;
for(i=0;i<8;i++){
scl = 0;
sda = sendata & 0x80;
_nop_();
scl = 1;
_nop_();
scl = 0;
_nop_();
sendata = sendata << 1;}
}
/*1. start()
2. 写入 b0111 1000 0x78
3. ACK
4. cotrol byte: (0)(0)000000 写入命令 (0)(1)000000写入数据
5. ACK
6. 写入指令/数据
7. ACK
8. STOP */
void Oled_Write_Cmd(char cmd)
{
strat();
send_byte(0x78);
ack();
send_byte(0x00);
ack();
send_byte(cmd);
ack();
stop();
}
void Oled_Write_data(char datadata)
{
strat();
send_byte(0x78);
ack();
send_byte(0x40);
ack();
send_byte(datadata);
ack();
stop();
}
void Oled_Init()
{
Oled_Write_Cmd(0xAE);//--display off
Oled_Write_Cmd(0x00);//---set low column address
Oled_Write_Cmd(0x10);//---set high column address
Oled_Write_Cmd(0x40);//--set start line address
Oled_Write_Cmd(0xB0);//--set page address
Oled_Write_Cmd(0x81); // contract control
Oled_Write_Cmd(0xFF);//--128
Oled_Write_Cmd(0xA1);//set segment remap
Oled_Write_Cmd(0xA6);//--normal / reverse
Oled_Write_Cmd(0xA8);//--set multiplex ratio(1 to 64)
Oled_Write_Cmd(0x3F);//--1/32 duty
Oled_Write_Cmd(0xC8);//Com scan direction
Oled_Write_Cmd(0xD3);//-set display offset
Oled_Write_Cmd(0x00);//
Oled_Write_Cmd(0xD5);//set osc division
Oled_Write_Cmd(0x80);//
Oled_Write_Cmd(0xD8);//set area color mode off
Oled_Write_Cmd(0x05);//
Oled_Write_Cmd(0xD9);//Set Pre-Charge Period
Oled_Write_Cmd(0xF1);//
Oled_Write_Cmd(0xDA);//set com pin configuartion
Oled_Write_Cmd(0x12);//
Oled_Write_Cmd(0xDB);//set Vcomh
Oled_Write_Cmd(0x30);//
Oled_Write_Cmd(0x8D);//set charge pump enable
Oled_Write_Cmd(0x14);//
Oled_Write_Cmd(0xAF);//--turn on oled panel }
}
void Oled_Clear()
{
int i,j;
for(i=0;i<8;i++){
Oled_Write_Cmd(0xB0+i);
Oled_Write_Cmd(0x00);
Oled_Write_Cmd(0x10);
for(j = 0;j<128;j++){
Oled_Write_data(0);
}
}
}
void Oled_Show_Image(unsigned char *image)
{
unsigned char i;
unsigned int j;
for(i=0;i<8;i++){
Oled_Write_Cmd(0xB0 + i);//page0--page7
//姣忎釜page浠?鍒?
Oled_Write_Cmd(0x00);
Oled_Write_Cmd(0x10);
//0鍒?27鍒楋紝渚濇鍐欏叆0锛屾瘡鍐欏叆鏁版嵁锛屽垪鍦板潃鑷姩鍋忕Щ
for(j = 128 * i; j<(128 * (i+1));j++){
Oled_Write_data(image[j]);
}
}
}
code unsigned char bmpImager[] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,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,0xC0,
0xE0,0x70,0x30,0x38,0x18,0x18,0x1C,0x0C,0x1C,0x18,0x18,0x18,0x18,0x18,0x10,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xE0,
0x70,0x38,0x18,0x1C,0x0C,0x0C,0x0E,0x0C,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0xFC,0x0C,0x0E,0x0E,0x06,0x06,0x06,
0x0E,0x0C,0x0C,0x0C,0x1C,0x18,0x38,0x70,0xE0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xE0,0x78,0x3E,0x0E,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xFC,0x1F,0x07,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,0xE0,0xF8,0x3E,0x0F,0x03,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,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x81,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xF0,0x7C,0x1E,0x07,0x03,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xF0,0xF8,0x1E,0x0F,0x03,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,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,0x01,0x03,0x03,0x07,0x06,0x06,0x06,
0x06,0x06,0x0E,0x0C,0x1C,0x18,0x78,0xF0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xFF,0xBF,0xC0,0xE0,0x60,0x60,0x60,0x60,
0x70,0x30,0x30,0x38,0x18,0x1C,0x0E,0x06,0x07,0x03,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x80,0xE0,0xF8,0x3F,0x0F,0x01,0x00,0x00,0x00,0x00,0x0F,0xFF,
0xF8,0x00,0x00,0x00,0x80,0xF0,0xFC,0x1F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x0F,0x1E,
0x38,0x70,0x60,0xE0,0xC0,0xC0,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xC0,0xC0,0xF8,
0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x30,0x30,0x30,0x30,0x30,0x30,
0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x39,0x1F,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x07,0x01,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x60,0x78,0x3E,0x0F,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,
0xFF,0xFC,0x78,0x1E,0x0F,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,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,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};//如果需要更改图像,就在这里面复制取模后的结果,其他部分无需更改
int main()
{
Oled_Init();
Oled_Write_Cmd(0x20);
Oled_Write_Cmd(0x02);
Oled_Clear();
Oled_Show_Image(bmpImager);
while(1);
}
效果如图:
3.6 显示kunkun跳舞动图
分别取模
#include <REGX51.H>
#include <REGX51.H>
#include <intrins.h>
sbit scl = P0^1;
sbit sda = P0^3;
void Delay500ms() //@11.0592MHz
{
unsigned char i, j, k;
_nop_();
i = 4;
j = 129;
k = 119;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void strat()
{
scl = 1;
sda = 1;
_nop_();
sda = 0;
_nop_();
}
void stop()
{
scl = 1;
sda = 0;
_nop_();
sda = 1;
_nop_();
}
char ack()
{
char flag;
sda = 1;
scl = 1;
_nop_();
flag = sda;
_nop_();
scl = 0;
_nop_();
return flag;
}
void send_byte(char sendata)
{
int i;
for(i=0;i<8;i++){
scl = 0;
sda = sendata & 0x80;
_nop_();
scl = 1;
_nop_();
scl = 0;
_nop_();
sendata = sendata << 1;}
}
/*1. start()
2. 写入 b0111 1000 0x78
3. ACK
4. cotrol byte: (0)(0)000000 写入命令 (0)(1)000000写入数据
5. ACK
6. 写入指令/数据
7. ACK
8. STOP */
void Oled_Write_Cmd(char cmd)
{
strat();
send_byte(0x78);
ack();
send_byte(0x00);
ack();
send_byte(cmd);
ack();
stop();
}
void Oled_Write_data(char datadata)
{
strat();
send_byte(0x78);
ack();
send_byte(0x40);
ack();
send_byte(datadata);
ack();
stop();
}
void Oled_Init()
{
Oled_Write_Cmd(0xAE);//--display off
Oled_Write_Cmd(0x00);//---set low column address
Oled_Write_Cmd(0x10);//---set high column address
Oled_Write_Cmd(0x40);//--set start line address
Oled_Write_Cmd(0xB0);//--set page address
Oled_Write_Cmd(0x81); // contract control
Oled_Write_Cmd(0xFF);//--128
Oled_Write_Cmd(0xA1);//set segment remap
Oled_Write_Cmd(0xA6);//--normal / reverse
Oled_Write_Cmd(0xA8);//--set multiplex ratio(1 to 64)
Oled_Write_Cmd(0x3F);//--1/32 duty
Oled_Write_Cmd(0xC8);//Com scan direction
Oled_Write_Cmd(0xD3);//-set display offset
Oled_Write_Cmd(0x00);//
Oled_Write_Cmd(0xD5);//set osc division
Oled_Write_Cmd(0x80);//
Oled_Write_Cmd(0xD8);//set area color mode off
Oled_Write_Cmd(0x05);//
Oled_Write_Cmd(0xD9);//Set Pre-Charge Period
Oled_Write_Cmd(0xF1);//
Oled_Write_Cmd(0xDA);//set com pin configuartion
Oled_Write_Cmd(0x12);//
Oled_Write_Cmd(0xDB);//set Vcomh
Oled_Write_Cmd(0x30);//
Oled_Write_Cmd(0x8D);//set charge pump enable
Oled_Write_Cmd(0x14);//
Oled_Write_Cmd(0xAF);//--turn on oled panel }
}
void Oled_Clear()
{
int i,j;
for(i=0;i<8;i++){
Oled_Write_Cmd(0xB0+i);
Oled_Write_Cmd(0x00);
Oled_Write_Cmd(0x10);
for(j = 0;j<128;j++){
Oled_Write_data(0);
}
}
}
void Oled_Show_Image(unsigned char *image)
{
unsigned char i;
unsigned int j;
for(i=0;i<8;i++){
Oled_Write_Cmd(0xB0 + i);//page0--page7
//姣忎釜page浠?鍒?
Oled_Write_Cmd(0x00);
Oled_Write_Cmd(0x10);
//0鍒?27鍒楋紝渚濇鍐欏叆0锛屾瘡鍐欏叆鏁版嵁锛屽垪鍦板潃鑷姩鍋忕Щ
for(j = 128 * i; j<(128 * (i+1));j++){
Oled_Write_data(image[j]);
}
}
}
code unsigned char bmpImager1[] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,
0xFE,0xFC,0xFE,0xFE,0xFC,0xFE,0xFE,0xFE,0xFE,0xFC,0xFC,0xF8,0xF0,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0xE0,0x3C,0xFE,0x06,0x02,0x1E,0x72,0xC3,0x07,
0x07,0x0F,0x1F,0x3B,0x79,0xF3,0xE7,0x81,0x64,0x1B,0x00,0x03,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,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x18,0x7E,0xE7,0x00,0xFE,0x03,0x00,0x00,0x00,0x00,0x03,0x0E,
0xF8,0x08,0x08,0x08,0x08,0x08,0x0D,0x0F,0xC7,0xFA,0x06,0x0C,0x78,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0x07,0x1D,0xF8,0xF0,0x60,0x60,0x20,0x20,0x20,
0x3F,0x20,0x20,0x20,0x60,0x60,0xE0,0xF0,0xFF,0x60,0x30,0x18,0x0C,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,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0x38,0x0F,0x03,0x00,0x00,0x00,0x80,0xC0,0xE0,
0x70,0x70,0xE0,0xC0,0x80,0x00,0x00,0x01,0x03,0x1E,0x38,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0x3C,0x07,0x01,0x00,0xC0,0x60,0x30,0x1C,0x06,0x03,0x01,0x00,
0x00,0x00,0x00,0x01,0x03,0x06,0x1C,0x30,0xE0,0x80,0x00,0x01,0x07,0x1C,0x70,0xC0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xF8,0x3F,0x01,0x00,0xC0,0xF0,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x0F,0x1C,0x78,0xF0,0x80,0x01,
0x07,0x1C,0xF0,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,0x00,0x00,0x00,0x00,0x00,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,
0xE6,0xEF,0xF8,0xFC,0xFC,0xCF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xCF,0xFC,
0xF8,0xF8,0xE8,0xEF,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,
};
code unsigned char bmpImager2[] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,
0xFE,0xFC,0xFE,0xFE,0xFC,0xFE,0x7E,0x3E,0xFE,0xFC,0xFC,0x38,0xF0,0x60,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0xE0,0x20,0x30,0x10,0x18,0x18,0xF8,0xC8,0x08,0x08,
0x17,0x1F,0x1F,0x0F,0x0F,0x0F,0x0E,0x18,0x11,0x18,0x3D,0x72,0x61,0xC0,0xC0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0x38,0x0E,0x03,0xC0,0x70,0x38,0xE0,0x00,0x00,0x00,0x01,0x03,0x0E,
0xF8,0x0C,0x0C,0x0C,0x0C,0x18,0x30,0x60,0xC0,0xF0,0x8E,0x80,0x00,0x80,0xF7,0x3E,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0x03,0x06,0x0C,0x3B,0x66,0xDC,0xFF,0xF0,0x60,0x60,0x20,0x20,0x20,
0x3F,0x20,0x20,0x20,0x60,0x60,0xE0,0xF0,0xFF,0x30,0x0C,0x07,0x03,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,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0x38,0x0F,0x03,0x00,0x00,0x00,0x80,0xC0,0xE0,
0x70,0x70,0xE0,0xC0,0x80,0x00,0x00,0x01,0x03,0x1E,0x38,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0x3C,0x07,0x01,0x00,0xC0,0x60,0x30,0x1C,0x06,0x03,0x01,0x00,
0x00,0x00,0x00,0x01,0x03,0x06,0x1C,0x30,0xE0,0x80,0x00,0x01,0x07,0x1C,0x70,0xC0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xF8,0x3F,0x01,0x00,0xC0,0xF0,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x0F,0x1C,0x78,0xF0,0x80,0x01,
0x07,0x1C,0xF0,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,0x00,0x00,0x00,0x00,0x00,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,
0xE6,0xEF,0xF8,0xFC,0xFC,0xCF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xCF,0xFC,
0xF8,0xF8,0xE8,0xEF,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,
};//两张图片交替显示
int main()
{
Oled_Init();
Oled_Write_Cmd(0x20);
Oled_Write_Cmd(0x02);
Oled_Clear();
while(1){
Oled_Show_Image(bmpImager1);
// Oled_Clear();
Oled_Show_Image(bmpImager2); //两张图片交替显示
// Oled_Clear();
}
}
感谢各位观看!