参考博客:https://blog.csdn.net/qq_42992084/article/details/89977888
void OLED_Init(void) { OLED_Config(); OLED_SCK(HIGH); // 空闲态时,SCLK处于高电平 OLED_CS(HIGH); // 关闭选择输入 /* 从上电到下面开始初始化要有足够的时间,即等待 RC复位完毕 */ OLED_RST(LOW); // 复位(低电平有效) OLED_Delay_ms(100); OLED_RST(HIGH); OLED_Delay_ms(30); /* //官方的驱动流程 OLED_Write_Cmd(0xA8); // 设置多路传输比率 -- set multiplex ratio (16 to 63) OLED_Write_Cmd(0x3F); // \ 1 / 64 duty OLED_Write_Cmd(0xD3); // 设置显示偏移 -- set display offset (0x00~0x3F) OLED_Write_Cmd(0x00); // \ not offset 偏移值是 0 OLED_Write_Cmd(0x40); // 设置设置屏幕(GDDRAM)起始行 -- Set Display Start Line (0x40~0x7F) /配置显示方向 OLED_Write_Cmd(0xA1); // 设置段重映射 -- Set SEG / Column Mapping 0xA0左右反置(复位值) 0xA1正常(重映射值) OLED_Write_Cmd(0xC8); // 设置行输出扫描方向 -- Set COM / Row Scan Direction 0xc0上下反置(复位值) 0xC8正常(重映射值) OLED_Write_Cmd(0xDA); // 设置列引脚硬件配置 -- set com pins hardware configuration OLED_Write_Cmd(0x12); // \ Sequential COM pin configuration,Enable COM Left/Right remap OLED_Write_Cmd(0x81); // 设置对比度 -- set contrast control register (0x00~0x100) OLED_Write_Cmd(0xCF); // \ Set SEG Output Current Brightness //根据RAM 内容显示 OLED_Write_Cmd(0xA4); // 全局显示开启(黑屏/亮屏) (0xA4 根据RAM 内容显示 / 0xA5 每个oled都点亮 全部显示) //正常显示方式(不是反现) OLED_Write_Cmd(0xA6); // 设置显示方式(正常/反显) -- set normal display (0xA6 / 0xA7) //设置显示时钟分频因子/振荡器频率 OLED_Write_Cmd(0xD5); // 设置显示时钟分频因子/振荡器频率 -- set display clock divide ratio/oscillator frequency OLED_Write_Cmd(0x80); // A[3:0] 分频因子, A[7:4] 震荡频率设置 Set Clock as 100 Frames/Sec OLED_Write_Cmd(0x8D); // 电荷泵设置 -- set Charge Pump enable / disable (0x14 / 0x10) OLED_Write_Cmd(0x14); // \ 启用电荷泵 Enable charge pump during display on OLED_Write_Cmd(0xAF); // 打开OLED -- turn on oled panel : OXAE 关闭OLED 休眠模式 0xaf 打开oled //官方的驱动流程 */ OLED_Write_Cmd(0xAE); // 关闭OLED -- turn off oled panel OLED_Write_Cmd(0xD5); // 设置显示时钟分频因子/振荡器频率 -- set display clock divide ratio/oscillator frequency OLED_Write_Cmd(0x80); // A[3:0] 分频因子, A[7:4] 震荡频率设置 Set Clock as 100 Frames/Sec OLED_Write_Cmd(0x20); // 设置内存寻址模式 -- Set Memory Addressing Mode (0x00 / 0x01 / 0x02) OLED_Write_Cmd(0x02); // \ Page Addressing 设置为页寻址模式 OLED_Write_Cmd(0xA8); // 设置多路传输比率 -- set multiplex ratio (16 to 63) OLED_Write_Cmd(0x3F); // \ 1 / 64 duty OLED_Write_Cmd(0xDA); // 设置列引脚硬件配置 -- set com pins hardware configuration OLED_Write_Cmd(0x12); // \ Sequential COM pin configuration,Enable COM Left/Right remap /* ----- 方向显示配置 ----- */ OLED_Write_Cmd(0xA1); // 设置段重映射 -- Set SEG / Column Mapping 0xA0左右反置(复位值) 0xA1正常(重映射值) OLED_Write_Cmd(0xC8); // 设置行输出扫描方向 -- Set COM / Row Scan Direction 0xc0上下反置(复位值) 0xC8正常(重映射值) /* ----- END ----- */ OLED_Write_Cmd(0x40); // 设置设置屏幕(GDDRAM)起始行 -- Set Display Start Line (0x40~0x7F) OLED_Write_Cmd(0xD3); // 设置显示偏移 -- set display offset (0x00~0x3F) OLED_Write_Cmd(0x00); // \ not offset 偏移值是 0 OLED_Write_Cmd(0x81); // 设置对比度 -- set contrast control register (0x00~0x100) OLED_Write_Cmd(0xCF); // \ Set SEG Output Current Brightness OLED_Write_Cmd(0xD9); // 设置预充电期间的持续时间 -- set pre-charge period OLED_Write_Cmd(0xF1); // \ Set Pre-Charge as 15 Clocks & Discharge as 1 Clock OLED_Write_Cmd(0xDB); // 调整VCOMH调节器的输出 -- set vcomh (0x00 / 0x20 / 0x30) OLED_Write_Cmd(0x20); // \ Set VCOM Deselect Level OLED_Write_Cmd(0x8D); // 电荷泵设置 -- set Charge Pump enable / disable (0x14 / 0x10) OLED_Write_Cmd(0x14); // \ 启用电荷泵 Enable charge pump during display on OLED_Write_Cmd(0xA4); // 全局显示开启(黑屏/亮屏) (0xA4 根据RAM 内容显示 / 0xA5 每个oled都点亮 全部显示) OLED_Write_Cmd(0xA6); // 设置显示方式(正常/反显) -- set normal display (0xA6 / 0xA7) OLED_Write_Cmd(0xAF); // 打开OLED -- turn on oled panel : OXAE 关闭OLED 休眠模式 0xaf 打开oled OLED_Fill(0x00); // 初始清屏 OLED_Coord(0, 0); // 设置原点坐标(0, 0) }