目录
- 一、I2C协议的基本原理和时序协议
- I2C通信协议的原理
- I2C时序基本单元
- I2C时序
- 二、建立工程
- RCC配置
- TIM1配置
- 时钟树配置
- 工程配置
- 三、U8g2移植
- 精简u8g2_d_setup.c
- 精简u8g2_d_memory.c
- 编写移植函数
- stm32_u8g2.h
- stm32_u8g2.c
- 四、实验
- 1.U82G的demo例程
- 2.显示网名昵称
- 中文取模步骤
- 3.滑动显示
- 4.显示一个图案
- 总结
一、实验目的:
1、了解I2C协议的基本原理和时序协议;
2、掌握0.96寸OLED屏的工作原理,汉字点阵显示原理;
3、掌握开源GUI库U82G在stm32上的移植编译方法,以及图形界面可视化技术。
一、I2C协议的基本原理和时序协议
I2C通信协议的原理
I2C通信协是由一根时钟线、一根数据线组成,是同步的(有时钟线控制时间,若遇到中断去执行别的程序,通信不会被打算),由一根数据线完成接收和发送数据,是半双工模式,为了实时的知道数据的接收信息设置了数据应答,支持连接多个外设。本文主要使用一主多从模式。
一主多从:一个主机,多个从机,从机默认无法操作数据线,主机可选择某个从机使其短暂的可以操作数据线。
多主多从:也是一个主机,多个从机,但从机可以与主机互换身份。
I2C时序基本单元
•起始条件:SCL高电平期间,SDA从高电平切换到低电平
•终止条件:SCL高电平期间,SDA从低电平切换到高电平
发送一个字节:
SCL低电平期间,主机将数据位依次放到SDA线上(高位先行),然后释放SCL,从机将在SCL高电平期间读取数据位,所以SCL高电平期间SDA不允许有数据变化,依次循环上述过程8次,即可发送一个字节
接收一个字节:
SCL低电平期间,从机将数据位依次放到SDA线上(高位先行),然后释放SCL,主机将在SCL高电平期间读取数据位,所以SCL高电平期间SDA不允许有数据变化,依次循环上述过程8次,即可接收一个字节(主机在接收之前,需要释放SDA)
•发送应答:主机在接收完一个字节之后,在下一个时钟发送一位数据,数据0表示应答,数据1表示非应答
•接收应答:主机在发送完一个字节之后,在下一个时钟接收一位数据,判断从机是否应答,数据0表示应答,数据1表示非应答(主机在接收之前,需要释放SDA)
I2C时序
•指定地址写
•对于指定设备(Slave Address),在指定地址(Reg Address)下,写入指定数据(Data)
•当前地址读
•对于指定设备(Slave Address),在当前地址指针指示的地址下,读取从机数据(Data)
•指定地址读
•对于指定设备(Slave Address),在指定地址(Reg Address)下,读取从机数据(Data)
二、建立工程
RCC配置
外部高速晶振(精度更高)——HSE;
SYS配置Debug设置成Serial Wire(否则可能导致芯片自锁);
I2C2配置作为OLED的通讯方式
TIM1配置
U8g2图形库需要us级延迟推动(U8g2的心跳)
时钟树配置
工程配置
三、U8g2移植
精简u8g2_d_setup.c
由于笔者的OLED是IIC接口,只留一个本次要用到u8g2_Setup_ssd1306_i2c_128x64_noname_f就好(如果是SPI接口,需要使用u8g2_Setup_ssd1306_128x64_noname_f这个函数),其它的可以删掉或注释掉。
精简u8g2_d_memory.c
由于用到的u8g2_Setup_ssd1306_i2c_128x64_noname_f函数中,只调用了u8g2_m_16_8_f这个函数,所以留下这个函数,其它的函数一定要删掉或注释掉,否则编译时很可能会提示内存不足
编写移植函数
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);#endif
stm32_u8g2.c
#include "stm32_u8g2.h"
#include "tim.h"
#include "i2c.h"uint8_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_int=1: delay by 5us, arg_int = 4: delay by 1.25uscase U8X8_MSG_GPIO_I2C_CLOCK: // arg_int=0: Output low at I2C clock pinbreak; // arg_int=1: Input dir with pullup high for I2C clock pincase U8X8_MSG_GPIO_I2C_DATA: // arg_int=0: Output low at I2C data pinbreak; // arg_int=1: 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);
}
四、实验
1.U82G的demo例程
test.h
#ifndef __TEST_H
#define __TEST_H#include "main.h"
#include "u8g2.h"void 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);#endif
test.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 i=10;i<=80;i=i+2){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, x+w+5, y-10, w-20, h+20);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, x+w+5, y-10, w-20, h+20, 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; j+=16){for (int i = 0; i < 128; i+=16){u8g2_DrawPixel(u8g2, i, j);u8g2_SendBuffer(u8g2);}}//实心矩形逐渐变大u8g2_ClearBuffer(u8g2);for(int i=30; i>0; i-=2){u8g2_DrawBox(u8g2,i*2,i,128-i*4,64-2*i);u8g2_SendBuffer(u8g2);}//空心矩形逐渐变小u8g2_ClearBuffer(u8g2);for(int i=0; i<32; i+=2){u8g2_DrawFrame(u8g2,i*2,i,128-i*4,64-2*i);u8g2_SendBuffer(u8g2);}//实心圆角矩形逐渐变大u8g2_ClearBuffer(u8g2);for(int i=30; i>0; 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 i=0; i<32; i+=2){u8g2_DrawRFrame(u8g2,i*2,i,128-i*4,64-2*i,10-i/3);u8g2_SendBuffer(u8g2);}//实心圆逐渐变大u8g2_ClearBuffer(u8g2);for(int i=2; i<64; i+=3){u8g2_DrawDisc(u8g2,64,32,i, U8G2_DRAW_ALL);u8g2_SendBuffer(u8g2);}//空心圆逐渐变小u8g2_ClearBuffer(u8g2);for(int i=64; i>0; i-=3){u8g2_DrawCircle(u8g2,64,32,i, U8G2_DRAW_ALL);u8g2_SendBuffer(u8g2);}//实心椭圆逐渐变大u8g2_ClearBuffer(u8g2);for(int i=2; i<32; i+=3){u8g2_DrawFilledEllipse(u8g2,64,32, i*2, i, U8G2_DRAW_ALL);u8g2_SendBuffer(u8g2);}//空心椭圆逐渐变小u8g2_ClearBuffer(u8g2);for(int i=32; i>0; 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);}
main函数
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 */
}
编译出现以下错误,删除tims_delay_us即可
效果如下:
2.显示网名昵称
中文取模步骤
1.打开PCtoLCD2002
2.选择模式 - 字符模式
3.点击选项,进行设置,
4.在输入栏输入需要取模的汉字(只能是汉字),然后点击生成字模。
以下是我用取模工具提取的位图数据:
/*落*/
static const unsigned char luo[] ={
0x10,0x04,0x10,0x04,0xFF,0x7F,0x10,0x04,0x04,0x01,0x08,0x1F,0x88,0x10,0x41,0x09,0x12,0x06,0x92,0x19,0x68,0x60,0x87,0x1F,0x84,0x10,0x84,0x10,0x84,0x1F,0x84,0x10};
/*笔*/
static const unsigned char bi[] ={
0x08,0x02,0x08,0x02,0xFC,0x7E,0x12,0x09,0xA1,0x10,0x00,0x1F,0xFC,0x00,0x80,0x00,0x80,0x1F,0xFC,0x00,0x80,0x00,0x80,0x3F,0xFE,0x40,0x80,0x40,0x80,0x40,0x00,0x7F};
/*太*/
static const unsigned char tai[] ={
0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0xFF,0x7F,0x80,0x00,0x80,0x00,0x40,0x01,0x40,0x01,0x20,0x02,0x20,0x02,0x50,0x04,0x88,0x08,0x84,0x10,0x03,0x60};
/*慌*/
static const unsigned char huang[]={
0x84,0x10,0x84,0x10,0xE4,0x7F,0x84,0x12,0x0C,0x04,0xF5,0x7F,0x45,0x00,0x45,0x00,0xC5,0x3F,0x04,0x00,0x44,0x12,0x44,0x12,0x44,0x12,0x24,0x52,0x24,0x52,0x14,0x62};/*张*/
static const unsigned char zhang[]={
0x80,0x00,0x9F,0x10,0x90,0x10,0x90,0x08,0x90,0x04,0x9E,0x02,0x82,0x00,0xE2,0x7F,0x82,0x02,0x9E,0x04,0x90,0x04,0x90,0x08,0x90,0x10,0x90,0x22,0x8A,0x41,0x84,0x00
};
main函数
u8g2_SetFont(&u8g2,u8g2_font_ncenB12_tf);//设置字体格式
u8g2_DrawXBMP(&u8g2,16,0,16,16,luo);//(参数顺序依次是,结构体、x、y、字宽、字高、储存要显示的字点阵的数组)
u8g2_DrawXBMP(&u8g2,32,0,16,16,bi);
u8g2_DrawXBMP(&u8g2,48,0,16,16,tai);
u8g2_DrawXBMP(&u8g2,64,0,16,16,huang);
u8g2_DrawXBMP(&u8g2,80,0,16,16,zhang);
u8g2_SetFont(&u8g2,u8g2_font_ncenB10_tf);
u8g2_DrawStr(&u8g2,16,50,"632207060723");
u8g2_SendBuffer(&u8g2);
效果展示:
3.滑动显示
思路:因为oled屏幕是128*64规格的,所以x坐标在(0,128)之间,为了实现滑动(以右滑动为例子)中定义横坐标x为变量,通过改变x的值从而实现滑动,向其它方位滑动同理(上下滑动设置变量y)
以右滑动为例子,其余同理
unsigned int x=16;while (1){if(x<=128){x++;//向右滑动,可以提高每次x的增加量来控制滑动速度}else if(x>128)//置零{x=0;}u8g2_SetFont(&u8g2,u8g2_font_ncenB12_tf);//设置字体格式u8g2_DrawXBMP(&u8g2,x,0,16,16,luo);u8g2_DrawXBMP(&u8g2,x+16,0,16,16,bi);u8g2_DrawXBMP(&u8g2,x+32,0,16,16,tai);u8g2_DrawXBMP(&u8g2,x+48,0,16,16,huang);u8g2_DrawXBMP(&u8g2,x+64,0,16,16,zhang);u8g2_SendBuffer(&u8g2);}
效果展示:
4.显示一个图案
选图:
取模:
以下是我用取模工具提取的图片的位图数据:
#define wall_e_bmp01_x 128
#define wall_e_bmp01_y 64
static const unsigned char wall_e_bmp01[] U8X8_PROGMEM = {
{
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x00,0x00,0xF0,0x9F,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x70,0xF0,0x9B,0xFF,0x07,0x00,0x00,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x00,0x00,0xC0,0x07,0xF3,0xFF,0xFF,0x01,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0xFC,0x0F,0x3F,0x3C,0x00,0xE0,0x07,0x00,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x80,0xFF,0xFF,0xFF,0x03,0x00,0x00,0x3C,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0xF0,0x07,0x00,0x00,0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x7E,0x00,0x78,0x00,0x00,0x00,0xC0,0xE0,0x03,0x00,0x00,0x00,0x01,0x00,0x00,0x80,0x0F,0xE0,0x7F,0x00,0xC0,0x0F,0x80,0x87,0x0F,0x00,0x00,0x00,
0x01,0x00,0x00,0xE0,0x03,0x7F,0x00,0x80,0xF9,0x7F,0x00,0x1E,0x1E,0x00,0x00,0x00,0x01,0x00,0x00,0x78,0xE0,0x07,0x00,0xE0,0xFE,0xFF,0x01,0x78,0x78,0x00,0x00,0x00,
0x01,0x00,0x00,0x3E,0xFC,0x00,0x00,0xF0,0xFF,0xFF,0x07,0xE0,0xE1,0x01,0x00,0x00,0x01,0x00,0x80,0x0F,0x0F,0x00,0xC0,0xF8,0xFF,0xFF,0x0F,0x80,0x87,0x07,0x00,0x00,
0x01,0x00,0xE0,0x83,0x00,0x00,0x70,0xFC,0xFF,0xFF,0x1F,0x00,0x0F,0x0F,0x00,0x00,0x01,0x00,0xF0,0x00,0x00,0x00,0x78,0x3E,0x00,0xC0,0x3F,0x0E,0x1E,0x3C,0x00,0x00,
0x01,0x00,0x3C,0x00,0x00,0x06,0x38,0x1E,0x00,0x00,0x7C,0x3C,0x38,0xF8,0x00,0x00,0x01,0x00,0x1E,0x80,0x81,0x03,0x38,0x1E,0x00,0x00,0xF8,0x70,0x70,0xF0,0x01,0x00,
0x01,0x00,0x07,0xC2,0xC0,0x03,0x38,0x1F,0x00,0x00,0xF8,0xF1,0xE1,0xC0,0x03,0x00,0x01,0x80,0x13,0xC3,0xC0,0x01,0x31,0x1F,0x00,0x00,0xF0,0xE2,0xC3,0x81,0x07,0x00,
0x01,0xC0,0x11,0xE3,0xE0,0x01,0x03,0x1F,0x00,0x00,0xF0,0xC7,0x87,0x01,0x0F,0x00,0x01,0xF0,0x88,0x63,0xE0,0x00,0x07,0x1F,0x00,0x00,0xFC,0xFF,0x0F,0x07,0x0F,0x00,
0x01,0x70,0x8C,0x63,0xF0,0x00,0x07,0xFE,0x1F,0x00,0x3F,0xFE,0x8F,0x0F,0x0F,0x00,0x01,0xC0,0x8F,0x63,0xF0,0x10,0x0F,0xFE,0xFF,0xC1,0x03,0xC0,0x1F,0x1F,0x0F,0x00,
0x01,0x00,0x9F,0xF3,0xE0,0x10,0x1F,0x3E,0xC0,0xE7,0x00,0x00,0x3F,0x3F,0x0F,0x00,0x01,0x00,0x9C,0xF3,0xE0,0x70,0xFF,0x3F,0x00,0x7F,0x00,0xF8,0x3C,0x3C,0x0F,0x00,
0x01,0x00,0x1C,0xF7,0xC0,0xF0,0xFE,0x3F,0x3C,0x3E,0x00,0xFE,0xFB,0x7F,0x0E,0x00,0x01,0x00,0x3C,0xFE,0x01,0xF0,0x7F,0x07,0xFF,0x3C,0x00,0xFE,0xF3,0xFF,0x07,0x00,
0x01,0x00,0x3C,0xFC,0x03,0xF0,0x0F,0x80,0xFF,0x3D,0x00,0xFC,0xF1,0xF3,0x03,0x00,0x01,0x00,0x38,0xF0,0x03,0xD0,0x07,0x80,0xFF,0x7C,0x00,0x70,0xB8,0x07,0x00,0x00,
0x01,0x00,0xF8,0xFC,0x06,0xF0,0x07,0x00,0x7E,0xFC,0x00,0x00,0x9C,0x07,0x00,0x00,0x01,0x00,0xF8,0xFF,0xFF,0xFF,0x0F,0x00,0x00,0xCE,0x01,0x00,0x0F,0x0F,0x00,0x00,
0x01,0x00,0x20,0xFF,0xFF,0x7F,0x1E,0x00,0x80,0xFF,0x0F,0xC0,0x03,0x0F,0x00,0x00,0x01,0x00,0x00,0x0F,0xFF,0xFF,0xF8,0x00,0xE0,0xFF,0xFF,0xFF,0xF8,0x0F,0x00,0x00,
0x01,0x00,0x00,0x0F,0xFF,0xFF,0xE1,0xFF,0xFF,0x00,0xF0,0x07,0xFF,0x0F,0x00,0x00,0x01,0x00,0x00,0x0F,0xFF,0xFF,0x01,0xFE,0x0F,0x00,0x80,0xC7,0xFF,0x0F,0x00,0x00,
0x01,0x00,0x00,0x1E,0xFF,0xFF,0x01,0xC0,0x03,0x00,0x00,0xEF,0xFF,0x07,0x00,0x00,0x01,0x00,0x00,0x3E,0xFE,0xFF,0x01,0xE0,0x0F,0x00,0xF0,0xE7,0xFF,0x03,0x00,0x00,
0x01,0x00,0x00,0x7C,0xFC,0x7F,0x00,0xE0,0xFF,0xFF,0xFF,0xE3,0xFF,0x03,0x00,0x00,0x01,0x00,0x00,0xF8,0xE0,0x0F,0x00,0xC0,0xCF,0xFF,0xF7,0xC1,0xFF,0x01,0x00,0x00,
0x01,0x00,0x00,0xE0,0x01,0x00,0x00,0x00,0x7F,0x00,0x7F,0x00,0x7F,0x00,0x00,0x00,0x01,0x00,0x00,0x80,0xCF,0x3F,0x00,0x00,0xF8,0xFF,0x0F,0x80,0x1F,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0xFF,0xFF,0x3F,0x00,0x00,0x00,0x00,0xF8,0x07,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0xFC,0xFF,0xFF,0x1F,0x00,0x00,0x80,0xFF,0x00,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0xFE,0xFF,0xFF,0xFF,0x1F,0x00,0xF0,0x3F,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,0x00,0x00,0x80,
0x01,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x80,0x01,0x00,0x00,0x80,0xF3,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x80,
0x01,0x00,0x00,0xC0,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x00,0x00,0x00,0x80,0x01,0x00,0x00,0xC0,0x00,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x00,0x80,
0x01,0x00,0x00,0xC0,0x03,0x3C,0xFF,0xFF,0xFF,0xFF,0x9F,0xFF,0x07,0x00,0x00,0x80,0x01,0x00,0x00,0xE0,0x1F,0xFC,0xFF,0xFF,0xFF,0xEF,0xCF,0xFF,0x0F,0x00,0x00,0x80,
0x01,0x00,0x00,0xF0,0x7F,0xF8,0xFF,0xFF,0xFF,0xF8,0xC7,0xFF,0x1F,0x00,0x00,0x80,0x01,0x00,0x00,0xF8,0xFF,0xF8,0xFF,0xFF,0x01,0xFF,0xE7,0xFF,0x3F,0x00,0x00,0x80,
0x01,0x00,0x00,0xFC,0xFF,0xF9,0xFF,0xFF,0xE3,0xFF,0xE3,0xFF,0x7F,0x00,0x00,0x80,0x01,0x00,0x00,0xFC,0xFF,0xF1,0xFF,0xFF,0xFB,0xFF,0xE3,0xFF,0xFF,0x00,0x00,0x80,
0x01,0x00,0x00,0xFE,0xFF,0xF3,0xFF,0xFF,0xFB,0xFF,0xF3,0xFF,0xFF,0x01,0x00,0x80,0x01,0x00,0x00,0xFE,0xFF,0xF3,0xFF,0xFF,0xE0,0xFF,0xF3,0xFF,0xFF,0x01,0x00,0x80,
0x01,0x00,0x00,0xFE,0xFF,0xF7,0xFF,0x7F,0x00,0xFF,0xF3,0xFF,0xFF,0x03,0x00,0x80,0x01,0x00,0x00,0xFF,0xFF,0xE7,0xFF,0xFF,0xF7,0xFF,0xF3,0xFF,0xFF,0x03,0x00,0x80,
/* (128 X 64 )*/
}
显示:
U8g2库操作位图的方法主要有
void u8g2_DrawBitmap(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t cnt, u8g2_uint_t h, const uint8_t *bitmap);
void u8g2_DrawXBM(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, const uint8_t *bitmap);
void u8g2_DrawXBMP(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, const uint8_t *bitmap);
几种方法的实现都大同小异,所以选取了如下的方法进行绘制操作
u8g2_DrawXBMP(&u8g2, 0, 0, wall_e_bmp01_x,wall_e_bmp01_y, wall_e_bmp01);
u8g2_SendBuffer(&u8g2);
效果如下:
总结
利用u8g2能让oled显示图案,汉字,字符等,让我感受到了单片机学习的乐趣
参考链接:
基于STM32移植U8g2图形库——OLED显示(HAL库)_stm32 u8g2-CSDN博客
STM32+OLED屏显示字符串、汉字、图片(二)_oled显示中文代码-CSDN博客
玩转u8g2 OLED库,一篇就够——基于SMT32、HAL-CSDN博客
U8G2中文显示问题(u8g2.drawStr()中文不显示)_u8g2显示中文-CSDN博客