oled显示汉字字体 形状 使用

oled模块的工作原理

在这里插入图片描述
oled的上方四个接口是IIC总线 通过IIC总线可以进行数据的传输 在OLED模块背后有一个芯片叫做SSD1306 这个芯片内部有1024个字节的RAM 对应到右边的小屏幕上就有1024个字节 一个字节八个bit位 每一个bit位就对应着一个小点 我们只需要往oled的RAM上写入数据就可以显示对应的字符和图片

OLED驱动简介

在这里插入图片描述
在单片机内部开一块buffer 也是1024kb的对应着oled屏幕 相当于一块画布 然后可以调用pal库的接口对oled画线等图案

OLED初始化

在这里插入图片描述
在这里插入图片描述
初始化屏幕就是 oled屏幕内部有一个芯片 芯片有一个SA0引脚 如果接地就为0 如果接高电平就为1
SA0接地为0 从机地址为0111100 接高电平就为0111101 我们的oled芯片是接地的所以SA0传入的值为RESET (0)

#include "stm32f10x.h"
#include "stm32f10x_pal.h"
#include "stm32f10x_pal_i2c.h"
#include "stm32f10x_pal_oled.h"


static PalI2C_HandleTypeDef hi2c1;
static PalOled_HandleTypeDef holed;

int main(void)
{
   
	PAL_Init();
	//初始化iic
	hi2c1.Init.I2Cx = I2C1;
	hi2c1.Init.I2C_ClockSpeed = 400000;
	hi2c1.Init.I2C_DutyCycle = I2C_DutyCycle_2;
	PAL_I2C_Init(&hi2c1);
	
	//初始化oled屏幕
	holed.Init.hi2c = &hi2c1;
	holed.Init.SA0 = RESET;
	PAL_OLED_Init(&holed);
	
	
	
	
	
	while(1)
	{
   
	}
}

绘制基本形状

在这里插入图片描述
在X和Y的方向上移动光标 就是X和Y坐标同时变化
画笔和画刷
在这里插入图片描述
如要画123和一个苹果 就是先画一个矩形 画笔和画刷都设置为白色就得到一个蓝色背景的矩形
然后绘画数字123 就是用黑色的画笔 透明的画刷 (这样就不会挡住后面的背景色了) 绘画苹果也是设置黑色画笔 透明画刷
画点
在这里插入图片描述

#include "stm32f10x.h"
#include "stm32f10x_pal.h"
#include "stm32f10x_pal_i2c.h"
#include "stm32f10x_pal_oled.h"


static PalI2C_HandleTypeDef hi2c1;
static PalOled_HandleTypeDef holed;

int main(void)
{
   
	PAL_Init(); 
	//初始化iic
	hi2c1.Init.I2Cx = I2C1;
	hi2c1.Init.I2C_ClockSpeed = 400000;
	hi2c1.Init.I2C_DutyCycle = I2C_DutyCycle_2;
	PAL_I2C_Init(&hi2c1);
	
	//初始化oled屏幕
	holed.Init.hi2c = &hi2c1;
	holed.Init.SA0 = RESET;
	PAL_OLED_Init(&holed);
	
	
	PAL_OLED_Clear(&holed);
	PAL_OLED_SetPen(&holed,OLED_COLOR_WHITE,3);
	PAL_OLED_SetCursor(&holed,29,32);
	PAL_OLED_DrawDot(&holed);
	uint32_t i;
	
	for(i=1;i<8;i++)
	{
   
		PAL_OLED_MoveCursorX(&holed,10);
		PAL_OLED_DrawDot(&holed);
	}
	
	 PAL_OLED_SendBuffer(&holed);
	
	
	while(1)
	{
   
	}
}

画线
在这里插入图片描述

#include "stm32f10x.h"
#include "stm32f10x_pal.h"
#include "stm32f10x_pal_i2c.h"
#include "stm32f10x_pal_oled.h"


static PalI2C_HandleTypeDef hi2c1;
static PalOled_HandleTypeDef holed;

int main(void)
{
   
	PAL_Init(); 
	//初始化iic
	hi2c1.Init.I2Cx = I2C1;
	hi2c1.Init.I2C_ClockSpeed = 400000;
	hi2c1.Init.I2C_DutyCycle = I2C_DutyCycle_2;
	PAL_I2C_Init(&hi2c1);
	
	//初始化oled屏幕
	holed.Init.hi2c = &hi2c1;
	holed.Init.SA0 = RESET;
	PAL_OLED_Init(&holed);
	
	
//	PAL_OLED_Clear(&holed);
//	PAL_OLED_SetPen(&holed,OLED_COLOR_WHITE,3);
//	PAL_OLED_SetCursor(&holed,29,32);
//	PAL_OLED_DrawDot(&holed);
//	uint32_t i;
//	
//	for(i=1;i<8;i++)
//	{
   
//		PAL_OLED_MoveCursorX(&holed,10);
//		PAL_OLED_DrawDot(&holed);
//	}
//	
//	 PAL_OLED_SendBuffer(&holed);

		PAL_OLED_Clear(&holed);
		
		PAL_OLED_SetCursor(&holed,17,20);
		
		PAL_OLED_SetPen(&holed,OLED_COLOR_WHITE,1);
		PAL_OLED_DrawLine(&holed,PAL_OLED_GetCursorX(&holed) + 45,PAL_OLED_GetCursorY(&holed));
		
		PAL_OLED_MoveCursorY(&holed,8);
		PAL_OLED_SetPen(&holed,OLED_COLOR_WHITE,2);
		PAL_OLED_DrawLine(&holed,PAL_OLED_GetCursorX(&holed) + 45,PAL_OLED_GetCursorY(&holed));
		
		PAL_OLED_MoveCursorY(&holed,8);
		PAL_OLED_SetPen(&holed,OLED_COLOR_WHITE,3);
		PAL_OLED_DrawLine(&holed,PAL_OLED_GetCursorX(&holed) + 45,PAL_OLED_GetCursorY(&holed));
		
		PAL_OLED_MoveCursorY(&holed,8);
		PAL_OLED_SetPen(&holed,OLED_COLOR_WHITE,4);
		PAL_OLED_DrawLine(&holed,PAL_OLED_GetCursorX(&holed) + 45,PAL_OLED_GetCursorY(&holed));
		
		PAL_OLED_SendBuffer(&holed);
	while(1)
	{
   
	}
}
#include "stm32f10x.h"
#include "stm32f10x_pal.h"
#include "stm32f10x_pal_i2c.h"
#include "stm32f10x_pal_oled.h"


static PalI2C_HandleTypeDef hi2c1;
static PalOled_HandleTypeDef holed;

int main(void)
{
   
	PAL_Init(); 
	//初始化iic
	hi2c1.Init.I2Cx = I2C1;
	hi2c1.Init.I2C_ClockSpeed = 400000;
	hi2c1.Init.I2C_DutyCycle = I2C_DutyCycle_2;
	PAL_I2C_Init(&hi2c1);
	
	//初始化oled屏幕
	holed.Init.hi2c = &hi2c1;
	holed.Init.SA0 = RESET;
	PAL_OLED_Init(&holed);
	
	
//	PAL_OLED_Clear(&holed);
//	PAL_OLED_SetPen(&holed,OLED_COLOR_WHITE,3);
//	PAL_OLED_SetCursor(&holed,29,32);
//	PAL_OLED_DrawDot(&holed);
//	uint32_t i;
//	
//	for(i=1;i<8;i++)
//	{
   
//		PAL_OLED_MoveCursorX(&holed,10);
//		PAL_OLED_DrawDot(&holed);
//	}
//	
//	 PAL_OLED_SendBuffer(&holed);

		PAL_OLED_Clear(&holed);
		
		PAL_OLED_SetCursor(&holed,17,20);
		
		PAL_OLED_SetPen(&holed,OLED_COLOR_WHITE,1);
		PAL_OLED_DrawLine(&holed,PAL_OLED_GetCursorX(&holed) + 45,PAL_OLED_GetCursorY(&holed));
		
		PAL_OLED_MoveCursorY(&holed,8);
		PAL_OLED_SetPen(&holed,OLED_COLOR_WHITE,2);
		PAL_OLED_DrawLine(&holed,PAL_OLED_GetCursorX(&holed) + 45,PAL_OLED_GetCursorY(&holed));
		
		PAL_OLED_MoveCursorY(&holed,8);
		PAL_OLED_SetPen(&holed,OLED_COLOR_WHITE,3);
		PAL_OLED_DrawLine(&holed,PAL_OLED_GetCursorX(&holed
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值