做网站需要购买网站空间吗,网站建设分为哪几个步骤,网站开发软硬件条件,上海网站建设解决方案文章目录 一、U8g2简介1、特点2、U8g2的使用步骤 二、I2C相关介绍1、I2C的基本原理2、I2C的时序协议 三、OLED屏的工作原理四、汉字点阵显示原理五、建立STM32CubeMX工程六、U8g2移植1、U8g2源码2、移植过程 七、代码编写1、参考博主实现的U82G的demo例程#xff08;1#xf… 文章目录 一、U8g2简介1、特点2、U8g2的使用步骤 二、I2C相关介绍1、I2C的基本原理2、I2C的时序协议 三、OLED屏的工作原理四、汉字点阵显示原理五、建立STM32CubeMX工程六、U8g2移植1、U8g2源码2、移植过程 七、代码编写1、参考博主实现的U82G的demo例程1编写移植函数2U8g2图形库测试函数3main函数 参考资料 一、U8g2简介 U8g2是一个用于嵌入式设备的单色图形库全称为“Universal 8bit Graphics Library version 2”。它由Oliver Kraus开发专门为微控制器设计用于驱动各种单色LCD和OLED显示屏。U8g2库支持多种不同的显示设备包括各种尺寸和分辨率的显示屏。 1、特点
U8g2库的特点包括
跨平台性U8g2可以在不同的微控制器平台上运行如Arduino、STM32、ESP8266等。 多种显示支持支持多种单色显示设备包括LCD和OLED。 字体支持U8g2内置了多种字体包括不同大小的字体和特殊字体。 易用性U8g2的API设计简单易用方便开发者快速上手。 低内存占用U8g2在设计中考虑到了嵌入式设备的资源限制尽量减少了内存的使用。 开源U8g2是开源的可以自由使用和修改。
2、U8g2的使用步骤
初始化显示屏根据具体的显示设备设置U8g2库的初始化参数。 发送命令和数据通过SPI、I2C或其他接口发送命令和数据到显示屏。 绘制图形和文本使用U8g2提供的函数可以绘制点、线、矩形、圆等基本图形以及显示文本。
二、I2C相关介绍
I2CInter-Integrated Circuit协议是一种由飞利浦公司现恩智浦半导体开发的串行通信协议用于连接低速外围设备。I2C总线是一种多主总线意味着它可以由多个主设备控制同时也可以有多个从设备连接在总线上。I2C协议通常用于短距离通信速度可达几百千比特每秒kbit/s。
1、I2C的基本原理
I2C总线只有两根信号线
SDASerial Data Line串行数据线用于传输数据。 SCLSerial Clock Line串行时钟线用于同步数据传输。 所有设备都连接到这两根线上可以是有源的如微控制器或无源的如传感器。每个设备都有一个唯一的地址主设备通过这个地址来选择和通信。
2、I2C的时序协议
I2C通信是由主设备控制的通信过程如下
起始条件Start Condition当SCL为高电平时主设备将SDA拉低表示一个数据传输的开始。 发送地址主设备发送一个字节这个字节的高7位是从设备的地址最低位是读/写位0为写1为读。 从机应答Acknowledge从设备在接收到地址后如果在总线上检测到自己的地址就会在下一个时钟周期内将SDA拉低表示应答。 数据传输在从设备应答后主设备开始发送或接收数据。每个字节后都有一个应答时钟周期。 停止条件Stop Condition当SCL为高电平时主设备将SDA拉高表示一个数据传输的结束。 重复起始条件Repeated Start Condition如果主设备想要进行连续的读/写操作它可以不发送停止条件而是发送另一个起始条件然后发送下一个从设备的地址。
三、OLED屏的工作原理
OLED(Organic Light Emitting Display中文名有机发光显示器是指有机半导体材料和发光材料在电场驱动下通过载流子注入和复合导致发光的现象。其原理是用ITO透明电极和金属电极分别作为器件的阳极和阴极在一定电压驱动下电子和空穴分别从阴极和阳极注入到电子和空穴传输层电子和空穴分别经过电子和空穴传输层迁移到发光层并在发光层中相遇形成激子并使发光分子激发后者经过辐射弛豫而发出可见光。
四、汉字点阵显示原理
1、 在汉字的点阵字库中每个字节的每个位都代表一个汉字的一个点每个汉字都是由一个矩形的点阵组成0代表没有1代表有点将0和1分别用不同颜色画出就形成了一个汉字常用的点阵矩阵有12x12, 14x14, 16x16三种字库。
2、 字库根据字节所表示点的不同有分为横向矩阵和纵向矩阵目前多数的字库都是横向矩阵的存储方式(用得最多的应该是早期UCDOS字库)纵向矩阵一般是因为有某些液晶是采用纵向扫描显示法为了提高显示速度于是便把字库矩阵做成纵向省得在显示时还要做矩阵转换。我们接下去所描述的都是指横向矩阵字库。
五、建立STM32CubeMX工程 配置RCC 配置SYS 配置I2C2作为OLED的通讯方式 配置TIM1U8g2图形库需要us级延迟推动U8g2的心跳 配置时钟树 设置工程路径、工程名,最后导出文件。使用keil打开并进行编写。
六、U8g2移植
1、U8g2源码
U8g2下载地址: https://github.com/olikraus/u8g2
2、移植过程
具体过程请参考博文https://blog.csdn.net/black_sneak/article/details/126312657
七、代码编写
1、参考博主实现的U82G的demo例程
1编写移植函数
stm32_u8g2.h
#ifndef __STM32_U8G2_H
#define __STM32_U8G2_H/* Includes ------------------------------------------------------------------*/
#include main.h
#include u8g2.h
/* USER CODE BEGIN Includes *//* USER CODE END Includes *//* USER CODE BEGIN Private defines *//* USER CODE END Private defines */
#define u8 unsigned char // ?unsigned char ????
#define MAX_LEN 128 //
#define OLED_ADDRESS 0x78 // oled
#define OLED_CMD 0x00 //
#define OLED_DATA 0x40 // /* USER CODE BEGIN Prototypes */
uint8_t u8x8_byte_hw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
uint8_t u8x8_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
void u8g2Init(u8g2_t *u8g2);
void draw(u8g2_t *u8g2);
void testDrawPixelToFillScreen(u8g2_t *u8g2);#endifstm32_u8g2.c
#include stm32_u8g2.h
#include tim.h
#include i2c.huint8_t u8x8_byte_hw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{/* u8g2/u8x8 will never send more than 32 bytes between START_TRANSFER and END_TRANSFER */static uint8_t buffer[128];static uint8_t buf_idx;uint8_t *data;switch (msg){case U8X8_MSG_BYTE_INIT:{/* add your custom code to init i2c subsystem */MX_I2C2_Init(); //I2C初始化}break;case U8X8_MSG_BYTE_START_TRANSFER:{buf_idx 0;}break;case U8X8_MSG_BYTE_SEND:{data (uint8_t *)arg_ptr;while (arg_int 0){buffer[buf_idx] *data;data;arg_int--;}}break;case U8X8_MSG_BYTE_END_TRANSFER:{if (HAL_I2C_Master_Transmit(hi2c2, OLED_ADDRESS, buffer, buf_idx, 1000) ! HAL_OK)return 0;}break;case U8X8_MSG_BYTE_SET_DC:break;default:return 0;}return 1;
}uint8_t u8x8_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{switch (msg){case U8X8_MSG_DELAY_100NANO: // delay arg_int * 100 nano seconds__NOP();break;case U8X8_MSG_DELAY_10MICRO: // delay arg_int * 10 micro secondsfor (uint16_t n 0; n 320; n){__NOP();}break;case U8X8_MSG_DELAY_MILLI: // delay arg_int * 1 milli secondHAL_Delay(1);break;case U8X8_MSG_DELAY_I2C: // arg_int is the I2C speed in 100KHz, e.g. 4 400 KHzTims_delay_us(5);break; // arg_int1: delay by 5us, arg_int 4: delay by 1.25uscase U8X8_MSG_GPIO_I2C_CLOCK: // arg_int0: Output low at I2C clock pinbreak; // arg_int1: Input dir with pullup high for I2C clock pincase U8X8_MSG_GPIO_I2C_DATA: // arg_int0: Output low at I2C data pinbreak; // arg_int1: Input dir with pullup high for I2C data pincase U8X8_MSG_GPIO_MENU_SELECT:u8x8_SetGPIOResult(u8x8, /* get menu select pin state */ 0);break;case U8X8_MSG_GPIO_MENU_NEXT:u8x8_SetGPIOResult(u8x8, /* get menu next pin state */ 0);break;case U8X8_MSG_GPIO_MENU_PREV:u8x8_SetGPIOResult(u8x8, /* get menu prev pin state */ 0);break;case U8X8_MSG_GPIO_MENU_HOME:u8x8_SetGPIOResult(u8x8, /* get menu home pin state */ 0);break;default:u8x8_SetGPIOResult(u8x8, 1); // default return valuebreak;}return 1;
}//U8g2的初始化需要调用下面这个u8g2_Setup_ssd1306_128x64_noname_f函数该函数的4个参数含义
//u8g2传入的U8g2结构体
//U8G2_R0默认使用U8G2_R0即可用于配置屏幕是否要旋转
//u8x8_byte_sw_i2c使用软件IIC驱动该函数由U8g2源码提供
//u8x8_gpio_and_delay就是上面我们写的配置函数void u8g2Init(u8g2_t *u8g2)
{u8g2_Setup_ssd1306_i2c_128x64_noname_f(u8g2, U8G2_R0, u8x8_byte_hw_i2c, u8x8_gpio_and_delay); // 初始化u8g2 结构体u8g2_InitDisplay(u8g2); // u8g2_SetPowerSave(u8g2, 0); // u8g2_ClearBuffer(u8g2);
}void draw(u8g2_t *u8g2)
{u8g2_ClearBuffer(u8g2); u8g2_SetFontMode(u8g2, 1); /*字体模式选择*/u8g2_SetFontDirection(u8g2, 0); /*字体方向选择*/u8g2_SetFont(u8g2, u8g2_font_inb24_mf); /*字库选择*/u8g2_DrawStr(u8g2, 0, 20, U);u8g2_SetFontDirection(u8g2, 1);u8g2_SetFont(u8g2, u8g2_font_inb30_mn);u8g2_DrawStr(u8g2, 21,8,8);u8g2_SetFontDirection(u8g2, 0);u8g2_SetFont(u8g2, u8g2_font_inb24_mf);u8g2_DrawStr(u8g2, 51,30,g);u8g2_DrawStr(u8g2, 67,30,\xb2);u8g2_DrawHLine(u8g2, 2, 35, 47);u8g2_DrawHLine(u8g2, 3, 36, 47);u8g2_DrawVLine(u8g2, 45, 32, 12);u8g2_DrawVLine(u8g2, 46, 33, 12);u8g2_SetFont(u8g2, u8g2_font_4x6_tr);u8g2_DrawStr(u8g2, 1,54,github.com/olikraus/u8g2);u8g2_SendBuffer(u8g2);HAL_Delay(1000);
}//画点填充
void testDrawPixelToFillScreen(u8g2_t *u8g2)
{int t 1000;u8g2_ClearBuffer(u8g2);for (int j 0; j 64; j){for (int i 0; i 128; i){u8g2_DrawPixel(u8g2,i, j);}}HAL_Delay(1000);
}2U8g2图形库测试函数
test.h
#ifndef __TEST_H
#define __TEST_H#include main.h
#include u8g2.hvoid testDrawProcess(u8g2_t *u8g2);
void testShowFont(u8g2_t *u8g2);
void testDrawFrame(u8g2_t *u8g2);
void testDrawRBox(u8g2_t *u8g2);
void testDrawCircle(u8g2_t *u8g2);
void testDrawFilledEllipse(u8g2_t *u8g2);
void testDrawMulti(u8g2_t *u8g2);
void testDrawXBM(u8g2_t *u8g2);void u8g2DrawTest(u8g2_t *u8g2);#endiftest.c
#include test.h//---------------U8g2测试函数#define SEND_BUFFER_DISPLAY_MS(u8g2, ms)\do {\u8g2_SendBuffer(u8g2); \HAL_Delay(ms);\}while(0);//进度条显示
void testDrawProcess(u8g2_t *u8g2)
{for(int i10;i80;ii2){u8g2_ClearBuffer(u8g2); char buff[20];sprintf(buff,%d%%,(int)(i/80.0*100));u8g2_SetFont(u8g2,u8g2_font_ncenB12_tf);u8g2_DrawStr(u8g2,16,32,STM32 U8g2);//字符显示u8g2_SetFont(u8g2,u8g2_font_ncenB08_tf);u8g2_DrawStr(u8g2,100,49,buff);//当前进度显示u8g2_DrawRBox(u8g2,16,40,i,10,4);//圆角填充框矩形框u8g2_DrawRFrame(u8g2,16,40,80,10,4);//圆角矩形u8g2_SendBuffer(u8g2);}HAL_Delay(500);
}//字体测试 数字英文可选用 u8g2_font_ncenB..(粗) 系列字体
//u8g2_font_unifont_t_symbols/u8g2_font_unifont_h_symbols(细 圆润)
void testShowFont(u8g2_t *u8g2)
{int t 1000;char testStr[14] STM32F103C8T6;u8g2_ClearBuffer(u8g2);u8g2_SetFont(u8g2,u8g2_font_u8glib_4_tf);u8g2_DrawStr(u8g2,0,5,testStr);SEND_BUFFER_DISPLAY_MS(u8g2,t);u8g2_SetFont(u8g2,u8g2_font_ncenB08_tf);u8g2_DrawStr(u8g2,0,30,testStr);SEND_BUFFER_DISPLAY_MS(u8g2,t);u8g2_SetFont(u8g2,u8g2_font_ncenB10_tr);u8g2_DrawStr(u8g2,0,60,testStr);SEND_BUFFER_DISPLAY_MS(u8g2,t);
}//画空心矩形
void testDrawFrame(u8g2_t *u8g2)
{int t 1000;int x 16;int y 32;int w 50;int h 20;u8g2_ClearBuffer(u8g2);u8g2_DrawStr(u8g2,0, 15, DrawFrame);u8g2_DrawFrame(u8g2, x, y, w, h);SEND_BUFFER_DISPLAY_MS(u8g2,t);u8g2_DrawFrame(u8g2, xw5, y-10, w-20, h20);SEND_BUFFER_DISPLAY_MS(u8g2,t);
}//画实心圆角矩形
void testDrawRBox(u8g2_t *u8g2)
{int t 1000;int x 16;int y 32;int w 50;int h 20;int r 3;u8g2_ClearBuffer(u8g2);u8g2_DrawStr(u8g2,0, 15, DrawRBox);u8g2_DrawRBox(u8g2, x, y, w, h, r);SEND_BUFFER_DISPLAY_MS(u8g2,t);u8g2_DrawRBox(u8g2, xw5, y-10, w-20, h20, r);SEND_BUFFER_DISPLAY_MS(u8g2,t);
}//画空心圆
void testDrawCircle(u8g2_t *u8g2)
{int t 600;int stx 0; //画图起始xint sty 16; //画图起始yint with 16;//一个图块的间隔int r 15; //圆的半径u8g2_ClearBuffer(u8g2);u8g2_DrawStr(u8g2, 0, 15, DrawCircle);u8g2_DrawCircle(u8g2, stx, sty - 1 with, r, U8G2_DRAW_UPPER_RIGHT); //右上SEND_BUFFER_DISPLAY_MS(u8g2,t);u8g2_DrawCircle(u8g2, stx with, sty, r, U8G2_DRAW_LOWER_RIGHT); //右下SEND_BUFFER_DISPLAY_MS(u8g2,t);u8g2_DrawCircle(u8g2, stx - 1 with * 3, sty - 1 with, r, U8G2_DRAW_UPPER_LEFT); //左上SEND_BUFFER_DISPLAY_MS(u8g2,t);u8g2_DrawCircle(u8g2, stx - 1 with * 4, sty, r, U8G2_DRAW_LOWER_LEFT); //左下SEND_BUFFER_DISPLAY_MS(u8g2,t);u8g2_DrawCircle(u8g2, stx - 1 with * 2, sty - 1 with * 2, r, U8G2_DRAW_ALL);//整个圆SEND_BUFFER_DISPLAY_MS(u8g2,t);u8g2_DrawCircle(u8g2, 32*3, 32, 31, U8G2_DRAW_ALL);//右侧整个圆SEND_BUFFER_DISPLAY_MS(u8g2,t);
}//画实心椭圆
void testDrawFilledEllipse(u8g2_t *u8g2)
{int t 800;int with 16;//一个图块的间隔int rx 27; //椭圆x方向的半径int ry 22; //椭圆y方向的半径u8g2_ClearBuffer(u8g2);u8g2_DrawStr(u8g2,0, 14, DrawFilledEllipse);SEND_BUFFER_DISPLAY_MS(u8g2,t);u8g2_DrawFilledEllipse(u8g2, 0, with, rx, ry, U8G2_DRAW_LOWER_RIGHT);//右下SEND_BUFFER_DISPLAY_MS(u8g2,t);u8g2_DrawFilledEllipse(u8g2, with * 4 - 1, with, rx, ry, U8G2_DRAW_LOWER_LEFT); //左下SEND_BUFFER_DISPLAY_MS(u8g2,t);u8g2_DrawFilledEllipse(u8g2, 0, with * 4 - 1, rx, ry, U8G2_DRAW_UPPER_RIGHT); //右上SEND_BUFFER_DISPLAY_MS(u8g2,t);u8g2_DrawFilledEllipse(u8g2, with * 4 - 1, with * 4 - 1, rx, ry, U8G2_DRAW_UPPER_LEFT); //左上SEND_BUFFER_DISPLAY_MS(u8g2,t);u8g2_DrawFilledEllipse(u8g2, with * 6, with * 2.5, rx, ry, U8G2_DRAW_ALL);//整个椭圆SEND_BUFFER_DISPLAY_MS(u8g2,t);
}//环形测试
void testDrawMulti(u8g2_t *u8g2)
{u8g2_ClearBuffer(u8g2);for (int j 0; j 64; j16){for (int i 0; i 128; i16){u8g2_DrawPixel(u8g2, i, j);u8g2_SendBuffer(u8g2);}}//实心矩形逐渐变大u8g2_ClearBuffer(u8g2);for(int i30; i0; i-2){u8g2_DrawBox(u8g2,i*2,i,128-i*4,64-2*i);u8g2_SendBuffer(u8g2);}//空心矩形逐渐变小u8g2_ClearBuffer(u8g2);for(int i0; i32; i2){u8g2_DrawFrame(u8g2,i*2,i,128-i*4,64-2*i);u8g2_SendBuffer(u8g2);}//实心圆角矩形逐渐变大u8g2_ClearBuffer(u8g2);for(int i30; i0; i-2){u8g2_DrawRBox(u8g2,i*2,i,128-i*4,64-2*i,10-i/3);u8g2_SendBuffer(u8g2);}//空心圆角矩形逐渐变小u8g2_ClearBuffer(u8g2);for(int i0; i32; i2){u8g2_DrawRFrame(u8g2,i*2,i,128-i*4,64-2*i,10-i/3);u8g2_SendBuffer(u8g2);}//实心圆逐渐变大u8g2_ClearBuffer(u8g2);for(int i2; i64; i3){u8g2_DrawDisc(u8g2,64,32,i, U8G2_DRAW_ALL);u8g2_SendBuffer(u8g2);}//空心圆逐渐变小u8g2_ClearBuffer(u8g2);for(int i64; i0; i-3){u8g2_DrawCircle(u8g2,64,32,i, U8G2_DRAW_ALL);u8g2_SendBuffer(u8g2);}//实心椭圆逐渐变大u8g2_ClearBuffer(u8g2);for(int i2; i32; i3){u8g2_DrawFilledEllipse(u8g2,64,32, i*2, i, U8G2_DRAW_ALL);u8g2_SendBuffer(u8g2);}//空心椭圆逐渐变小u8g2_ClearBuffer(u8g2);for(int i32; i0; i-3){u8g2_DrawEllipse(u8g2,64,32, i*2, i, U8G2_DRAW_ALL);u8g2_SendBuffer(u8g2);}
}// width: 128, height: 48
const unsigned char bilibili[] U8X8_PROGMEM { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0xe0, 0x03, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0xf0, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x01, 0xfc, 0x00, 0x00, 0x00, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x03, 0xfc, 0x00, 0x00, 0x3c, 0xc0, 0x0f, 0x00, 0x80, 0x03, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0x07, 0xfc, 0x00, 0x00, 0x3c, 0xc0, 0x0f, 0x00, 0xc0, 0x07, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xfc, 0x00, 0x00, 0x3c, 0x80, 0x0f, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x0f, 0x00, 0x00, 0x80, 0x0f, 0xf8, 0x00, 0x00, 0x3c, 0x80, 0x0f, 0x00, 0x80, 0x07, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x78, 0x80, 0x0f, 0x00, 0x80, 0x07, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x78, 0x80, 0x0f, 0x00, 0x80, 0x07, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x80, 0x79, 0x80, 0x0f, 0x00, 0x98, 0x07, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0xe0, 0x79, 0x9f, 0x0f, 0x00, 0xbe, 0xe7, 0x01, 0xc0, 0x07, 0x10, 0x40, 0x00, 0x1f, 0xf8, 0x00, 0xe0, 0x7b, 0x1f, 0x0f, 0x00, 0xbe, 0xe7, 0x01, 0xc0, 0x87, 0x1f, 0xe0, 0x0f, 0x1f, 0xf8, 0x00, 0xe0, 0x7b, 0x1e, 0x0f, 0x00, 0x3e, 0xe7, 0x01, 0xc0, 0xe7, 0x3f, 0xe0, 0x3f, 0x1f, 0xf0, 0x00, 0xe0, 0x7b, 0x1e, 0x0f, 0x00, 0x3e, 0xe7, 0x01, 0xc0, 0xe7, 0x3f, 0xe0, 0x3f, 0x1f, 0xf0, 0x00, 0x60, 0x71, 0x1e, 0x0f, 0x00, 0x34, 0xe7, 0x01, 0xc0, 0xe7, 0x07, 0x00, 0x3f, 0x1f, 0xf0, 0x00, 0x00, 0x70, 0x00, 0x1f, 0x00, 0x00, 0x07, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x1f, 0xf0, 0x00, 0xc0, 0x73, 0x1e, 0x1f, 0x00, 0x3c, 0xc7, 0x01, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x1f, 0xf0, 0x00, 0xc0, 0x73, 0x1e, 0x1f, 0x00, 0x7c, 0xe7, 0x01, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x1f, 0xf0, 0x00, 0xc0, 0x73, 0x1e, 0x1f, 0x00, 0x7c, 0xef, 0x01, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x1f, 0xf0, 0x01, 0xc0, 0x77, 0x1e, 0x1e, 0x00, 0x7c, 0xef, 0x01, 0xc0, 0x07, 0x00, 0x03, 0x00, 0x1f, 0xf0, 0xff, 0xc1, 0xf7, 0x1e, 0xfe, 0x1f, 0x78, 0xef, 0x01, 0xc0, 0x07, 0x70, 0x37, 0x00, 0x1f, 0xe0, 0xff, 0x87, 0xf7, 0x1e, 0xfe, 0xff, 0x78, 0xee, 0x01, 0xc0, 0x07, 0xe0, 0x3f, 0x00, 0x1f, 0xe0, 0xff, 0x9f, 0xf7, 0x1e, 0xfe, 0xff, 0x79, 0xce, 0x01, 0xc0, 0x07, 0xc0, 0x18, 0x00, 0x1f, 0xe0, 0xff, 0xbf, 0xe7, 0x1e, 0xfe, 0xff, 0x7b, 0xce, 0x01, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x1f, 0xe0, 0xc7, 0xbf, 0xe7, 0x1e, 0xfe, 0xf8, 0x77, 0xce, 0x01, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x1f, 0xe0, 0x0f, 0x3f, 0xe7, 0x1c, 0xfe, 0xf0, 0x77, 0xce, 0x03, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x1f, 0xe0, 0xcf, 0x3f, 0xe7, 0x1c, 0xfe, 0xf8, 0xf3, 0xce, 0x03, 0xc0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xe0, 0xef, 0x1f, 0xe7, 0x1c, 0xfe, 0xfe, 0xf1, 0xce, 0x03, 0x80, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xe0, 0xff, 0x0f, 0xcf, 0x1c, 0xfc, 0xff, 0xf0, 0xc0, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff, 0x07, 0xe0, 0xff, 0x03, 0x06, 0x1c, 0xfc, 0x7f, 0x60, 0xc0, 0x01, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x03, 0xe0, 0xff, 0x00, 0x00, 0x00, 0xfc, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x00, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
// width: 128, height: 48
const unsigned char three_support[] U8X8_PROGMEM { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0x00, 0xfc, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x80, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0x00, 0x00, 0x80, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0xc0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x03, 0x00, 0x00, 0x80, 0x0f, 0xf0, 0x01, 0x00, 0x00, 0xfc, 0xff, 0x01, 0x00, 0x00, 0xc0, 0xfd, 0xff, 0x00, 0x00, 0xc0, 0x7f, 0xfe, 0x01, 0x00, 0x00, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xe0, 0xfd, 0xff, 0x01, 0x00, 0xc0, 0x1f, 0xf8, 0x03, 0x00, 0x00, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xe0, 0xfd, 0xff, 0x01, 0x00, 0xc0, 0x0f, 0xf0, 0x03, 0x00, 0x00, 0xfe, 0xff, 0x07, 0x00, 0x00, 0xe0, 0xfd, 0xff, 0x01, 0x00, 0xc0, 0x67, 0xe6, 0x03, 0x00, 0x00, 0xfc, 0xff, 0x03, 0x00, 0x00, 0xe0, 0xfd, 0xff, 0x01, 0x00, 0xc0, 0x67, 0xe6, 0x03, 0x00, 0x00, 0xf8, 0xff, 0x01, 0x00, 0x00, 0xe0, 0xfd, 0xff, 0x00, 0x00, 0xc0, 0x67, 0xe6, 0x03, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0x00, 0xe0, 0xfd, 0xff, 0x00, 0x00, 0xc0, 0x67, 0xee, 0x03, 0x00, 0x00, 0xe0, 0x7f, 0x00, 0x00, 0x00, 0xe0, 0xfd, 0xff, 0x00, 0x00, 0x80, 0x7f, 0xfe, 0x01, 0x00, 0x00, 0xe0, 0xff, 0x00, 0x00, 0x00, 0xe0, 0xfd, 0xff, 0x00, 0x00, 0x80, 0x7f, 0xfe, 0x01, 0x00, 0x00, 0xf0, 0xff, 0x00, 0x00, 0x00, 0xe0, 0xfd, 0x7f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x00, 0x00, 0x00, 0xe0, 0xfd, 0x7f, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x00, 0x00, 0x00, 0xf8, 0xf9, 0x01, 0x00, 0x00, 0xe0, 0xfd, 0x7f, 0x00, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00, 0x00, 0xf8, 0xf0, 0x00, 0x00, 0x00, 0xe0, 0xfd, 0x1f, 0x00, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x30, 0xc0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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 testDrawXBM(u8g2_t *u8g2)
{int t 1000;u8g2_ClearBuffer(u8g2);u8g2_DrawStr(u8g2,0, 14, DrawXBM);u8g2_DrawXBM(u8g2,0, 16, 128, 48, bilibili);SEND_BUFFER_DISPLAY_MS(u8g2,t);u8g2_ClearBuffer(u8g2);u8g2_DrawStr(u8g2,0, 14, bilibili);u8g2_DrawXBM(u8g2,0, 16, 128, 48, three_support);SEND_BUFFER_DISPLAY_MS(u8g2,t);
}void u8g2DrawTest(u8g2_t *u8g2)
{testDrawProcess(u8g2);testDrawMulti(u8g2);//testDrawFrame(u8g2);//testDrawRBox(u8g2);//testDrawCircle(u8g2);//testDrawFilledEllipse(u8g2);testShowFont(u8g2);testDrawXBM(u8g2);}3main函数
int main(void)
{/* USER CODE BEGIN 1 *//* USER CODE END 1 *//* MCU Configuration--------------------------------------------------------*//* Reset of all peripherals, Initializes the Flash interface and the Systick. */HAL_Init();/* USER CODE BEGIN Init *//* USER CODE END Init *//* Configure the system clock */SystemClock_Config();/* USER CODE BEGIN SysInit *//* USER CODE END SysInit *//* Initialize all configured peripherals */MX_GPIO_Init();MX_I2C2_Init();MX_TIM1_Init();/* USER CODE BEGIN 2 */u8g2_t u8g2;u8g2Init(u8g2); /* USER CODE END 2 *//* Infinite loop *//* USER CODE BEGIN WHILE */while (1){/* USER CODE END WHILE *//* USER CODE BEGIN 3 */u8g2_FirstPage(u8g2);do{draw(u8g2);u8g2DrawTest(u8g2);} while (u8g2_NextPage(u8g2));}/* USER CODE END 3 */
}最终效果 基于STM32移植U8g2图形库——OLED显示HAL库 参考资料
https://blog.csdn.net/Hahhhnxsm_/article/details/134485585 文章转载自: http://www.morning.zqfz.cn.gov.cn.zqfz.cn http://www.morning.wglhz.cn.gov.cn.wglhz.cn http://www.morning.rui931.cn.gov.cn.rui931.cn http://www.morning.rksnk.cn.gov.cn.rksnk.cn http://www.morning.fmtfj.cn.gov.cn.fmtfj.cn http://www.morning.bbjw.cn.gov.cn.bbjw.cn http://www.morning.rqxtb.cn.gov.cn.rqxtb.cn http://www.morning.jjtwh.cn.gov.cn.jjtwh.cn http://www.morning.cniedu.com.gov.cn.cniedu.com http://www.morning.xpmhs.cn.gov.cn.xpmhs.cn http://www.morning.ryzgp.cn.gov.cn.ryzgp.cn http://www.morning.bnfrj.cn.gov.cn.bnfrj.cn http://www.morning.ljpqy.cn.gov.cn.ljpqy.cn http://www.morning.fdlyh.cn.gov.cn.fdlyh.cn http://www.morning.gwwky.cn.gov.cn.gwwky.cn http://www.morning.yprnp.cn.gov.cn.yprnp.cn http://www.morning.dywgl.cn.gov.cn.dywgl.cn http://www.morning.nbrkt.cn.gov.cn.nbrkt.cn http://www.morning.wscfl.cn.gov.cn.wscfl.cn http://www.morning.ctfh.cn.gov.cn.ctfh.cn http://www.morning.dblgm.cn.gov.cn.dblgm.cn http://www.morning.gbjxj.cn.gov.cn.gbjxj.cn http://www.morning.kpyyf.cn.gov.cn.kpyyf.cn http://www.morning.fykrm.cn.gov.cn.fykrm.cn http://www.morning.khlxd.cn.gov.cn.khlxd.cn http://www.morning.smj79.cn.gov.cn.smj79.cn http://www.morning.pqxjq.cn.gov.cn.pqxjq.cn http://www.morning.sxcwc.cn.gov.cn.sxcwc.cn http://www.morning.xbdd.cn.gov.cn.xbdd.cn http://www.morning.cnyqj.cn.gov.cn.cnyqj.cn http://www.morning.nchlk.cn.gov.cn.nchlk.cn http://www.morning.msbmp.cn.gov.cn.msbmp.cn http://www.morning.wgqtt.cn.gov.cn.wgqtt.cn http://www.morning.rpzqk.cn.gov.cn.rpzqk.cn http://www.morning.pnmnl.cn.gov.cn.pnmnl.cn http://www.morning.jqwpw.cn.gov.cn.jqwpw.cn http://www.morning.wnjwb.cn.gov.cn.wnjwb.cn http://www.morning.pqkyx.cn.gov.cn.pqkyx.cn http://www.morning.wmgjq.cn.gov.cn.wmgjq.cn http://www.morning.tyrlk.cn.gov.cn.tyrlk.cn http://www.morning.wcjk.cn.gov.cn.wcjk.cn http://www.morning.trqzk.cn.gov.cn.trqzk.cn http://www.morning.kjawz.cn.gov.cn.kjawz.cn http://www.morning.3dcb8231.cn.gov.cn.3dcb8231.cn http://www.morning.rggky.cn.gov.cn.rggky.cn http://www.morning.dbqg.cn.gov.cn.dbqg.cn http://www.morning.mdnnz.cn.gov.cn.mdnnz.cn http://www.morning.qxltp.cn.gov.cn.qxltp.cn http://www.morning.thzgd.cn.gov.cn.thzgd.cn http://www.morning.jghqc.cn.gov.cn.jghqc.cn http://www.morning.kqbwr.cn.gov.cn.kqbwr.cn http://www.morning.mpscg.cn.gov.cn.mpscg.cn http://www.morning.rwbh.cn.gov.cn.rwbh.cn http://www.morning.ldspj.cn.gov.cn.ldspj.cn http://www.morning.pxdgy.cn.gov.cn.pxdgy.cn http://www.morning.fpczq.cn.gov.cn.fpczq.cn http://www.morning.xptkl.cn.gov.cn.xptkl.cn http://www.morning.rmfh.cn.gov.cn.rmfh.cn http://www.morning.hhboyus.cn.gov.cn.hhboyus.cn http://www.morning.tphrx.cn.gov.cn.tphrx.cn http://www.morning.trjdr.cn.gov.cn.trjdr.cn http://www.morning.ndlww.cn.gov.cn.ndlww.cn http://www.morning.aa1585.com.gov.cn.aa1585.com http://www.morning.xkwyk.cn.gov.cn.xkwyk.cn http://www.morning.rrbhy.cn.gov.cn.rrbhy.cn http://www.morning.lcxzg.cn.gov.cn.lcxzg.cn http://www.morning.zrdhd.cn.gov.cn.zrdhd.cn http://www.morning.rpwm.cn.gov.cn.rpwm.cn http://www.morning.lwhsp.cn.gov.cn.lwhsp.cn http://www.morning.qrmyd.cn.gov.cn.qrmyd.cn http://www.morning.wlddq.cn.gov.cn.wlddq.cn http://www.morning.rgwrl.cn.gov.cn.rgwrl.cn http://www.morning.rmyt.cn.gov.cn.rmyt.cn http://www.morning.dpqqg.cn.gov.cn.dpqqg.cn http://www.morning.gjqwt.cn.gov.cn.gjqwt.cn http://www.morning.kdnrc.cn.gov.cn.kdnrc.cn http://www.morning.zympx.cn.gov.cn.zympx.cn http://www.morning.pflpb.cn.gov.cn.pflpb.cn http://www.morning.pjyrl.cn.gov.cn.pjyrl.cn http://www.morning.mhnxs.cn.gov.cn.mhnxs.cn