基于STM32F103 0.96寸OLED液晶屏驱动(iic通讯)

注:
本文只是博主学习记录分享,仅供参考。如有错误肯定是博主理解有问题,谢谢!

一、概述

OLED驱动方式有8080、6800、3线/4线SPI以及IIC,能够显示字符、汉字的图片,无字库需通过取模软件获取显示内容数组。本次实验使用的是IIC通信协议,SSD1306驱动芯片的OLED屏。

二、实验材料

1、0.96寸OLED屏。
2、最小系统STM32F103C8T6.
3、杜邦线若干。

三、接线

功能引脚GPIO
GNDGND
VCCVCC
SCLPA6
SDAPA7

四、程序代码

1、GPIO初始化

void Oled_Init(void)
{
	IIC_Pin_Init();//iic引脚初始化
	
	OLED_Send_Command(0xAE);//--turn off oled panel
	OLED_Send_Command(0x02);//---SET low column address
	OLED_Send_Command(0x10);//---SET high column address
	OLED_Send_Command(0x40);//--SET start line address  SET Mapping RAM Display Start Line (0x00~0x3F)
	OLED_Send_Command(0x81);//--SET contrast control register
	OLED_Send_Command(0xCF); // SET SEG Output Current Brightness
	OLED_Send_Command(0xA1);//--SET SEG/Column Mapping     0xa0左右反置 0xa1正常
	OLED_Send_Command(0xC8);//SET COM/Row Scan Direction   0xc0上下反置 0xc8正常
	OLED_Send_Command(0xA6);//--SET normal display
	OLED_Send_Command(0xA8);//--SET multiplex ratio(1 to 64)
	OLED_Send_Command(0x3f);//--1/64 duty
	OLED_Send_Command(0xD3);//-SET display offSET	Shift Mapping RAM Counter (0x00~0x3F)
	OLED_Send_Command(0x00);//-not offSET
	OLED_Send_Command(0xd5);//--SET display clock divide ratio/oscillator frequency
	OLED_Send_Command(0x80);//--SET divide ratio, SET Clock as 100 Frames/Sec
	OLED_Send_Command(0xD9);//--SET pre-charge period
	OLED_Send_Command(0xF1);//SET Pre-Charge as 15 Clocks & Discharge as 1 Clock
	OLED_Send_Command(0xDA);//--SET com pins hardware configuration
	OLED_Send_Command(0x12);
	OLED_Send_Command(0xDB);//--SET vcomh
	OLED_Send_Command(0x40);//SET VCOM Deselect Level
	OLED_Send_Command(0x20);//-SET Page Addressing Mode (0x00/0x01/0x02)
	OLED_Send_Command(0x02);//
	OLED_Send_Command(0x8D);//--SET Charge Pump enable/disable
	OLED_Send_Command(0x14);//--SET(0x10) disable
	OLED_Send_Command(0xA4);// Disable Entire Display On (0xa4/0xa5)
	OLED_Send_Command(0xA6);// Disable Inverse Display On (0xa6/a7) 
	OLED_Send_Command(0xAF);//--turn on oled panel
	OLED_Send_Command(0xAF); /*display ON*/ 
	
	OLED_Clear(0x00); //清屏
}

2、写数据

void Oled_Write_Data(u8 data)
{
	IIC_Start();
	IIC_Send_Data(0x78);//地址
	IIC_Send_Data(0x40);//写数据
	IIC_Send_Data(data);//指令
	IIC_Stop();
}

3、写命令

void OLED_Send_Command(u8 com)
{
	IIC_Start();
	IIC_Send_Data(0x78);//地址
	IIC_Send_Data(0x00);//写指令 第6位控制写数据/命令
	IIC_Send_Data(com);//指令
	IIC_Stop();
}

4、清屏

void OLED_Clear(u8 clear_dat)
{ 
	u8 i = 0, j = 0;
	
	for(i = 0; i < 8; i++)
	{
		OLED_Send_Command(0xB0 + i);
		OLED_Send_Command(0X00);  //低列地址
		OLED_Send_Command(0X10);  //高列地址
		for(j = 0; j < 128; j++)
		{
			Oled_Write_Data(clear_dat);
		}
	}

}

5、显示位置

void Oled_Address(u8 row,u8 col)
{
	OLED_Send_Command(0xB0 + row);
	OLED_Send_Command(0X10 + ((col & 0xf0) >> 4));  //高列地址
	OLED_Send_Command(0X00 + (col & 0x0f)); 
}

6、显示字符

void Oled_Display_Char(u8 page,u8 col,char ch)
{
	u8 loca = ch - ' ';
	u8 i = 0;
	
	//页地址
	Oled_Address(page,col);
	for(i = 0; i < 8; i++)
	{
		Oled_Write_Data(Aciss_8X16[loca * 16 + i]);
	}
	Oled_Address(page + 1,col);
	for(i = 0; i < 8; i++)
	{
		Oled_Write_Data(Aciss_8X16[loca * 16 + 8 + i]);
	}
}

7、显示字符串

void Oled_Display_String(u8 page,u8 col,char *str)
{
	while(*str)
	{
		Oled_Display_Char(page,col,*str);
		col += 8;
		str++;
	}
}

8、显示汉字或图片

void Oled_Display_Pic(u8 wight,u8 high,u8 page,u8 col,u8 *str)
{
	u8 i = 0, j = 0;
	
	for(i = 0; i < high / 8; i++)
	{
		Oled_Address(page + i,col);
		for(j = 0; j < wight;j++)
		{
			Oled_Write_Data(str[wight * i + j]);
		}
	}
}

9、主函数

int main(void)
{
	char buf[] = {"There is no luck"};
	char buf1[] = {"There is only"};
	char buf2[] = {"word."};
	char author[] = {"Qing"};
	
	Sys_Delay_Init();
	Oled_Init();
//	Oled_Display_Char(0,0,'A');//显示单个字符
	
	//There is no luck.There is only work.幸运是不存在的,努力才是硬道理。
	Oled_Display_String(0,0,buf); //显示字符串
	Oled_Display_String(2,0,buf1); //显示字符串
	Oled_Display_String(4,0,buf2); //显示字符串
	Oled_Display_String(6,80,author);
	while(1)
	{
		
	}
}

五、实验效果

在这里插入图片描述

程序及相关资料
链接:https://pan.baidu.com/s/1Bo093SotTLxs1NgNwa01nQ
提取码:ygrv

如有错误还望指出,谢谢!

  • 27
    点赞
  • 133
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 24
    评论
0.96蓝色OLED模块 4P I2C接口软硬件设计资料(包括技术手册+硬件参考设计+C51STM32软件工程源码+取字模软件): OLED反白显示技术资料.rar SPI接口arduino连接方式.rar 中景园电子0.96OLED显示屏原理图 中景园电子0.96OLED显示屏数据手册 中景园电子0.96OLED显示屏测试程序 中景园电子0.96OLED使用文档新手必看V2.0.pdf 关于七针0.96OLED使用IIC接口的说明.rar 取字模软件 arduino_SPI_例程.rar arduino_SPI_例程.rar.zip 中景园电子0.96OLED显示屏_arduino_IIC_例程 中景园电子0.96OLED显示屏_arduino_IIC_例程.rar 中景园电子0.96OLED显示屏_C51系列_IIC_例程 中景园电子0.96OLED显示屏_C51系列_IIC_例程.rar 中景园电子0.96OLED显示屏_C51系列_IIC_例程推荐使用 中景园电子0.96OLED显示屏_C51系列_IIC_例程推荐使用.zip 中景园电子0.96OLED显示屏_C51系列_IIC应答_例程 中景园电子0.96OLED显示屏_C51系列_IIC应答_例程.rar 中景园电子0.96OLED显示屏_C51系列_IIC无应答_例程 中景园电子0.96OLED显示屏_C51系列_IIC无应答_例程.rar 中景园电子0.96OLED显示屏_C51系列_SPI_例程.rar 中景园电子0.96OLED显示屏_MSP430系列_SPI_例程.rar 中景园电子0.96OLED显示屏_PIC系列_SPI_例程.rar 中景园电子0.96OLED显示屏_STM32F103C8_IIC_V1.0.rar 中景园电子0.96OLED显示屏_STM32F103RC_IIC_V1.0.zip 中景园电子0.96OLED显示屏_STM32F103ZET6_IIC_V1.0.zip 中景园电子0.96OLED显示屏_STM32ZET系列_SPI_例程.zip 中景园电子0.96OLED显示屏_STM32_F103C8系列_SPI_例程 中景园电子0.96OLED显示屏_STM32_F103C8系列_SPI_例程.rar 中景园电子0.96OLED显示屏_STM32_F103RCT6系列_SPI_例程.zip 中景园电子0.96OLED显示屏_STM8S103K3T6_SPI_例程.zip 中景园电子0.96OLED显示屏_STM8系列_IIC_例程.zip 中景园电子0.96OLED显示屏_STM8系列_SPI_例程.rar

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 24
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员超庆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值