其他分享
首页 > 其他分享> > 1.3寸IIC OLED SSD1106控制的oled显示问题解决方案

1.3寸IIC OLED SSD1106控制的oled显示问题解决方案

作者:互联网

1.3寸IIC OLED SSD1106 控制的oled显示问题解决方案

首先鸣谢:电子发烧友论坛帖子

在使用1.3寸IIC OLED SSD1106屏幕作为oled显示是,难免会碰到一些问题

在使用Arduino开发环境下使用SH1106库驱动,那么则是:SH1106Wire.h
引脚定义和地址:
const int I2C_DISPLAY_ADDRESS = 0x3c; //I2c地址默认 SH1106Wire display(I2C_DISPLAY_ADDRESS, SDA_PIN, SDC_PIN); // 1.3寸用这个

*在使用U8g2库驱动的时候正确定义方式:
U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

在keil开发环境下,则需要注意改的地方:WriteCmd(0x02)有两处!
WriteCmd(0xAE); //关闭显示display off
	WriteCmd(0x20);	//Set Memory Addressing Mode	
	WriteCmd(0x10);	//00,Horizontal Addressing Mode;01,Vertical Addressing Mode;10,Page Addressing Mode (RESET);11,Invalid
	WriteCmd(0xb0);	//Set Page Start Address for Page Addressing Mode,0-7
	WriteCmd(0xc8);	//Set COM Output Scan Direction
	WriteCmd(0x02); //-设置低位列地址set low column address 注意:0.96屏幕从0x00开始写数据,1.3寸屏幕从0x02开始写数据
	WriteCmd(0x10); //-设置高位列地址set high column address
	WriteCmd(0x40); //--set start line address
	WriteCmd(0x81); //--set contrast control register
	WriteCmd(0xff); //亮度调节 0x00~0xff
	WriteCmd(0xa1); //--set segment re-map 0 to 127
	WriteCmd(0xa6); //--set normal display
	WriteCmd(0xa8); //--set multiplex ratio(1 to 64)
	WriteCmd(0x3F); //
	WriteCmd(0xa4); //0xa4,Output follows RAM content;0xa5,Output ignores RAM content
	WriteCmd(0xd3); //-设置显示偏移set display offset
	WriteCmd(0x00); //-没有偏移not offset
	WriteCmd(0xd5); //-设置时钟分频因子,震荡频率set display clock divide ratio/oscillator frequency
	WriteCmd(0xf0); //--set divide ratio
	WriteCmd(0xd9); //--set pre-charge period
	WriteCmd(0x22); //
	WriteCmd(0xda); //--设置COM硬件引脚配置set com pins hardware configuration
	WriteCmd(0x12);//[5:4]配置
	WriteCmd(0xdb); //--set vcomh
	WriteCmd(0x20); //0x20,0.77xVcc
	WriteCmd(0x8d); //-电荷泵设置set DC-DC enable
	WriteCmd(0x14); //bit2,开启/关闭
	WriteCmd(0xaf); //-开启显示 turn on oled panel
	OLED_CLS();
}
/*
1.3寸OLED SSD1106往0x00地址写数据前要往0x40地址写三个命令,
0XB0-7是页地址,
0X00~0X0F是低位列地址,
0X10~0X1F是高位列地址.
解决方法是写数据前设置地址的0x00改为0x02.

*/

void OLED_CLS(void)//清屏 全部发送0x00
{
	unsigned char m,n;
	for(m=0;m<8;m++)
	{
		WriteCmd(0xb0+m);		//page0-page8
		WriteCmd(0x02);	//low  column start address1.3寸屏幕发送地址是从0x02开始的,0.96屏幕是从0x00地址开始的特别注意个地方!!!!
		WriteCmd(0x10);			//high column start address
		for(n=0;n<128;n++)
		{
			WriteDat(0x00);
		}
	}
}

void OLED_ON(void)
{
	WriteCmd(0X8D);  //设置电荷泵
	WriteCmd(0X14);  //开启电荷泵
	WriteCmd(0XAF);  //OLED唤醒
}

void OLED_OFF(void)
{
	WriteCmd(0X8D);  //设置电荷泵
	WriteCmd(0X10);  //关闭电荷泵
	WriteCmd(0XAE);  //OLED休眠
}

标签:set,WriteCmd,--,1.3,0x00,oled,SSD1106,OLED,地址
来源: https://blog.csdn.net/weixin_42880082/article/details/115377476