【分享帖】官方OLED模块_bug解决与额外功能函数开源
4600
0
5
2020-07-25
官方的OLED使用的是SH1106G。在使用官方代码驱动时存在显示不稳定,抖动的情况。经过一段时间的分析发现原因出在官方代码设置低列地址时寄存器地址错误。
SH1106-CN中文数据手册中:
设置低列地址:(00H-0FH)
官方代码:
static void oled_set_pos(uint8_t x, uint8_t y)
{
x += 2;
oled_write_byte((0xb0 + y), OLED_CMD); //set page address y
oled_write_byte(((x&0xf0)>>4)|0x10, OLED_CMD); //set column high address
oled_write_byte((x&0xf0), OLED_CMD); //set column low address
}
应修改为:
static void oled_set_pos(uint8_t x, uint8_t y)
{
x += 2;
oled_write_byte((0xb0 + y), OLED_CMD); //set page address y
oled_write_byte(((x&0xf0)>>4)|0x10, OLED_CMD); //set column high address
oled_write_byte((x&0x0f), OLED_CMD); //set column low address
}
即可解决问题。
顺便开源几个函数:分别为调整对比度、取反色、屏幕全亮、图像沿X轴翻转。
/**
* @brief set the OLED contrast
*
* @param contrast 0-255
*/
void oled_contrast_set(uint8_t contrast)
SH1106-CN中文数据手册中:
设置低列地址:(00H-0FH)
官方代码:
static void oled_set_pos(uint8_t x, uint8_t y)
{
x += 2;
oled_write_byte((0xb0 + y), OLED_CMD); //set page address y
oled_write_byte(((x&0xf0)>>4)|0x10, OLED_CMD); //set column high address
oled_write_byte((x&0xf0), OLED_CMD); //set column low address
}
应修改为:
static void oled_set_pos(uint8_t x, uint8_t y)
{
x += 2;
oled_write_byte((0xb0 + y), OLED_CMD); //set page address y
oled_write_byte(((x&0xf0)>>4)|0x10, OLED_CMD); //set column high address
oled_write_byte((x&0x0f), OLED_CMD); //set column low address
}
即可解决问题。
顺便开源几个函数:分别为调整对比度、取反色、屏幕全亮、图像沿X轴翻转。
/**
* @brief set the OLED contrast
*
* @param contrast 0-255
*/
void oled_contrast_set(uint8_t contrast)