我是靠谱客的博主 要减肥小土豆,最近开发中收集的这篇文章主要介绍cebemax hal库 stm32 OLED移植 解析cebemax hal库 stm32 OLED移植,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

cebemax hal库 stm32 OLED移植

序言:

这是一篇对于作者对于将OLED的驱动代码移植成hal库的文章,会有完整的过程,后面自然也会有完整的代码,希望能够帮到大家,同时也是做一个记录,方便自己查看。

注:萌新写文,大佬轻喷。

1.写命令与数据函数的完成

原标准库代码

void I2C_Configuration(void)
{
	I2C_InitTypeDef I2C_InitStructure;
	GPIO_InitTypeDef GPIO_InitStructure;
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
	GPIO_Init(GPIOB, &GPIO_InitStructure);
	I2C_DeInit(I2C1);
	I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
	I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
	I2C_InitStructure.I2C_OwnAddress1 = 0x30;
	I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
	I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
	I2C_InitStructure.I2C_ClockSpeed = 400000;
	I2C_Cmd(I2C1, ENABLE);
	I2C_Init(I2C1, &I2C_InitStructure);
}
void I2C_WriteByte(uint8_t addr,uint8_t data)
{
	while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY));
	I2C_GenerateSTART(I2C1, ENABLE);
	while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
	I2C_Send7bitAddress(I2C1, OLED_ADDRESS, I2C_Direction_Transmitter);
	while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
	I2C_SendData(I2C1, addr);
	while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
	I2C_SendData(I2C1, data);
	while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
	I2C_GenerateSTOP(I2C1, ENABLE);
}
void WriteCmd(unsigned char I2C_Command)
{
	I2C_WriteByte(0x00, I2C_Command);
}
void WriteDat(unsigned char I2C_Data)
{
	I2C_WriteByte(0x40, I2C_Data);
}

函数说明

I2C_Configuration 其实就是 I2C 的初始化函数,hal库里有现成的,所以删除。
I2C_WriteByte 在下面的两个函数有用到,但hal库里有现成的,所以删除。
WriteCmd 和 WriteDat 改写成 HAL 库的方式DelayMs 改为 HAL 库中的函数: HAL_I2C_Mem_Write……

所以就变成了

函数移植

void WriteCmd(unsigned char I2C_Command)
{
	HAL_I2C_Mem_Write(&hi2c1,0X78,0x00,I2C_MEMADD_SIZE_8BIT,&I2C_Command,1,100);
}
void WriteDat(unsigned char I2C_Data)
{
	HAL_I2C_Mem_Write(&hi2c1,0X78,0x40,I2C_MEMADD_SIZE_8BIT,&I2C_Data,1,100);
}

大家一定很疑惑,为啥一下子就变成这样了勒?
别急,接下来就来好好讲讲。
首先,我们先来看看HAL_I2C_Mem_Write函数的原型。
机翻,不一定会很准确,但能看懂。

移植代码的说明

说过了,是机翻,作者英语不好。

/**
* @brief以阻塞模式向特定内存地址写入大量数据
* @param hi2c指针指向一个I2C_HandleTypeDef结构,包含
*指定I2C的配置信息。
目标设备地址:设备7位地址值
*在数据表中必须在调用接口前向左移动
* @param MemAddress内存地址
* @param MemAddSize内存地址的大小
@param pData指向数据缓冲区的指针
* @param大小要发送的数据量
* @param超时超时持续时间
@retval HAL状态
  */

我们再对照着完整的函数看。

HAL_StatusTypeDef HAL_I2C_Mem_Write(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout)

两相对照,我们就能够看明白每一个参数大概是干啥的。

参数一:I2C_HandleTypeDef *hi2c
指向包含指定I2C的配置信息的I2C_HandleTypeDef结构的指针,大概就是填写你所使用的i2c通道,如&hi2c1,&hi2c2。

参数二:uint16_t DevAddress
这里填目标设备地址,7位地址值。

参数三:uint16_t MemAddress
内存地址,也是目标设备的。

参数四:uint16_t MemAddSize
内存地址的大小,目标设备。

参数五:uint8_t *pData
指向数据缓冲区的指针,要写的东西。

参数六:uint16_t Size
要发送的数据量。

参数七:uint32_t Timeout
超时持续时间,大概就是,传输了多久还没传输完,就算他超时。

这样一来,我们再来看一下我之前写的那两个函数。

void WriteCmd(unsigned char I2C_Command)
{
	HAL_I2C_Mem_Write(&hi2c1,0X78,0x00,I2C_MEMADD_SIZE_8BIT,&I2C_Command,1,100);
}
void WriteDat(unsigned char I2C_Data)
{
	HAL_I2C_Mem_Write(&hi2c1,0X78,0x40,I2C_MEMADD_SIZE_8BIT,&I2C_Data,1,100);
}

大概能看明白了吧。
其中,0X78就是OLED的地址,这是默认地址,还有一种是0X7A的,具体怎么搞,我也没仔细研究,暂时用不上。
I2C_MEMADD_SIZE_8BIT是一个宏定义

#define I2C_MEMADD_SIZE_8BIT            0x00000001U

代码的优化

作者想了想之后,这个函数还可以再优化一下。
两个函数合成一个,方便使用。

void OLED_Write(unsigned char dat,unsigned char cmd)
{
	if(cmd)
		HAL_I2C_Mem_Write(&hi2c1,0X78,0x00,I2C_MEMADD_SIZE_8BIT,&dat,1,100);
	else
		HAL_I2C_Mem_Write(&hi2c1,0X78,0x40,I2C_MEMADD_SIZE_8BIT,&dat,1,100);
}

显而易见,dat填要写的数据,cmd选择是写数据还是写命令。
那么,到此,最为基本的写命令与数据的函数就完成了。
接下来,开始写初始化。

2.OLED初始化函数

原标准库函数

void OLED_Init(void)
{
	IIC_Init();
	DelayMs(500);								//初始化之前的延时很重要!
	OLED_WR_Byte(0xAE,OLED_CMD); //关闭显示
	OLED_WR_Byte(0x00,OLED_CMD);//设置低列地址
	OLED_WR_Byte(0x10,OLED_CMD);//设置高列地址
	OLED_WR_Byte(0x40,OLED_CMD);//设置起始行地址,集映射RAM显示起始行(0x00~0x3F)
	OLED_WR_Byte(0x81,OLED_CMD);//设置对比度控制寄存器
	OLED_WR_Byte(0xCF,OLED_CMD);//设置SEG输出电流亮度
	OLED_WR_Byte(0xA1,OLED_CMD);//段重定义设置,bit0:0,0->0;1,0->127; 0xa0左右反置 0xa1正常
	OLED_WR_Byte(0xC8,OLED_CMD);//设置COM扫描方向;bit3:0,普通模式;1,重定义模式 COM[N-1]->COM0;N:驱动路数   0xc0上下反置 0xc8正常
	OLED_WR_Byte(0xA6,OLED_CMD);//设置正常显示(设置显示方式;bit0:1,反相显示;0,正常显示	)
	OLED_WR_Byte(0xA8,OLED_CMD);//设置驱动路数 设置多路复用比(1比64)
	OLED_WR_Byte(0x3F,OLED_CMD);//1/64 duty(默认0X3F(1/64))
	OLED_WR_Byte(0xD3,OLED_CMD);//设置显示偏移位移映射RAM计数器(0x00~0x3F)
	OLED_WR_Byte(0x00,OLED_CMD);//-not offset
	OLED_WR_Byte(0xD5,OLED_CMD);//设置显示时钟分频比/振荡器频率
	OLED_WR_Byte(0x80,OLED_CMD);//设置分频比,设置时钟为100帧/秒
	OLED_WR_Byte(0xD9,OLED_CMD);//设置预充电周期
	OLED_WR_Byte(0xF1,OLED_CMD);//设置预充15个时钟,放电1个时钟([3:0],PHASE 1;[7:4],PHASE 2;)
	OLED_WR_Byte(0xDA,OLED_CMD);//设置COM硬件引脚配置
	OLED_WR_Byte(0x12,OLED_CMD);//[5:4]配置
	OLED_WR_Byte(0xDB,OLED_CMD);//设置VCOMH 电压倍率
	OLED_WR_Byte(0x40,OLED_CMD);//Set VCOM 释放电压([6:4] 000,0.65*vcc;001,0.77*vcc;011,0.83*vcc;)
	OLED_WR_Byte(0x20,OLED_CMD);//设置页面寻址模式(0x00/0x01/0x02)
	OLED_WR_Byte(0x02,OLED_CMD);//[1:0],00,列地址模式;01,行地址模式;10,页地址模式;默认10;
	OLED_WR_Byte(0x8D,OLED_CMD);//设置充电泵启用/禁用
	OLED_WR_Byte(0x14,OLED_CMD);//设置(0x10禁用,0x14启用)
	OLED_WR_Byte(0xA4,OLED_CMD);// 全局显示开启;bit0:1,开启;0,关闭;(白屏/黑屏) (0xa4/0xa5)
	OLED_WR_Byte(0xA6,OLED_CMD);// 设置显示方式;bit0:1,反相显示;0,正常显示 (0xa6/a7) 
	OLED_WR_Byte(0xAF,OLED_CMD);//开启显示	
	OLED_Clear();
	OLED_SetCursorAddrese(0,0);
}

这个不用解释吧,无非是定好的一连串命令。
一个个写太麻烦,搞一个数组。

移植后函数

const uint8_t OLED_Init_cmd[28]=
	{
	0xAE, //关闭显示
	0x00,//设置低列地址
	0x10,//设置高列地址
	0x40,//设置起始行地址,集映射RAM显示起始行(0x00~0x3F)
	0x81,//设置对比度控制寄存器
	0xCF,//设置SEG输出电流亮度
	0xA1,//段重定义设置,bit0:0,0->0;1,0->127; 0xa0左右反置 0xa1正常
	0xC8,//设置COM扫描方向;bit3:0,普通模式;1,重定义模式 COM[N-1]->COM0;N:驱动路数   0xc0上下反置 0xc8正常
	0xA6,//设置正常显示(设置显示方式;bit0:1,反相显示;0,正常显示	)
	0xA8,//设置驱动路数 设置多路复用比(1比64)
	0x3F,//1/64 duty(默认0X3F(1/64))
	0xD3,//设置显示偏移位移映射RAM计数器(0x00~0x3F)
	0x00,//-not offset
	0xD5,//设置显示时钟分频比/振荡器频率
	0x80,//设置分频比,设置时钟为100帧/秒
	0xD9,//设置预充电周期
	0xF1,//设置预充15个时钟,放电1个时钟([3:0],PHASE 1;[7:4],PHASE 2;)
	0xDA,//设置COM硬件引脚配置
	0x12,//[5:4]配置
	0xDB,//设置VCOMH 电压倍率
	0x40,//Set VCOM 释放电压([6:4] 000,0.65*vcc;001,0.77*vcc;011,0.83*vcc;)
	0x20,//设置页面寻址模式(0x00/0x01/0x02)
	0x02,//[1:0],00,列地址模式;01,行地址模式;10,页地址模式;默认10;
	0x8D,//设置充电泵启用/禁用
	0x14,//设置(0x10禁用,0x14启用)
	0xA4,// 全局显示开启;bit0:1,开启;0,关闭;(白屏/黑屏) (0xa4/0xa5)
	0xA6,// 设置显示方式;bit0:1,反相显示;0,正常显示 (0xa6/a7) 
	0xAF //开启显示
};

然后再加一个初始化的for循环

void OLED_Init(void)
{
	uint8_t i;
	//IIC_Init(); //cubemax自动生成了,我们不需要。
	HAL_Delay(500);								//初始化之前的延时很重要!
	for(i = 0;i < 29;i ++)
	{
	 OLED_Write(OLED_Init_cmd[i],1);
	}
	OLED_Clear();
	OLED_SetCursorAddrese(0,0);
}

原初始化函数里还有三个函数的调用,其中一个我们不需要,另外两个我们先放着,一个是用来清屏的,还有一个是用来设置光标位置的,后面马上就可以看到。
那么,至此,初始化便完成了,我们继续改其他的函数。
上原函数。

3.OLED其他功能函数移植

开显示,关显示,还有显示一个点的原函数

/*函数功能:开启OLED显示 */
void OLED_Display_On(void)
{
	OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC命令(设置电荷泵)
	OLED_WR_Byte(0X14,OLED_CMD);  //DCDC ON (开启电荷泵)
	OLED_WR_Byte(0XAF,OLED_CMD);  //DISPLAY ON(OLED唤醒)
}
/*函数功能:关闭OLED显示*/ 
 
void OLED_Display_Off(void)
{
	OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC命令 (设置电荷泵)
	OLED_WR_Byte(0X10,OLED_CMD);  //DCDC OFF (关闭电荷泵)
	OLED_WR_Byte(0XAE,OLED_CMD);  //DISPLAY OFF (OLED休眠)
}
 
 
/*
函数功能:清屏函数,清完屏,整个屏幕是黑色的!  
说明: 清屏就是向OLED里写0
      对于OLED屏,0就不显示,1才会在屏幕上显示出来一个点
*/
void OLED_Clear(void)  
{  
	u8 i,n;  
	for(i=0;i<8;i++)
	{
		OLED_WR_Byte(0xB0+i,OLED_CMD);//设置页地址(0~7)
		OLED_WR_Byte(0x00,OLED_CMD);  //设置显示位置―列低地址
		OLED_WR_Byte(0x10,OLED_CMD);  //设置显示位置―列高地址 
		for(n=0;n<128;n++)
		{
			OLED_WR_Byte(0x00,OLED_DATA);
		}
	}
}

开显示的修改

/*函数功能:开启OLED显示 */
void OLED_Display_On(void)
{
	OLED_Write(0X8D,1);//SET DCDC命令(设置电荷泵)
	OLED_Write(0X14,1);//DCDC ON (开启电荷泵)
	OLED_Write(0XAF,1);//DISPLAY ON(OLED唤醒)
}

关显示的修改

/*函数功能:关闭OLED显示*/ 
void OLED_Display_Off(void)
{
	OLED_Write(0X8D,1);//SET DCDC命令 (设置电荷泵)
	OLED_Write(0X10,1); //DCDC OFF (关闭电荷泵)
	OLED_Write(0XAE,1);//DISPLAY OFF (OLED休眠)
}

清屏函数的修改

/*
函数功能:清屏函数,清完屏,整个屏幕是黑色的!  
说明: 清屏就是向OLED里写0
      对于OLED屏,0就不显示,1才会在屏幕上显示出来一个点
*/
void OLED_Clear(void)  
{  
	u8 i,n;  
	for(i=0;i<8;i++)
	{
		OLED_Write(0xB0+i,1);//设置页地址(0~7)
		OLED_Write(0x00,1);//设置显示位置―列低地址
		OLED_Write(0x10,1);//设置显示位置―列高地址 
		for(n=0;n<128;n++)
		{
			OLED_Write(0x00,0);
		}
	}
}

直接复制的小伙伴,是不是有些出现了问题,哈哈。
是一些有关于宏定义的问题。
在c文件里加上这一段就行:

typedef   signed          char int8_t;    //  标准表达方式 signed char 被等同于 int8_t;
typedef   signed short     int int16_t;
typedef   signed           int int32_t;   //在32位环境里,int代表4个字节32位!!

/* exact-width unsigned integer types */
typedef unsigned          char uint8_t;
typedef unsigned short     int uint16_t;
typedef unsigned           int uint32_t;

typedef int32_t  s32;
typedef int16_t s16;
typedef int8_t  s8;

typedef uint32_t  u32; //32位
typedef uint16_t u16;  //16位
typedef uint8_t  u8;   //8位

接下来便是

写点,设光标以及垂直滚动的原函数

/*
函数功能:在显存数组上画一个点
函数参数:x,y为点的横纵坐标   c为这个点的亮灭(1亮0灭)
参数范围:x 0~128  y 0~8 
每一个数据是 低位在前,高位在后
*/
void OLED_Draw_Point(u8 x,u8 y,u8 c)
{
	u8 page,addr;
	page = y/8; //显存的页地址
	addr = y%8; //显存的一个字节数据中c所在的位置 
	if(c) OLED_GRAM[page][x] |= 1<<addr;
	else  OLED_GRAM[page][x] &= ~(1<<addr);
}
/*
函数功能: 设置光标位置
函数参数: x列的起始位置(0~127)
				  y页的起始位置(0~7)
比如: 0x8  高4位0000   低4位1000 
*/
void OLED_SetCursorAddrese(u8 x,u8 y)
{
		OLED_WR_Byte(0xB0+y,OLED_CMD); 					//设置页地址
	  //第6列显示数据  6被分成2个4位(高位和低位)。
		OLED_WR_Byte((x&0xF0)>>4|0x10,OLED_CMD);//设置列高起始地址(半字节)
		OLED_WR_Byte((x&0x0F)|0x00,OLED_CMD);   //设置列低起始地址(半字节)			
}
/*****************************************************
** 函数名称:OLED_VerticalDisplay
** 函数功能:实现OLED垂直滚动范围配置
** 参    数:1.toprow:设置滚动起始行
**           2.scrollrow:设置滚动行数
**           注意:toprow+scrollrow<64
** 函数返回:无
******************************************************/
void OLED_VerticalDisplay(u8 toprow,u8 scrollrow)
{
	OLED_WR_Byte(SET_VERTICAL_SCROLL_AREA,OLED_CMD);
	OLED_WR_Byte(toprow,OLED_CMD);
	OLED_WR_Byte(scrollrow,OLED_CMD);
}

写点函数的修改

这些函数的名字啥的我都懒得改了,无所谓的。

/*
函数功能:在显存数组上画一个点
函数参数:x,y为点的横纵坐标   c为这个点的亮灭(1亮0灭)
参数范围:x 0~128  y 0~8 
每一个数据是 低位在前,高位在后
*/
void OLED_Draw_Point(u8 x,u8 y,u8 c)
{
	u8 page,addr;
	page = y/8; //显存的页地址
	addr = y%8; //显存的一个字节数据中c所在的位置 
	if(c) OLED_GRAM[page][x] |= 1<<addr;
	else  OLED_GRAM[page][x] &= ~(1<<addr);
}

这个好像不用改,不过涉及到一个数组,之前没有定义,定义一下。

u8 OLED_GRAM[8][128];/*定义OLED显存数组*/

函数内容很简单,就是要让哪位显示出来,就给哪位赋值一个1,不显示就给那位非一下,赋值0.

设光标函数的修改

/*
函数功能: 设置光标位置
函数参数: x列的起始位置(0~127)
				  y页的起始位置(0~7)
比如: 0x8  高4位0000   低4位1000 
*/
void OLED_SetCursorAddrese(u8 x,u8 y)
{		
		OLED_Write(0xB0+y,1);	//设置页地址
	  //第6列显示数据  6被分成2个4位(高位和低位)。
		OLED_Write((x&0xF0)>>4|0x10,1);//设置列高起始地址(半字节)
		OLED_Write((x&0x0F)|0x00,1);  //设置列低起始地址(半字节)			
}

滚动函数修改

/*****************************************************
** 函数名称:OLED_VerticalDisplay
** 函数功能:实现OLED垂直滚动范围配置
** 参    数:1.toprow:设置滚动起始行
**           2.scrollrow:设置滚动行数
**           注意:toprow+scrollrow<64
** 函数返回:无
******************************************************/
void OLED_VerticalDisplay(u8 toprow,u8 scrollrow)
{
	OLED_Write(0xA3,1);//设置垂直滚动范围命令
	OLED_Write(toprow,1);//设置滚动起始行
	OLED_Write(scrollrow,1);//设置滚动行数
}

关闭滚动, 按页清屏,更新显示原函数

/*****************************************************
** 函数名称:OledScrollStop
** 函数功能:关闭滚屏功能
******************************************************/ 
void OledScrollStop(void)
{
	OLED_WR_Byte(DEACTIVATE_SCROLL,OLED_CMD);
}
 
/*
函数功能: 按页清屏 (0~7)
*/
void OLED_PageClear(u8 page)
{
		u8 j;
		OLED_WR_Byte(0xB0+page,OLED_CMD); //设置页地址
		OLED_WR_Byte(0x10,OLED_CMD);      //设置列高起始地址(半字节)
		OLED_WR_Byte(0x00,OLED_CMD);      //设置列低起始地址(半字节)
		for(j=0;j<128;j++)
		{
				OLED_WR_Byte(0,OLED_DATA); //写数据
		}
}
 
/*
函数功能:更新显存到OLED屏幕上
*/
void OLED_Refresh_Screen(void)
{
	u8 page,list;  //定义页地址和列地址
	for(page=0;page<8;page++)
	{
		OLED_WR_Byte(0xB0+page,OLED_CMD); //设置页地址(0~7)
		OLED_WR_Byte(0x00,OLED_CMD);      //设置显示位置―列低地址
		OLED_WR_Byte(0x10,OLED_CMD);      //设置显示位置―列高地址 
		for(list=0;list<128;list++)
		{
			OLED_WR_Byte(OLED_GRAM[page][list],OLED_DATA);
		}
	}
	memset(OLED_GRAM,0,sizeof(OLED_GRAM));	/*清空显存数组*/
}

关闭滚动函数修改

/*****************************************************
** 函数名称:OledScrollStop
** 函数功能:关闭滚屏功能
******************************************************/ 
void OledScrollStop(void)
{
	OLED_Write(0x2E,1);//关闭滚动显示功能
}

按页清屏函数修改

/*
函数功能: 按页清屏 (0~7)
*/
void OLED_PageClear(u8 page)
{
		u8 j;
		OLED_Write(0xB0+page,1); //设置页地址 
		OLED_Write(0x10,1);   //设置列高起始地址(半字节)
		OLED_Write(0x00,1);   //设置列低起始地址(半字节)
		for(j=0;j<128;j++)
		{
				OLED_Write(0,0); //写数据
		}
}

更新显示函数修改

/*
函数功能:更新显存到OLED屏幕上
*/
void OLED_Refresh_Screen(void)
{
	u8 page,list;  //定义页地址和列地址
	for(page=0;page<8;page++)
	{
		OLED_Write(0xB0+page,1); //设置页地址(0~7)
		OLED_Write(0x00,1);      //设置显示位置―列低地址
		OLED_Write(0x10,1);      //设置显示位置―列高地址 
		for(list=0;list<128;list++)
		{
			OLED_Write(OLED_GRAM[page][list],0);
		}
	}
	memset(OLED_GRAM,0,sizeof(OLED_GRAM));	/*清空显存数组*/
}

memset(OLED_GRAM,0,sizeof(OLED_GRAM)); /清空显存数组/这个函数是#include "string.h"这里面的一个函数,整句话的意思是,向OLED_GRAM数组里面写满0.

4.字符显示函数

基础的函数都移植完了,那么接下来就是显示的函数了,原函数这里就不放了。
原程序里他把中英文搞一块儿我觉得编程序的时候不太友好,给阉割了, 我给单独领出来了,这里只能显示些英文符号。
也不是说他那样干不好,不过一般我们用起来其实最多几个汉字,自己取一下模就行。
或者有兴趣的也可以按照他那样搞一个中文字库,哈哈,有搞好的千万@我一下。
我还是把他的原版程序给你们看看吧。

原程序

void OLED_DisplayString(u8 x,u8 y,u8 width,u8 height,u8 *str)
{
	u8 addr=0,i;
	u16 font=0;
	while(*str!='') //连续显示
	{
		//取模从空格开始的,计算下标
		//写8*16ASCII字符的上半部分
		if(*str >= ' '&& *str <= '~') //显示英文
		{
			addr=*str-' '; //取模从空格开始的,计算下标
			//写8*16ASCII字符的上半部分
			OLED_SetCursorAddrese(x,y); //设置光标的位置
			for(i=0;i<width/2;i++)      //横向写width列
			{
				 OLED_WR_Byte(ASCII_8_16[addr][i],OLED_DATA); 
			}
			//写8*16ASCII字符的下半部分
			OLED_SetCursorAddrese(x,y+1); //设置光标的位置
			for(i=0;i<width/2;i++)        //横向写width列
			{
				 OLED_WR_Byte(ASCII_8_16[addr][i+width/2],OLED_DATA); 
			}
			str++;//继续显示下一个字符
			x+=width/2; //在下一个位置继续显示数据			
		}
		else //显示中文
		{
			OLED_SetCursorAddrese(x,y); //设置光标的位置
			font=((*str)<<8)+(*(str+1));
			switch(font)
			{
				case 0xCEC2:addr=0;break;//温
				case 0xCAAA:addr=1;break;//湿
				case 0xB6C8:addr=2;break;//度
				case 0xCAFD:addr=3;break;//数
				case 0xBEDD:addr=4;break;//据
				case 0xB3C9:addr=5;break;//成
				case 0xB9A6:addr=6;break;//功
				case 0xB7A2:addr=7;break;//发
				case 0xCBCD:addr=8;break;//送
				case 0xC1AC:addr=9;break;//连
				case 0xBDD3:addr=10;break;//接
				case 0xB7FE:addr=11;break;//服
				case 0xCEF1:addr=12;break;//务
				case 0xC6F7:addr=13;break;//器
				case 0xC9CF:addr=14;break;//上
				case 0xCFC2:addr=15;break;//下
				case 0xCFDE:addr=16;break;//限
				case 0xD6B5:addr=17;break;//值
				case 0xC9E8:addr=18;break;//设
				case 0xD6C3:addr=19;break;//置
				case 0xB4AB:addr=20;break;//传
				case 0xD6DC:addr=21;break;//周
				case 0xC6DA:addr=22;break;//期
				case 0xBFD8:addr=23;break;//控
				case 0xD6C6:addr=24;break;//制
				case 0xB2CE:addr=25;break;//参
				case 0xD7DC:addr=26;break;//总
				case 0xB1ED:addr=27;break;//表
				case 0xB1B8:addr=28;break;//备
				case 0xCDF8:addr=29;break;//网
				case 0xC2E7:addr=30;break;//络
				case 0xD0C5:addr=31;break;//信
				case 0xCFA2:addr=32;break;//息
				case 0xCAA7:addr=33;break;//失
				case 0xB0DC:addr=34;break;//败
				case 0xB1A3:addr=35;break;//保
				case 0xB4E6:addr=36;break;//存
				case 0xB9FD:addr=37;break;//过
				case 0xB8DF:addr=38;break;//高
				case 0xA1E6:addr=39;break;//℃
				case 0xD0C7:addr=40;break;//星
				case 0xC8D5:addr=42;break;//日
				case 0xD2BB:addr=43;break;//一
				case 0xB6FE:addr=44;break;//二
				case 0xC8FD:addr=45;break;//三
				case 0xCBC4:addr=46;break;//四
				case 0xCEE5:addr=47;break;//五
				case 0xC1F9:addr=48;break;//六
				case 0xC4EA:addr=49;break;//年
				case 0xD4C2:addr=50;break;//月
				default : break;
			}
			for(i=0;i<width;i++) //横向写width列
			{
				 OLED_WR_Byte(ChineseFont_16_16[addr][i],OLED_DATA); 
			}
			
			//写8*16ASCII字符的下半部分
			OLED_SetCursorAddrese(x,y+1); //设置光标的位置
			for(i=0;i<width;i++)          //横向写width列
			{
				 OLED_WR_Byte(ChineseFont_16_16[addr][i+width],OLED_DATA); 
			}
			str+=2;//继续显示下一个字符
			x+=width; //在下一个位置继续显示数据
		}
	}
}

英文字符显示函数修改

void OLED_DisplayString(u8 x,u8 y,u8 *str)
{
	u8 addr=0,i;
	u16 font=0;
	while(*str!='') //连续显示
	{
		//取模从空格开始的,计算下标
		//写8*16ASCII字符的上半部分
			addr=*str-' '; //取模从空格开始的,计算下标
			//写8*16ASCII字符的上半部分
			OLED_SetCursorAddrese(x,y); //设置光标的位置
			for(i=0;i<8;i++)      //横向写width列
			{
				 OLED_Write(ASCII_8_16[addr][i],0); 
			}
			//写8*16ASCII字符的下半部分
			OLED_SetCursorAddrese(x,y+1); //设置光标的位置
			for(i=0;i<8;i++)        //横向写width列
			{
				 OLED_Write(ASCII_8_16[addr][i+8],0); 
			}
			str++;//继续显示下一个字符
			x+=8; //在下一个位置继续显示数据			
	}
}

ASCII_8_16数组

const u8 ASCII_8_16[][16]=
{
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",0*/
{0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x00,0x00,0x00,0x00},/*"!",1*/
{0x00,0x10,0x0C,0x02,0x10,0x0C,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*""",2*/
{0x00,0x40,0xC0,0x78,0x40,0xC0,0x78,0x00,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x00},/*"#",3*/
{0x00,0x70,0x88,0x88,0xFC,0x08,0x30,0x00,0x00,0x18,0x20,0x20,0xFF,0x21,0x1E,0x00},/*"$",4*/
{0xF0,0x08,0xF0,0x80,0x60,0x18,0x00,0x00,0x00,0x31,0x0C,0x03,0x1E,0x21,0x1E,0x00},/*"%",5*/
{0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x2C,0x19,0x27,0x21,0x10},/*"&",6*/
{0x00,0x12,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",7*/
{0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00},/*"(",8*/
{0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00},/*")",9*/
{0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00},/*"*",10*/
{0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x0F,0x01,0x01,0x01},/*"+",11*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x90,0x70,0x00,0x00,0x00,0x00,0x00},/*",",12*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x00},/*"-",13*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00},/*".",14*/
{0x00,0x00,0x00,0x00,0xC0,0x38,0x04,0x00,0x00,0x60,0x18,0x07,0x00,0x00,0x00,0x00},/*"/",15*/
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},/*"0",16*/
{0x00,0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00},/*"1",17*/
{0x00,0x70,0x08,0x08,0x08,0x08,0xF0,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},/*"2",18*/
{0x00,0x30,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x18,0x20,0x21,0x21,0x22,0x1C,0x00},/*"3",19*/
{0x00,0x00,0x80,0x40,0x30,0xF8,0x00,0x00,0x00,0x06,0x05,0x24,0x24,0x3F,0x24,0x24},/*"4",20*/
{0x00,0xF8,0x88,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x20,0x20,0x20,0x11,0x0E,0x00},/*"5",21*/
{0x00,0xE0,0x10,0x88,0x88,0x90,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x20,0x1F,0x00},/*"6",22*/
{0x00,0x18,0x08,0x08,0x88,0x68,0x18,0x00,0x00,0x00,0x00,0x3E,0x01,0x00,0x00,0x00},/*"7",23*/
{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00},/*"8",24*/
{0x00,0xF0,0x08,0x08,0x08,0x10,0xE0,0x00,0x00,0x01,0x12,0x22,0x22,0x11,0x0F,0x00},/*"9",25*/
{0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00},/*":",26*/
{0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00},/*";",27*/
{0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00},/*"<",28*/
{0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x02,0x00},/*"=",29*/
{0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00},/*">",30*/
{0x00,0x70,0x48,0x08,0x08,0x88,0x70,0x00,0x00,0x00,0x00,0x30,0x37,0x00,0x00,0x00},/*"?",31*/
{0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x28,0x2F,0x28,0x17,0x00},/*"@",32*/
{0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20},/*"A",33*/
{0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00},/*"B",34*/
{0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00},/*"C",35*/
{0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00},/*"D",36*/
{0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00},/*"E",37*/
{0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00},/*"F",38*/
{0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00},/*"G",39*/
{0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20},/*"H",40*/
{0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},/*"I",41*/
{0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00},/*"J",42*/
{0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00},/*"K",43*/
{0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00},/*"L",44*/
{0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x01,0x3E,0x01,0x3F,0x20,0x00},/*"M",45*/
{0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00},/*"N",46*/
{0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00},/*"O",47*/
{0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00},/*"P",48*/
{0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x28,0x28,0x30,0x50,0x4F,0x00},/*"Q",49*/
{0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20},/*"R",50*/
{0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00},/*"S",51*/
{0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00},/*"T",52*/
{0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00},/*"U",53*/
{0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00},/*"V",54*/
{0x08,0xF8,0x00,0xF8,0x00,0xF8,0x08,0x00,0x00,0x03,0x3E,0x01,0x3E,0x03,0x00,0x00},/*"W",55*/
{0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20},/*"X",56*/
{0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00},/*"Y",57*/
{0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00},/*"Z",58*/
{0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00},/*"[",59*/
{0x00,0x04,0x38,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00},/*"",60*/
{0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00},/*"]",61*/
{0x00,0x00,0x04,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"^",62*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80},/*"_",63*/
{0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"`",64*/
{0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x19,0x24,0x24,0x12,0x3F,0x20,0x00},/*"a",65*/
{0x10,0xF0,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00},/*"b",66*/
{0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00},/*"c",67*/
{0x00,0x00,0x80,0x80,0x80,0x90,0xF0,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20},/*"d",68*/
{0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x24,0x24,0x24,0x24,0x17,0x00},/*"e",69*/
{0x00,0x80,0x80,0xE0,0x90,0x90,0x20,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},/*"f",70*/
{0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00},/*"g",71*/
{0x10,0xF0,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20},/*"h",72*/
{0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},/*"i",73*/
{0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00},/*"j",74*/
{0x10,0xF0,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x06,0x29,0x30,0x20,0x00},/*"k",75*/
{0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},/*"l",76*/
{0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F},/*"m",77*/
{0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20},/*"n",78*/
{0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00},/*"o",79*/
{0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0x91,0x20,0x20,0x11,0x0E,0x00},/*"p",80*/
{0x00,0x00,0x00,0x80,0x80,0x00,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0x91,0xFF,0x80},/*"q",81*/
{0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00},/*"r",82*/
{0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00},/*"s",83*/
{0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x10,0x00},/*"t",84*/
{0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20},/*"u",85*/
{0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x03,0x0C,0x30,0x0C,0x03,0x00,0x00},/*"v",86*/
{0x80,0x80,0x00,0x80,0x80,0x00,0x80,0x80,0x01,0x0E,0x30,0x0C,0x07,0x38,0x06,0x01},/*"w",87*/
{0x00,0x80,0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x20,0x31,0x0E,0x2E,0x31,0x20,0x00},/*"x",88*/
{0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x81,0x86,0x78,0x18,0x06,0x01,0x00},/*"y",89*/
{0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00},/*"z",90*/
{0x00,0x00,0x00,0x00,0x00,0xFC,0x02,0x02,0x00,0x00,0x00,0x00,0x01,0x3E,0x40,0x40},/*"{",91*/
{0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00},/*"|",92*/
{0x02,0x02,0xFC,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0x3E,0x01,0x00,0x00,0x00,0x00},/*"}",93*/
{0x00,0x80,0x40,0x80,0x80,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00},/*"~",94*/
};

接下来就是:

中文显示函数修改

void OLED_DisplayChinese(u8 x,u8 y,u8 str)
{
	u8 addr=0,i;
	addr = str; //你要显示第几个汉字
	OLED_SetCursorAddrese(x,y); //设置光标的位置
	for(i=0;i<16;i++)      //横向写width列
	{
		 OLED_Write(ChineseFont_16_16[addr][i],0); 
	}
	OLED_SetCursorAddrese(x,y+1); //设置光标的位置
	for(i=0;i<16;i++)        //横向写width列
	{
		 OLED_Write(ChineseFont_16_16[addr][i+16],0); 
	}		
}

ChineseFont_16_16数组

const u8 ChineseFont_16_16[][32]=
{
{0x10,0x60,0x02,0x8C,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,0x04,0x04,0x7E,0x01,0x40,0x7E,0x42,0x42,0x7E,0x42,0x7E,0x42,0x42,0x7E,0x40,0x00},/*"温",0*/
{0x10,0x60,0x02,0x8C,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,0x04,0x04,0x7E,0x01,0x44,0x48,0x50,0x7F,0x40,0x40,0x7F,0x50,0x48,0x44,0x40,0x00},/*"湿",1*/
{0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00,0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00},/*"度",2*/
{0x90,0x52,0x34,0x10,0xFF,0x10,0x34,0x52,0x80,0x70,0x8F,0x08,0x08,0xF8,0x08,0x00,0x82,0x9A,0x56,0x63,0x22,0x52,0x8E,0x00,0x80,0x40,0x33,0x0C,0x33,0x40,0x80,0x00},/*"数",3*/
{0x10,0x10,0xFF,0x10,0x90,0x00,0xFE,0x92,0x92,0x92,0xF2,0x92,0x92,0x9E,0x80,0x00,0x42,0x82,0x7F,0x01,0x80,0x60,0x1F,0x00,0xFC,0x44,0x47,0x44,0x44,0xFC,0x00,0x00},/*"据",4*/
{0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0x08,0x08,0xFF,0x08,0x09,0x0A,0xC8,0x08,0x00,0x80,0x60,0x1F,0x00,0x10,0x20,0x1F,0x80,0x40,0x21,0x16,0x18,0x26,0x41,0xF8,0x00},/*"成",5*/
{0x08,0x08,0x08,0xF8,0x08,0x08,0x08,0x10,0x10,0xFF,0x10,0x10,0x10,0xF0,0x00,0x00,0x10,0x30,0x10,0x1F,0x08,0x88,0x48,0x30,0x0E,0x01,0x40,0x80,0x40,0x3F,0x00,0x00},/*"功",6*/
{0x00,0x00,0x18,0x16,0x10,0xD0,0xB8,0x97,0x90,0x90,0x90,0x92,0x94,0x10,0x00,0x00,0x00,0x20,0x10,0x8C,0x83,0x80,0x41,0x46,0x28,0x10,0x28,0x44,0x43,0x80,0x80,0x00},/*"发",7*/
{0x40,0x40,0x42,0xCC,0x00,0x88,0x89,0x8E,0x88,0xF8,0x88,0x8C,0x8B,0x88,0x80,0x00,0x00,0x40,0x20,0x1F,0x20,0x40,0x50,0x48,0x46,0x41,0x42,0x44,0x58,0x40,0x40,0x00},/*"送",8*/
{0x40,0x40,0x42,0xCC,0x00,0x04,0x44,0x64,0x5C,0x47,0xF4,0x44,0x44,0x44,0x04,0x00,0x00,0x40,0x20,0x1F,0x20,0x44,0x44,0x44,0x44,0x44,0x7F,0x44,0x44,0x44,0x44,0x00},/*"连",9*/
{0x10,0x10,0x10,0xFF,0x10,0x50,0x44,0x54,0x65,0xC6,0x44,0x64,0x54,0x44,0x40,0x00,0x04,0x44,0x82,0x7F,0x01,0x82,0x82,0x4A,0x56,0x23,0x22,0x52,0x4E,0x82,0x02,0x00},/*"接",10*/
{0x00,0x00,0xFE,0x22,0x22,0x22,0xFE,0x00,0xFE,0x82,0x82,0x92,0xA2,0x9E,0x00,0x00,0x80,0x60,0x1F,0x02,0x42,0x82,0x7F,0x00,0xFF,0x40,0x2F,0x10,0x2C,0x43,0x80,0x00},/*"服",11*/
{0x00,0x00,0x90,0x88,0x4C,0x57,0xA4,0x24,0x54,0x54,0x8C,0x84,0x00,0x00,0x00,0x00,0x01,0x01,0x80,0x42,0x22,0x1A,0x07,0x02,0x42,0x82,0x42,0x3E,0x01,0x01,0x01,0x00},/*"务",12*/
{0x80,0x80,0x9E,0x92,0x92,0x92,0x9E,0xE0,0x80,0x9E,0xB2,0xD2,0x92,0x9E,0x80,0x00,0x08,0x08,0xF4,0x94,0x92,0x92,0xF1,0x00,0x01,0xF2,0x92,0x94,0x94,0xF8,0x08,0x00},/*"器",13*/
{0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00},/*"上",14*/
{0x02,0x02,0x02,0x02,0x02,0x02,0xFE,0x02,0x02,0x42,0x82,0x02,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x01,0x06,0x00,0x00,0x00},/*"下",15*/
{0x00,0xFE,0x22,0x5A,0x86,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,0x00,0xFF,0x04,0x08,0x07,0x00,0xFF,0x40,0x20,0x03,0x0C,0x14,0x22,0x41,0x40,0x00},/*"限",16*/
{0x00,0x80,0x60,0xF8,0x07,0x04,0xE4,0xA4,0xA4,0xBF,0xA4,0xA4,0xE4,0x04,0x00,0x00,0x01,0x00,0x00,0xFF,0x40,0x40,0x7F,0x4A,0x4A,0x4A,0x4A,0x4A,0x7F,0x40,0x40,0x00},/*"值",17*/
{0x40,0x40,0x42,0xCC,0x00,0x40,0xA0,0x9E,0x82,0x82,0x82,0x9E,0xA0,0x20,0x20,0x00,0x00,0x00,0x00,0x3F,0x90,0x88,0x40,0x43,0x2C,0x10,0x28,0x46,0x41,0x80,0x80,0x00},/*"设",18*/
{0x00,0x17,0x15,0xD5,0x55,0x57,0x55,0x7D,0x55,0x57,0x55,0xD5,0x15,0x17,0x00,0x00,0x40,0x40,0x40,0x7F,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x7F,0x40,0x40,0x40,0x00},/*"置",19*/
{0x00,0x80,0x60,0xF8,0x07,0x40,0x48,0x48,0xE8,0x5F,0x48,0x48,0x48,0x40,0x40,0x00,0x01,0x00,0x00,0xFF,0x00,0x00,0x02,0x0B,0x12,0x22,0xD2,0x0A,0x06,0x00,0x00,0x00},/*"传",20*/
{0x00,0x00,0xFE,0x82,0x92,0x92,0x92,0xFE,0x92,0x92,0x92,0x82,0xFE,0x00,0x00,0x00,0x80,0x60,0x1F,0x00,0x00,0x1E,0x12,0x12,0x12,0x1E,0x40,0x80,0x7F,0x00,0x00,0x00},/*"周",21*/
{0x00,0x04,0xFF,0x24,0x24,0x24,0xFF,0x04,0x00,0xFE,0x22,0x22,0x22,0xFE,0x00,0x00,0x88,0x48,0x2F,0x09,0x09,0x19,0xAF,0x48,0x30,0x0F,0x02,0x42,0x82,0x7F,0x00,0x00},/*"期",22*/
{0x10,0x10,0x10,0xFF,0x90,0x20,0x98,0x48,0x28,0x09,0x0E,0x28,0x48,0xA8,0x18,0x00,0x02,0x42,0x81,0x7F,0x00,0x40,0x40,0x42,0x42,0x42,0x7E,0x42,0x42,0x42,0x40,0x00},/*"控",23*/
{0x40,0x50,0x4E,0x48,0x48,0xFF,0x48,0x48,0x48,0x40,0xF8,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x3E,0x02,0x02,0xFF,0x12,0x22,0x1E,0x00,0x0F,0x40,0x80,0x7F,0x00,0x00},/*"制",24*/
{0x00,0x20,0x20,0xA8,0x6C,0x2A,0x39,0x28,0xA8,0x2A,0x6C,0xA8,0x20,0x20,0x00,0x00,0x02,0x82,0x81,0x90,0x92,0x4A,0x49,0x45,0x24,0x22,0x10,0x08,0x01,0x02,0x02,0x00},/*"参",25*/
{0x00,0x00,0x00,0xF1,0x12,0x14,0x10,0x10,0x10,0x14,0x12,0xF1,0x00,0x00,0x00,0x00,0x40,0x30,0x00,0x03,0x39,0x41,0x41,0x45,0x59,0x41,0x41,0x73,0x00,0x08,0x30,0x00},/*"总",26*/
{0x00,0x04,0x24,0x24,0x24,0x24,0x24,0xFF,0x24,0x24,0x24,0x24,0x24,0x04,0x00,0x00,0x21,0x21,0x11,0x09,0xFD,0x83,0x41,0x23,0x05,0x09,0x11,0x29,0x25,0x41,0x41,0x00},/*"表",27*/
{0x80,0x90,0x90,0x48,0x4C,0x57,0x24,0x24,0x24,0x54,0x4C,0x44,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0xFF,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0xFF,0x00,0x00,0x00,0x00},/*"备",28*/
{0x00,0xFE,0x02,0x22,0x42,0x82,0x72,0x02,0x22,0x42,0x82,0x72,0x02,0xFE,0x00,0x00,0x00,0xFF,0x10,0x08,0x06,0x01,0x0E,0x10,0x08,0x06,0x01,0x4E,0x80,0x7F,0x00,0x00},/*"网",29*/
{0x20,0x30,0xAC,0x63,0x30,0x20,0x10,0x18,0xA7,0x44,0xA4,0x14,0x0C,0x00,0x00,0x00,0x22,0x67,0x22,0x12,0x12,0x04,0x02,0xFD,0x44,0x44,0x44,0x45,0xFD,0x02,0x02,0x00},/*"络",30*/
{0x00,0x80,0x60,0xF8,0x07,0x00,0x04,0x24,0x24,0x25,0x26,0x24,0x24,0x24,0x04,0x00,0x01,0x00,0x00,0xFF,0x00,0x00,0x00,0xF9,0x49,0x49,0x49,0x49,0x49,0xF9,0x00,0x00},/*"信",31*/
{0x00,0x00,0x00,0xFC,0x54,0x54,0x56,0x55,0x54,0x54,0x54,0xFC,0x00,0x00,0x00,0x00,0x40,0x30,0x00,0x03,0x39,0x41,0x41,0x45,0x59,0x41,0x41,0x73,0x00,0x08,0x30,0x00},/*"息",32*/	
{0x00,0x40,0x30,0x1E,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x00,0x81,0x81,0x41,0x21,0x11,0x0D,0x03,0x01,0x03,0x0D,0x11,0x21,0x41,0x81,0x81,0x00},/*"失",33*/
{0x00,0xFE,0x02,0xFA,0x02,0xFE,0x40,0x20,0xD8,0x17,0x10,0x10,0xF0,0x10,0x10,0x00,0x80,0x47,0x30,0x0F,0x10,0x67,0x80,0x40,0x21,0x16,0x08,0x16,0x21,0x40,0x80,0x00},/*"败",34*/
{0x00,0x80,0x60,0xF8,0x07,0x00,0x3E,0x22,0x22,0xE2,0x22,0x22,0x3E,0x00,0x00,0x00,0x01,0x00,0x00,0xFF,0x20,0x11,0x09,0x05,0x03,0xFF,0x03,0x05,0x09,0x11,0x20,0x00},/*"保",35*/
{0x04,0x04,0x84,0xE4,0x1C,0x07,0x24,0x24,0x24,0x24,0xA4,0x64,0x24,0x04,0x04,0x00,0x02,0x01,0x00,0xFF,0x00,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x00},/*"存",36*/
{0x40,0x40,0x42,0xCC,0x00,0x08,0x48,0x88,0x08,0x08,0x08,0xFF,0x08,0x08,0x08,0x00,0x00,0x40,0x20,0x1F,0x20,0x40,0x40,0x41,0x40,0x48,0x50,0x4F,0x40,0x40,0x40,0x00},/*"过",37*/
{0x04,0x04,0x04,0x04,0xF4,0x94,0x95,0x96,0x94,0x94,0xF4,0x04,0x04,0x04,0x04,0x00,0x00,0xFE,0x02,0x02,0x7A,0x4A,0x4A,0x4A,0x4A,0x4A,0x7A,0x02,0x82,0xFE,0x00,0x00},/*"高",38*/
{0x06,0x09,0x09,0xE6,0xF8,0x0C,0x04,0x02,0x02,0x02,0x02,0x02,0x04,0x1E,0x00,0x00,0x00,0x00,0x00,0x07,0x1F,0x30,0x20,0x40,0x40,0x40,0x40,0x40,0x20,0x10,0x00,0x00},/*"℃",39*/
{0x00,0x00,0x00,0xBE,0x2A,0x2A,0x2A,0xEA,0x2A,0x2A,0x2A,0x3E,0x00,0x00,0x00,0x00,0x00,0x44,0x42,0x49,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x49,0x41,0x40,0x00,0x00},/*"星",40*/
{0x00,0x04,0xFF,0x24,0x24,0x24,0xFF,0x04,0x00,0xFE,0x22,0x22,0x22,0xFE,0x00,0x00,0x88,0x48,0x2F,0x09,0x09,0x19,0xAF,0x48,0x30,0x0F,0x02,0x42,0x82,0x7F,0x00,0x00},/*"期",41*/
{0x00,0x00,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x00,0x00,0x00,0x00},/*"日",42*/
{0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"一",43*/
{0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00},/*"二",44*/
{0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x04,0x00,0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00},/*"三",45*/
{0x00,0xFC,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0xFC,0x00,0x00,0x00,0x7F,0x28,0x24,0x23,0x20,0x20,0x20,0x20,0x21,0x22,0x22,0x22,0x7F,0x00,0x00},/*"四",46*/
{0x00,0x02,0x42,0x42,0x42,0xC2,0x7E,0x42,0x42,0x42,0x42,0xC2,0x02,0x02,0x00,0x00,0x40,0x40,0x40,0x40,0x78,0x47,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x00},/*"五",47*/
{0x20,0x20,0x20,0x20,0x20,0x20,0x21,0x22,0x2C,0x20,0x20,0x20,0x20,0x20,0x20,0x00,0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x00,0x01,0x02,0x04,0x18,0x60,0x00,0x00},/*"六",48*/
{0x00,0x20,0x18,0xC7,0x44,0x44,0x44,0x44,0xFC,0x44,0x44,0x44,0x44,0x04,0x00,0x00,0x04,0x04,0x04,0x07,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x04,0x00},/*"年",49*/
{0x00,0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0xFE,0x00,0x00,0x00,0x80,0x40,0x30,0x0F,0x02,0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x00,0x00,0x00},/*"月",50*/
{0x00,0xF8,0x01,0x06,0x00,0xF0,0x12,0x12,0x12,0xF2,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x1F,0x11,0x11,0x11,0x1F,0x00,0x40,0x80,0x7F,0x00,0x00},/*"间",51*/
};

至于图片显示的函数。
由于没有现成的图片数组素材,也懒得去搞字模了,(本文章里的这些字模都是隔壁偷的,嘿嘿,)所以没有尝试,哈哈,反正原理差不多,大家可以自己动手改一改,如果前面都看明白了的话……
最后的效果大概是这样:在这里插入图片描述

while循环里的代码:

while (1)
  {
    /* USER CODE END WHILE */
		OLED_DisplayString(20,0,"Are you ok?");
		OLED_DisplayChinese(0,4,0);//温
		OLED_DisplayChinese(16,4,1);//湿
		OLED_DisplayChinese(32,4,2);//度
    /* USER CODE BEGIN 3 */
  }

注意啊,OLED的初始化我写在while循环外面了。

最后

再给你们看一下作者cubemax里面的引脚配置吧~
作者用的是C8T6,但是这个OLED的移植显然是可以在所有支持cubemax的32芯片上用的,不然还移植个屁啊,对吧。
在这里插入图片描述

需要用到的代码都在这里啦,仔细看完肯定就能过搞出来的。
当然,如果不想去理解那么多,也可以直接拿来就用,付个费就行,哈哈。
作者文章堆里还有一篇一模一样的,付费的文章,里面有完整工程哦~

最后

以上就是要减肥小土豆为你收集整理的cebemax hal库 stm32 OLED移植 解析cebemax hal库 stm32 OLED移植的全部内容,希望文章能够帮你解决cebemax hal库 stm32 OLED移植 解析cebemax hal库 stm32 OLED移植所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部