51单片机用IIC协议实现OLED的显示

IIC协议

IIC协议概述
IIC全称Inter-Integrated Circuit (集成电路总线)是由PHILIPS公司在80年代开发的两线式串行总线,用于连接微控制器及其外围设备。IIC属于半双工同步通信方式

构成
IIC串行总线一般有两根信号线,一根是双向的数据线SDA,另一根是时钟线SCL,其时钟信号是由主控器件产生。所有接到IIC总线设备上的串行数据SDA都接到总线的SDA上,各设备的时钟线SCL接到总线的SCL上。对于并联在一条总线上的每个IC都有唯一的地址。

51单片机用IIC协议实现OLED的显示_第1张图片

IIC总线在传输数据的过程中一共有三种类型信号,分别为:开始信号、结束信号和应答信号。
//起始位,停止位,数据位,速度
这些信号中,起始信号是必需的,结束信号和应答信号

起始和终止信号时序图:
51单片机用IIC协议实现OLED的显示_第2张图片

应答信号
发送器每发送一个字节(8个bit),就在时钟脉冲9期间释放数据线,由接收器反馈一个应答信号。
应答信号为低电平时,规定为有效应答位(ACK,简称应答位),表示接收器已经成功地接收了该字
节;
应答信号为高电平时,规定为非应答位(NACK),一般表示接收器接收该字节没有成功

应答信号时序图:
51单片机用IIC协议实现OLED的显示_第3张图片

数据发送时序图:
51单片机用IIC协议实现OLED的显示_第4张图片

IIC协议实现代码:

#include “reg52.h”
#include “intrins.h”
sbit scl = P0^1;
sbit sda = P0^3;

void IIC_Start()
{
scl = 1;
sda = 1;
nop();
sda = 0;
nop();

}

void IIC_Stop()
{
sda = 0;
scl = 1;
nop();
sda = 1;
nop();

}

char IIC_ACK()
{
char flag;
sda = 1;//时钟脉冲9期间释放数据线
nop();
scl = 1;
nop();
flag = sda;
nop();
scl = 0;

return flag;

}

void IIC_Send_Byte(char dataSend)
{
char i;
for(i =0;i<8;i++){

	scl = 0;//scl拉低,让sda做好数据准备
	sda = dataSend & 0x80; //让sda等于dataSend的最高位
	_nop_();//发送数据建立时间
	scl = 1;//scl拉高,开始传输
	_nop_();//数据发送的时间
	scl =0;//发送完毕,拉低scl
	_nop_();//等待下一位数据
	dataSend = dataSend << 1;
	
}

}

void Oled_Write_Cmd(char dataCmd)
{

//1. start()
IIC_Start();
//2. 写入从机地址: b0111 1000: 0x78
IIC_Send_Byte(0x78);
//3. ACK
IIC_ACK();
//4. cotrol byte: (0)(0)000000 写入命令   (0)(1)000000写入数据
IIC_Send_Byte(0x00);
//5. ACK
IIC_ACK();
//6. 写入指令/数据
IIC_Send_Byte(dataCmd);
//7. ACK
IIC_ACK();
//8. STOP
IIC_Stop();	

}

void Oled_Write_Data(char dataData)
{

//1. start()
IIC_Start();
//2. 写入从机地址: b0111 1000: 0x78
IIC_Send_Byte(0x78);
//3. ACK
IIC_ACK();
//4. cotrol byte: (0)(0)000000 写入命令   (0)(1)000000写入数据
IIC_Send_Byte(0x40);
//5. ACK
IIC_ACK();
//6. 写入指令/数据
IIC_Send_Byte(dataData);
//7. ACK
IIC_ACK();
//8. STOP
IIC_Stop();	

}

void main()
{

}

IIC协议结合OLED显示屏显示一个字符代码:

#include “reg52.h”
#include “intrins.h”
sbit scl = P0^1;
sbit sda = P0^3;

/*--  文字:  A  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
char A1[8]={0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00};
char A2[8]={0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20};

void IIC_Start()
{
scl = 0;
scl = 1;
sda = 1;
nop();
sda = 0;
nop();

}

void IIC_Stop()
{
scl = 0;
sda = 0;
scl = 1;
nop();
sda = 1;
nop();

}

char IIC_ACK()
{
char flag;
sda = 1;//时钟脉冲9期间释放数据线
nop();
scl = 1;
nop();
flag = sda;
nop();
scl = 0;

return flag;

}

void IIC_Send_Byte(char dataSend)
{
char i;
for(i =0;i<8;i++){

	scl = 0;//scl拉低,让sda做好数据准备
	sda = dataSend & 0x80; //让sda等于dataSend的最高位
	_nop_();//发送数据建立时间
	scl = 1;//scl拉高,开始传输
	_nop_();//数据发送的时间
	scl =0;//发送完毕,拉低scl
	_nop_();//等待下一位数据
	dataSend = dataSend << 1;
	
}

}

void Oled_Write_Cmd(char dataCmd)
{

//1. start()
IIC_Start();
//2. 写入从机地址: b0111 1000: 0x78
IIC_Send_Byte(0x78);
//3. ACK
IIC_ACK();
//4. cotrol byte: (0)(0)000000 写入命令   (0)(1)000000写入数据
IIC_Send_Byte(0x00);
//5. ACK
IIC_ACK();
//6. 写入指令/数据
IIC_Send_Byte(dataCmd);
//7. ACK
IIC_ACK();
//8. STOP
IIC_Stop();	

}

void Oled_Write_Data(char dataData)
{

//1. start()
IIC_Start();
//2. 写入从机地址: b0111 1000: 0x78
IIC_Send_Byte(0x78);
//3. ACK
IIC_ACK();
//4. cotrol byte: (0)(0)000000 写入命令   (0)(1)000000写入数据
IIC_Send_Byte(0x40);
//5. ACK
IIC_ACK();
//6. 写入指令/数据
IIC_Send_Byte(dataData);
//7. ACK
IIC_ACK();
//8. STOP
IIC_Stop();	

}

void Oled_Init(void){

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()//清屏
{
char i;
int j;
for(i=0;i<8;i++){
Oled_Write_Cmd(0xB0 + i); //page0 - page7
Oled_Write_Cmd(0x00);//每个page从0列开始
Oled_Write_Cmd(0x10);
for(j=0;j<128;j++){//每个page从0-127列,依次写入0,每写入数据,列地址自动偏移
Oled_Write_Data(0);
}

}

}

void main()
{
int i;
//1、OLED初始化
Oled_Init();
//2、选择一个位置
//2、1确认为页寻址模式 0x20,0x02
Oled_Write_Cmd(0x20);
Oled_Write_Cmd(0x02);
Oled_Clear();//清屏
//2、2选择page0 10110000
Oled_Write_Cmd(0xB0);
Oled_Write_Cmd(0x00);
Oled_Write_Cmd(0x10);
for(i=0;i<8;i++){
Oled_Write_Data(A1[i]);
}

Oled_Write_Cmd(0xB1);
Oled_Write_Cmd(0x00);
Oled_Write_Cmd(0x10);
for(i=0;i<8;i++){
	Oled_Write_Data(A2[i]);
}


while(1);//防止程序退出

}

效果图:

51单片机用IIC协议实现OLED的显示_第5张图片

IIC协议结合OLED显示屏显示行个字符代码:

#include “reg52.h”
#include “intrins.h”
sbit scl = P0^1;
sbit sda = P0^3;

/– 文字: 谢 –/
/– 宋体12; 此字体下对应的点阵为:宽x高=16x16 –/
code char x1[16]={0x40,0x42,0xCC,0x00,0x00,0xFC,0x56,0x55,0xFC,0x80,0x10,0x10,0xFF,0x10,0x10,0x00};
code char x2[16]={0x00,0x00,0x3F,0x10,0x2A,0x13,0x4A,0x86,0x7F,0x00,0x43,0x80,0x7F,0x00,0x00,0x00};

/– 文字: 方 –/
/– 宋体12; 此字体下对应的点阵为:宽x高=16x16 –/
code char f1[16]={0x08,0x08,0x08,0x08,0x08,0xF8,0x89,0x8E,0x88,0x88,0x88,0x88,0x08,0x08,0x08,0x00};
code char f2[16]={0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x00,0x40,0x80,0x40,0x3F,0x00,0x00,0x00,0x00};

/– 文字: 静 –/
/– 宋体12; 此字体下对应的点阵为:宽x高=16x16 –/
code char j1[16]={0x44,0x54,0x54,0x7F,0x54,0x54,0x44,0x20,0x28,0x27,0xE4,0x34,0x2C,0xE0,0x00,0x00};
code char j2[16]={0x00,0xFF,0x15,0x55,0x95,0x7F,0x00,0x09,0x49,0x89,0x7F,0x09,0x09,0x1F,0x01,0x00};

/– 文字: 帅 –/
/– 宋体12; 此字体下对应的点阵为:宽x高=16x16 –/
code char s1[16]={0x00,0xFC,0x00,0x00,0xFF,0x00,0x00,0xF0,0x10,0x10,0xFF,0x10,0x10,0xF0,0x00,0x00};
code char s2[16]={0x00,0x87,0x40,0x30,0x0F,0x00,0x00,0x1F,0x00,0x00,0xFF,0x08,0x10,0x0F,0x00,0x00};

void IIC_Start()
{
scl = 0;
scl = 1;
sda = 1;
nop();
sda = 0;
nop();

}

void IIC_Stop()
{
scl = 0;
sda = 0;
scl = 1;
nop();
sda = 1;
nop();

}

char IIC_ACK()
{
char flag;
sda = 1;//时钟脉冲9期间释放数据线
nop();
scl = 1;
nop();
flag = sda;
nop();
scl = 0;

return flag;

}

void IIC_Send_Byte(char dataSend)
{
char i;
for(i =0;i<8;i++){

	scl = 0;//scl拉低,让sda做好数据准备
	sda = dataSend & 0x80; //让sda等于dataSend的最高位
	_nop_();//发送数据建立时间
	scl = 1;//scl拉高,开始传输
	_nop_();//数据发送的时间
	scl =0;//发送完毕,拉低scl
	_nop_();//等待下一位数据
	dataSend = dataSend << 1;
	
}

}

void Oled_Write_Cmd(char dataCmd)
{

//1. start()
IIC_Start();
//2. 写入从机地址: b0111 1000: 0x78
IIC_Send_Byte(0x78);
//3. ACK
IIC_ACK();
//4. cotrol byte: (0)(0)000000 写入命令   (0)(1)000000写入数据
IIC_Send_Byte(0x00);
//5. ACK
IIC_ACK();
//6. 写入指令/数据
IIC_Send_Byte(dataCmd);
//7. ACK
IIC_ACK();
//8. STOP
IIC_Stop();	

}

void Oled_Write_Data(char dataData)
{

//1. start()
IIC_Start();
//2. 写入从机地址: b0111 1000: 0x78
IIC_Send_Byte(0x78);
//3. ACK
IIC_ACK();
//4. cotrol byte: (0)(0)000000 写入命令   (0)(1)000000写入数据
IIC_Send_Byte(0x40);
//5. ACK
IIC_ACK();
//6. 写入指令/数据
IIC_Send_Byte(dataData);
//7. ACK
IIC_ACK();
//8. STOP
IIC_Stop();	

}

void Oled_Init(void){

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()//清屏
{
char i;
int j;
for(i=0;i<8;i++){
Oled_Write_Cmd(0xB0 + i); //page0 - page7
Oled_Write_Cmd(0x00);//每个page从0列开始
Oled_Write_Cmd(0x10);
for(j=0;j<128;j++){//每个page从0-127列,依次写入0,每写入数据,列地址自动偏移
Oled_Write_Data(0);
}

}

}

void main()
{
int i;
//1、OLED初始化
Oled_Init();
//2、选择一个位置
//2、1确认为页寻址模式 0x20,0x02
Oled_Write_Cmd(0x20);
Oled_Write_Cmd(0x02);
Oled_Clear();//清屏
//2、2选择page0 10110000
Oled_Write_Cmd(0xB0);
Oled_Write_Cmd(0x00);
Oled_Write_Cmd(0x10);
for(i=0;i<16;i++){
Oled_Write_Data(x1[i]);
}
for(i=0;i<16;i++){
Oled_Write_Data(f1[i]);
}
for(i=0;i<16;i++){
Oled_Write_Data(j1[i]);
}
for(i=0;i<16;i++){
Oled_Write_Data(s1[i]);
}

Oled_Write_Cmd(0xB1);
Oled_Write_Cmd(0x00);
Oled_Write_Cmd(0x10);
for(i=0;i<16;i++){
	Oled_Write_Data(x2[i]);
}
for(i=0;i<16;i++){
	Oled_Write_Data(f2[i]);
}
for(i=0;i<16;i++){
	Oled_Write_Data(j2[i]);
}
for(i=0;i<16;i++){
	Oled_Write_Data(s2[i]);
}



while(1);//防止程序退出

}

效果图:

51单片机用IIC协议实现OLED的显示_第6张图片

IIC协议结合OLED显示屏显示图片代码

#include “reg52.h”
#include “intrins.h”
sbit scl = P0^1;
sbit sda = P0^3;

void IIC_Start()
{
scl = 0;
scl = 1;
sda = 1;
nop();
sda = 0;
nop();

}

void IIC_Stop()
{
scl = 0;
sda = 0;
scl = 1;
nop();
sda = 1;
nop();

}

char IIC_ACK()
{
char flag;
sda = 1;//时钟脉冲9期间释放数据线
nop();
scl = 1;
nop();
flag = sda;
nop();
scl = 0;

return flag;

}

void IIC_Send_Byte(char dataSend)
{
char i;
for(i =0;i<8;i++){

	scl = 0;//scl拉低,让sda做好数据准备
	sda = dataSend & 0x80; //让sda等于dataSend的最高位
	_nop_();//发送数据建立时间
	scl = 1;//scl拉高,开始传输
	_nop_();//数据发送的时间
	scl =0;//发送完毕,拉低scl
	_nop_();//等待下一位数据
	dataSend = dataSend << 1;
	
}

}

void Oled_Write_Cmd(char dataCmd)
{

//1. start()
IIC_Start();
//2. 写入从机地址: b0111 1000: 0x78
IIC_Send_Byte(0x78);
//3. ACK
IIC_ACK();
//4. cotrol byte: (0)(0)000000 写入命令   (0)(1)000000写入数据
IIC_Send_Byte(0x00);
//5. ACK
IIC_ACK();
//6. 写入指令/数据
IIC_Send_Byte(dataCmd);
//7. ACK
IIC_ACK();
//8. STOP
IIC_Stop();	

}

void Oled_Write_Data(char dataData)
{

//1. start()
IIC_Start();
//2. 写入从机地址: b0111 1000: 0x78
IIC_Send_Byte(0x78);
//3. ACK
IIC_ACK();
//4. cotrol byte: (0)(0)000000 写入命令   (0)(1)000000写入数据
IIC_Send_Byte(0x40);
//5. ACK
IIC_ACK();
//6. 写入指令/数据
IIC_Send_Byte(dataData);
//7. ACK
IIC_ACK();
//8. STOP
IIC_Stop();	

}

void Oled_Init(void){

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()//清屏
{
char i;
int j;
for(i=0;i<8;i++){
Oled_Write_Cmd(0xB0 + i); //page0 - page7
Oled_Write_Cmd(0x00);//每个page从0列开始
Oled_Write_Cmd(0x10);
for(j=0;j<128;j++){//每个page从0-127列,依次写入0,每写入数据,列地址自动偏移
Oled_Write_Data(0);
}

}

}

code unsigned char bmpImager[]={
/– 调入了一幅图像:C:\Users\xfj\Pictures\Saved Pictures\无标题.bmp –/
/– 宽度x高度=128x64 12888–/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x0C,0x18,0x70,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x80,0xE0,0x3C,
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0x60,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0xF6,0x18,0x0C,0x04,0x37,0x02,0x02,
0x02,0x02,0x02,0x36,0x64,0x04,0x0E,0x1B,0xE1,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x06,0x0C,0x8C,0xF5,0x05,0x05,
0x05,0x05,0x05,0x04,0x04,0x06,0x06,0xFF,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,0x80,0x80,0x80,0xC0,0x40,0x40,
0x60,0x20,0x20,0x20,0x30,0xF0,0x20,0x30,0x10,0x18,0x0C,0xE6,0x23,0xE0,0x00,0x00,
0x00,0x00,0x00,0xF0,0x10,0x30,0xE0,0x07,0x3C,0x60,0x40,0x40,0xC0,0xC0,0xC0,0xC0,
0x40,0x40,0x20,0x20,0x20,0x60,0x40,0x40,0x40,0x40,0x40,0x40,0xC0,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,0x00,0x00,0x00,0x00,
0x00,0x40,0xE0,0x90,0x88,0x8C,0x86,0x82,0x83,0x81,0x81,0x80,0x80,0xC0,0x60,0x20,
0x30,0x18,0x08,0x0C,0x04,0xFF,0x80,0x00,0x00,0xF0,0x9E,0x87,0xC7,0x7D,0x00,0x00,
0x70,0xD8,0x88,0x8F,0x9E,0x93,0xB1,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x03,0x86,0xFC,0x38,0x20,0x20,0x20,0x30,0x10,0x10,0x10,0x18,0x08,0x08,0x09,0x07,
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0xF1,0x1F,0x02,0x02,0x02,0x06,0x04,0x04,0x04,
0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0xE4,0x3C,0x0E,0x02,0x02,0x02,
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,0xC0,0x7C,0x37,0x30,0x20,0x60,0x40,0x40,0x80,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x30,0x30,0x20,0x20,0x60,
0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x20,0x20,0x20,0xF8,0x20,0x20,0x20,0x80,0x40,0x20,0x00,0x00,0x08,0x08,0x08,0x08,
0x08,0xF8,0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x08,0x1F,0x30,0x20,0x20,0x20,0x20,0x30,0x10,0x18,0x0D,0x07,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x02,0x02,0x04,0x04,
0x06,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x09,
0x09,0x05,0x55,0x51,0x53,0x49,0x49,0x45,0x61,0x01,0x00,0x00,0x40,0x41,0x41,0x41,
0x41,0x7F,0x41,0x41,0x41,0x41,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00

};

void Oled_Show_Image(unsigned char *image)//清屏
{
char i;
unsigned int j;
for(i=0;i<8;i++){
Oled_Write_Cmd(0xB0 + i); //page0 - page7
Oled_Write_Cmd(0x00);//每个page从0列开始
Oled_Write_Cmd(0x10);
for(j=(i * 128);j<(128 * (i+1));j++){//每个page从0-127列,依次写入0,每写入数据,列地址自动偏移
Oled_Write_Data(image[j]);
}

}

}

void main()
{

//1、OLED初始化
Oled_Init();
//2、选择一个位置
//2、1确认为页寻址模式 0x20,0x02
Oled_Write_Cmd(0x20);
Oled_Write_Cmd(0x02);
Oled_Clear();//清屏

Oled_Show_Image(bmpImager);


while(1);//防止程序退出

}

效果图:

51单片机用IIC协议实现OLED的显示_第7张图片

你可能感兴趣的:(51单片机笔记,51单片机)