详解0.9寸OLED驱动开发(linux platform tree i2c 应用实例)

目录

概述

1 认识OLED

1.1 OLED简介

1.2 SSD1306介绍

1.3 0.9寸OLED模块介绍

1.4 i2c操作OLED时序

2 驱动代码实现

2.1 查看i2c总线下Device

2.2 OLED驱动接口

2.2.1 初始化函数

2.2.2 写指令函数

2.2.3 其他接口函数

2.3 完整驱动代码

3 编译

3.1 编写测试程序

3.2 Makefile

4 验证

4.1 编译代码

4.2 执行程序


源代码下载地址:0.9寸OLED驱动程序,基于linuxplatformtree下I2C接口资源-CSDN文库

概述

        本文详细介绍了SSD1306驱动型OLED的相关知识,并使用linux platform tree下的i2c驱动接口,实现该款OLED的驱动程序,并且编写了一个测试程序,验证其是否可靠。

1 认识OLED

1.1 OLED简介

     OLED(有机发光二极管)是一种显示技术,它使用有机物质来发出光线。与传统液晶显示屏相比,OLED具有更高的对比度和更广的视角。它没有背光源,因此可以提供更深的黑色和更明亮的白色。

       OLED显示屏由许多小的发光二极管组成,每个像素都可以独立发光。这意味着OLED显示屏可以实现真正的黑色,因为当像素关闭时,没有任何光线发射。

     OLED具有快速的响应时间,因此在显示动态图像时可以提供更流畅的画面。此外,OLED显示屏拥有更宽广的视角,因此无论从哪个角度观看,图像都能保持清晰和准确。

      OLED显示屏还具有较高的能源效率。因为每个像素都可以独立点亮,所以在显示黑色时可以关闭相应的像素,从而节省能源。

      OLED技术可应用于各种设备,包括智能手机、电视、电子书阅读器、车载显示屏等。由于OLED显示屏的薄度和柔性,它还可以用于可弯曲的显示设备和可穿戴设备。

       然而,OLED显示屏也有一些限制。首先,长时间显示相同的图像可能会导致“烧结”效应,即在屏幕上留下轮廓。其次,OLED显示屏的寿命相对较短,使用寿命通常较液晶显示屏更短。

      总的来说,OLED技术在显示领域具有许多优势,如高对比度、广视角和能源效率。随着技术的不断发展,OLED显示屏将在各种设备中得到更广泛的应用。

1.2 SSD1306介绍

      SSD1306是一款常用的单色OLED驱动芯片,由Solomon Systech Limited(国巨控股)设计和生产。它被广泛应用于各种嵌入式系统和电子设备中,用于驱动OLED显示屏。

      SSD1306采用低功耗、高对比度和快速刷新率的技术,使得显示效果清晰亮丽。它具备128x64或128x32像素的分辨率,并支持四种显示模式:正常显示、反转显示、镜像显示和指令显示。SSD1306还可以通过I2C或SPI接口与微控制器或其他外部设备进行通信。

      SSD1306内置了丰富的图形绘制和文本显示功能,可以轻松实现直线、矩形、圆形、位图等图形的绘制,以及字符、数字和自定义字体的显示。它还提供了多种显示模式和亮度调节选项,可以根据实际需求灵活控制显示效果。

      SSD1306还具备内置的电源管理功能,支持低电压检测和电池电量显示,可以实现智能电源管理。此外,它还支持多种硬件和软件配置选项,方便用户进行定制化开发。

      总的来说,SSD1306是一款功能强大、易于使用的OLED驱动芯片,适用于各种嵌入式系统和电子设备中,能够实现高质量、低功耗的显示效果。

1.3 0.9寸OLED模块介绍

          笔者使用的0.9寸OLED模块, 驱动芯片为SSD1306,该模块采用I2C驱动方式,对外有四个引脚:

1) GND: 电源地

2)VCC: 电源正极 ,工作电压区间为3~5.5V

3)SCL: I2C 时钟引脚

4) SDA: I2C数据引脚

模块的原理图如下:

1.4 i2c操作OLED时序

关于i2c的详细信号分析,请参看文章:linux platform架构下I2C接口驱动开发-CSDN博客

这里只介绍使用i2c总线操作oled应该注意的操作:

I2C写时序是指在I2C通信中进行写操作时的时间顺序。以下是一般的I2C写时序:

  1. 主设备发送起始条件:主设备发送一个起始条件(Start)信号,通知从设备开始通信。

  2. 主设备发送器件地址:主设备发送要写入的从设备的地址。这个地址是由从设备的唯一I2C地址和读写位组成。

  3. 从设备响应:从设备根据接收到的地址信息,发送一个ACK信号(应答)给主设备,表示从设备已经准备好接收数据。

  4. 主设备发送数据:主设备发送要写入从设备的数据。

  5. 从设备响应:从设备接收到数据后,发送一个ACK信号给主设备,表示已经成功接收到数据。

  6. 可选的重复写操作:如果主设备需要继续向从设备写入数据,可以选择重复上述步骤。

  7. 主设备发送停止条件:主设备发送一个停止条件(Stop)信号,通知从设备结束通信。

注意:在I2C通信中,每个数据字节都需要从设备发送一个ACK信号以表示接收成功,如果从设备发送一个NACK信号(非应答),则表示接收失败或从设备不支持写操作。

下图为I2C 写OLED参数时序图:

2 驱动代码实现

2.1 查看i2c总线下Device

在终端使用i2c-tools,查看总线下设备地址信息,对于I2C设备,总线上挂载设备地址必须是唯一的,否则导致控制时序混乱,从而操作芯片失败。

使用Linux 环境下的i2c-tools工具,非常方便查看总线下的设备地址,命令如下:

i2cdetect -a 1

执行命令后,终端会打印如下信息:

2.2 OLED驱动接口

2.2.1 初始化函数

1)第128行,open函数打开驱动接口(i2c)

2)第137行,初始化i2c的工作模式(slave),并且传递设备地址( 0x3c )

2.2.2 写指令函数

1) 参数介绍: data -- 传给ssd1306的数据

                       mode: 选择写命令还是写数据,mode = 1 为写数据, mode = 0, 此时写命令

2)第52行write函数为i2c 写接口,因为在linux platform tree框架下, 所有驱动程序的读和写分别被封装为: read/write。这里直接调用write,就可以实现写操作了。

2.2.3 其他接口函数

包括:

1) 清屏函数 oled_clear()

2) 设置字符大小函数

3)关闭/打开显示

4)写字符/字符串函数 

2.3 完整驱动代码

1)oled_dev.c

创建oled_dev.c文件,编写代码。完整代码如下

/***************************************************************
Copyright  2024-2029. All rights reserved.
文件名     : drv_oled.c
作者       : tangmingfei2013@126.com
版本       : V1.0
描述       : oled 驱动程序
其他       : 无
日志       : 初版V1.0 2024/02/23***************************************************************/
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/types.h>
#include <linux/i2c-dev.h>
#include <linux/i2c.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
#include <linux/fs.h>
#include <errno.h>
#include <assert.h>
#include <string.h>
#include <time.h>
#include "drv_oled.h"
#include "font.h"#define DEV_FILE               "/dev/i2c-1"#define grayoled_swap(a, b)                                                    \(((a) ^= (b)), ((b) ^= (a)), ((a) ^= (b))) ///< No-temp-var swap operationstatic int fd = -1;
static unsigned char charSize=0; static int oled_write_reg( unsigned char data, unsigned char mode)
{int              ret = -1;unsigned char    buf[2] = {0};if( mode ){buf[0] = 0x40;}else{buf[0] = 0;}buf[1] = data;ret = write(fd, buf, 2);if( ret < 0 ){printf("write cmd to oled register failure.\n");return -1;}return 0;
}static void oled_drv_Init(void)
{ oled_write_reg(0xAE,PARA);//--display offoled_write_reg(0x00,PARA);//---set low column addressoled_write_reg(0x10,PARA);//---set high column addressoled_write_reg(0x40,PARA);//--set start line address  oled_write_reg(0xB0,PARA);//--set page addressoled_write_reg(0x81,PARA); // contract controloled_write_reg(0xFF,PARA);//--128   oled_write_reg(0xA1,PARA);//set segment remap oled_write_reg(0xA6,PARA);//--normal / reverseoled_write_reg(0xA8,PARA);//--set multiplex ratio(1 to 64)oled_write_reg(0x3F,PARA);//--1/32 dutyoled_write_reg(0xC8,PARA);//Com scan directionoled_write_reg(0xD3,PARA);//-set display offsetoled_write_reg(0x00,PARA);//oled_write_reg(0xD5,PARA);//set osc divisionoled_write_reg(0x80,PARA);//oled_write_reg(0xD8,PARA);//set area color mode offoled_write_reg(0x05,PARA);//oled_write_reg(0xD9,PARA);//Set Pre-Charge Periodoled_write_reg(0xF1,PARA);//oled_write_reg(0xDA,PARA);//set com pin configuartionoled_write_reg(0x12,PARA);//oled_write_reg(0xDB,PARA);//set Vcomholed_write_reg(0x30,PARA);//oled_write_reg(0x8D,PARA);//set charge pump enableoled_write_reg(0x14,PARA);//oled_write_reg(0xAF,PARA);//--turn on oled paneloled_clear();
}void oled_clear(void)  
{  unsigned char i,n;for(i=0;i<8;i++)  {  oled_write_reg (0xb0+i,PARA);   oled_write_reg (0x00,PARA);oled_write_reg (0x10,PARA); for( n = 0;n < 128; n++){oled_write_reg(0,DATA);} } 
}void oled_release( void )
{close( fd );
}int oled_init(void)
{// init i2c fd = open(DEV_FILE, O_RDWR);if( fd < 0 ){close( fd );printf("%s %s i2c device open failure: %s\n", __FILE__, __FUNCTION__, strerror(errno));return -1;}ioctl(fd, I2C_TENBIT, 0);ioctl(fd, I2C_SLAVE, OLED_ADDR);oled_drv_Init();return fd;
}/*oled 12864 API 
*/void oled_setCharSize( unsigned char val )
{charSize = val;
}void oled_setPostion( unsigned char x, unsigned char y) 
{oled_write_reg(0xb0+y,PARA);oled_write_reg(((x&0xf0)>>4)|0x10,PARA);oled_write_reg((x&0x0f),PARA); 
}void oled_displayOn(void)
{oled_write_reg(0X8D,PARA); oled_write_reg(0X14,PARA); oled_write_reg(0XAF,PARA);
}void oled_displayOff(void)
{oled_write_reg(0X8D,PARA);oled_write_reg(0X10,PARA);oled_write_reg(0XAE,PARA);
}void oled_upScreenOn(void)  
{  unsigned char i,n;for(i=0;i<8;i++)  {  oled_write_reg (0xb0+i,PARA);oled_write_reg (0x00,PARA); oled_write_reg (0x10,PARA);for(n=0;n<128;n++){oled_write_reg(1,DATA); }} 
}void oled_printfChar(unsigned char x,unsigned char y,unsigned char val )
{ unsigned char character = 0;unsigned char i=0;character = val-' ';if( x > X_WIDTH-1){x = 0;y += 2;}if( charSize == FONT_16 ){oled_setPostion(x,y);	for( i = 0; i < 8; i++){oled_write_reg(F8X16[character*16+i],DATA);}oled_setPostion(x,y+1);for(i=0;i<8;i++){oled_write_reg(F8X16[character*16+i+8],DATA);}}else {oled_setPostion(x,y);for(i=0;i<6;i++){oled_write_reg(F6x8[character][i],DATA);}}
}void oled_printfString(unsigned char x,unsigned char y,unsigned char *str  )
{unsigned char index = 0;while ( str[index]!='\0' ){oled_printfChar(x,y,str[index] );x += 8;if( x > 120 ){  x=0;y+=2;}index++;}
}void oled_printmutiChar(unsigned char x,unsigned char y,unsigned char *str,  unsigned char length )
{unsigned char index = 0;for( index = 0; index < length; index++ ){oled_printfChar(x,y,str[index] );x += 8;if( x > 120 ){  x=0;y+=2;}}
}/* Eed of this file */

2)创建drv_oled.h,编写如下代码:

#ifndef __DRV__OLED_H
#define __DRV__OLED_H#ifdef __cplusplus
extern "C" {
#endif#define OLED_ADDR          0x3ctypedef enum
{FONT_16 = 0,FONT_12 = 1,
}OLED_CHARSIZE;typedef enum
{PARA = 0,DATA = 0x40,
}OLED_PARE_REG;typedef enum
{X_WIDTH = 128,Y_WIDTH = 64,
}OLED_SCREEN_SIZE;int oled_init(void);
void oled_release( void );void oled_clear(void);void oled_setCharSize( unsigned char val );
void oled_setPostion( unsigned char x, unsigned char y) ;
void oled_displayOn(void);
void oled_displayOff(void);void oled_printfChar(unsigned char x,unsigned char y,unsigned char val );
void oled_printfString(unsigned char x,unsigned char y,unsigned char *str );#ifdef __cplusplus
}
#endif#endif /* __DRV__OLED_H */

3)字库文件font.h

#ifdef __cplusplus
extern "C" {
#endifconst unsigned char F6x8[][6] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,// sp
0x00, 0x00, 0x00, 0x2f, 0x00, 0x00,// !
0x00, 0x00, 0x07, 0x00, 0x07, 0x00,// "
0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14,// #
0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12,// $
0x00, 0x62, 0x64, 0x08, 0x13, 0x23,// %
0x00, 0x36, 0x49, 0x55, 0x22, 0x50,// &
0x00, 0x00, 0x05, 0x03, 0x00, 0x00,// '
0x00, 0x00, 0x1c, 0x22, 0x41, 0x00,// (
0x00, 0x00, 0x41, 0x22, 0x1c, 0x00,// )
0x00, 0x14, 0x08, 0x3E, 0x08, 0x14,// *
0x00, 0x08, 0x08, 0x3E, 0x08, 0x08,// +
0x00, 0x00, 0x00, 0xA0, 0x60, 0x00,// ,
0x00, 0x08, 0x08, 0x08, 0x08, 0x08,// -
0x00, 0x00, 0x60, 0x60, 0x00, 0x00,// .
0x00, 0x20, 0x10, 0x08, 0x04, 0x02,// /
0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0
0x00, 0x00, 0x42, 0x7F, 0x40, 0x00,// 1
0x00, 0x42, 0x61, 0x51, 0x49, 0x46,// 2
0x00, 0x21, 0x41, 0x45, 0x4B, 0x31,// 3
0x00, 0x18, 0x14, 0x12, 0x7F, 0x10,// 4
0x00, 0x27, 0x45, 0x45, 0x45, 0x39,// 5
0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6
0x00, 0x01, 0x71, 0x09, 0x05, 0x03,// 7
0x00, 0x36, 0x49, 0x49, 0x49, 0x36,// 8
0x00, 0x06, 0x49, 0x49, 0x29, 0x1E,// 9
0x00, 0x00, 0x36, 0x36, 0x00, 0x00,// :
0x00, 0x00, 0x56, 0x36, 0x00, 0x00,// ;
0x00, 0x08, 0x14, 0x22, 0x41, 0x00,// <
0x00, 0x14, 0x14, 0x14, 0x14, 0x14,// =
0x00, 0x00, 0x41, 0x22, 0x14, 0x08,// >
0x00, 0x02, 0x01, 0x51, 0x09, 0x06,// ?
0x00, 0x32, 0x49, 0x59, 0x51, 0x3E,// @
0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C,// A
0x00, 0x7F, 0x49, 0x49, 0x49, 0x36,// B
0x00, 0x3E, 0x41, 0x41, 0x41, 0x22,// C
0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C,// D
0x00, 0x7F, 0x49, 0x49, 0x49, 0x41,// E
0x00, 0x7F, 0x09, 0x09, 0x09, 0x01,// F
0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A,// G
0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F,// H
0x00, 0x00, 0x41, 0x7F, 0x41, 0x00,// I
0x00, 0x20, 0x40, 0x41, 0x3F, 0x01,// J
0x00, 0x7F, 0x08, 0x14, 0x22, 0x41,// K
0x00, 0x7F, 0x40, 0x40, 0x40, 0x40,// L
0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F,// M
0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F,// N
0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E,// O
0x00, 0x7F, 0x09, 0x09, 0x09, 0x06,// P
0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q
0x00, 0x7F, 0x09, 0x19, 0x29, 0x46,// R
0x00, 0x46, 0x49, 0x49, 0x49, 0x31,// S
0x00, 0x01, 0x01, 0x7F, 0x01, 0x01,// T
0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F,// U
0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F,// V
0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F,// W
0x00, 0x63, 0x14, 0x08, 0x14, 0x63,// X
0x00, 0x07, 0x08, 0x70, 0x08, 0x07,// Y
0x00, 0x61, 0x51, 0x49, 0x45, 0x43,// Z
0x00, 0x00, 0x7F, 0x41, 0x41, 0x00,// [
0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55,// 55
0x00, 0x00, 0x41, 0x41, 0x7F, 0x00,// ]
0x00, 0x04, 0x02, 0x01, 0x02, 0x04,// ^
0x00, 0x40, 0x40, 0x40, 0x40, 0x40,// _
0x00, 0x00, 0x01, 0x02, 0x04, 0x00,// '
0x00, 0x20, 0x54, 0x54, 0x54, 0x78,// a
0x00, 0x7F, 0x48, 0x44, 0x44, 0x38,// b
0x00, 0x38, 0x44, 0x44, 0x44, 0x20,// c
0x00, 0x38, 0x44, 0x44, 0x48, 0x7F,// d
0x00, 0x38, 0x54, 0x54, 0x54, 0x18,// e
0x00, 0x08, 0x7E, 0x09, 0x01, 0x02,// f
0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C,// g
0x00, 0x7F, 0x08, 0x04, 0x04, 0x78,// h
0x00, 0x00, 0x44, 0x7D, 0x40, 0x00,// i
0x00, 0x40, 0x80, 0x84, 0x7D, 0x00,// j
0x00, 0x7F, 0x10, 0x28, 0x44, 0x00,// k
0x00, 0x00, 0x41, 0x7F, 0x40, 0x00,// l
0x00, 0x7C, 0x04, 0x18, 0x04, 0x78,// m
0x00, 0x7C, 0x08, 0x04, 0x04, 0x78,// n
0x00, 0x38, 0x44, 0x44, 0x44, 0x38,// o
0x00, 0xFC, 0x24, 0x24, 0x24, 0x18,// p
0x00, 0x18, 0x24, 0x24, 0x18, 0xFC,// q
0x00, 0x7C, 0x08, 0x04, 0x04, 0x08,// r
0x00, 0x48, 0x54, 0x54, 0x54, 0x20,// s
0x00, 0x04, 0x3F, 0x44, 0x40, 0x20,// t
0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C,// u
0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C,// v
0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C,// w
0x00, 0x44, 0x28, 0x10, 0x28, 0x44,// x
0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C,// y
0x00, 0x44, 0x64, 0x54, 0x4C, 0x44,// z
0x14, 0x14, 0x14, 0x14, 0x14, 0x14,// horiz lines
};/****************************************8*16************************************/
const unsigned char F8X16[]=  
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 00x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 10x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 20x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 30x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 40xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 50x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 60x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 70x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 80x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 90x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 100x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 110x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 120x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 130x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 140x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 150x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 160x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 170x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 180x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 190x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 200x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 210x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 220x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 230x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 240x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 250x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 260x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 270x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 280x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 290x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 300x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 310xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 320x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 330x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 340xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 350x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 360x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 370x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 380xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 390x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 400x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 410x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 420x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 430x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 440x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 450x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 460xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 470x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 480xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 490x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 500x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 510x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 520x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 530x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 540xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 550x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 560x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 570x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 580x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 590x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 600x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 610x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 620x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 630x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 640x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 650x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 660x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 670x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 680x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 690x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 700x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 710x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 720x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 730x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 740x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 750x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 760x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 770x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 780x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 790x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 800x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 810x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 820x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 830x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 840x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 850x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 860x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 870x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 880x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 890x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 900x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 910x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 920x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 930x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94
};/******************************************************************************
* END OF C++ DECLARATION WRAPPER
******************************************************************************/#ifdef __cplusplus
}
#endif#endif /* __FONT_H */  

3 编译

3.1 编写测试程序

编写一个测试程序,主要实现初始化OLED后,清空屏显,然后写不同的字符串,详细代码如下:

/***************************************************************
Copyright  2024-2029. All rights reserved.
文件名     : test_18_oled.c
作者       : tangmingfei2013@126.com
版本       : V1.0
描述       : 验证dev_oled.c 
其他       : 无
日志       : 初版V1.0 2024/02/23***************************************************************/
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/types.h>
#include <linux/i2c-dev.h>
#include <linux/i2c.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
#include <linux/fs.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <assert.h>
#include <string.h>
#include <time.h>
#include "drv_oled.h"void test_oled( void )
{oled_setCharSize( FONT_16 );  oled_printfString(6,0,(unsigned char *)"0.96' OLED TEST");  oled_setCharSize( FONT_12 );oled_printfString(0,6,(unsigned char*)"ASCII:");  oled_printfString(60,6,(unsigned char*)"-CODE:");
}int main(void)
{int set;set = oled_init();if( set < 0){printf("initial oled failure.\n");return -1;}test_oled();oled_release();return 0;
}

3.2 Makefile

创建Makefile文件,将其放在驱动程序和测试程序的同级目录下,详细代码如下:

CFLAGS= -Wall -O2
CC=/home/ctools/gcc-linaro-4.9.4-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
STRIP=/home/ctools/gcc-linaro-4.9.4-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-striptest_18_oled: test_18_oled.o drv_oled.o$(CC) $(CFLAGS) -o test_18_oled test_18_oled.o drv_oled.o$(STRIP) -s test_18_oledclean:rm -f test_18_oled test_18_oled.o drv_oled.o

4 验证

4.1 编译代码

 使用make命令编译程序,然后将生成的执行文件放在NFS共享目录下,方便在板卡中执行程序

4.2 执行程序

在板卡的mnt下的nfs共享目录中找到执行文件,然后运行

 运行代码后,在OLED屏幕上可以看见:

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/491429.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【算法训练营】:周测5

考题10-5 题目描述 平面固定有一些全等的圆角矩形&#xff0c;不同的圆角矩形具有不同的位置和倾斜角。这些圆角矩形都通过将以原本四个直角处距离两条直角边均为 r&#xfffd; 的位置为圆心&#xff0c;半径为 r&#xfffd; 且与两条直角边相切的四分之一圆弧以外的区域裁剪…

Ansible script 模块 该模块用于将本机的脚本在被管理端的机器上运行。Ansible服务执行本机脚本

目录 过程首先&#xff0c;我们写一个脚本&#xff0c;并给其加上执行权限直接运行命令来实现在被管理端执行该脚本验证错误演示 过程 该模块直接指定脚本的路径即可 首先&#xff0c;我们写一个脚本&#xff0c;并给其加上执行权限 vim /tmp/df.sh编辑脚本内容 这个脚本内容…

Linux安装Mysql设置自启动失败,bugFailed to execute operation: No such file or directory

bug: [rootlocalhost mysql-5.7]# systemctl enable mysql.service Failed to execute operation: No such file or directory 出现bug原因&#xff1a; ①CentOS7的服务systemctl脚本存放在&#xff1a;/usr/lib/systemd/&#xff0c;有系统&#xff08;system&#xff09;和…

2024022502-数据库绪论

数据库绪论 数据管理的三个阶段 人工管理阶段 文件系统阶段 数据库系统阶段 基本术语 数据&#xff08;Data&#xff09; 计算机用来描述事物的记录&#xff08;文字&#xff0e;图形&#xff0e;图像&#xff0e;声音&#xff09;数据的形式本身并不能完全表达其内容&am…

基础复习(IDA调试器)

1.选择IDA调试后端 在顶部有一个下拉菜单&#xff0c;选择调试器后端位置 很多用户实际上使用的是Windows版本的IDA&#xff0c;该IDA可以直接调试Windows下32bit和64bit的程序 2.本地调试启动方法 载入IDA后&#xff0c;程序实际上在对程序内置的一个字符串进行base64解码…

【项目部署上线】宝塔部署前端Docker部署后端

【项目部署上线】宝塔部署前端&Docker部署后端 文章目录 【项目部署上线】宝塔部署前端&Docker部署后端1.安装依赖1.1 安装mysql1.2 安装Canal1.3 安装redis1.4 安装rabbitmq1.5 安装nacos 2. 部署前端3. 部署后端 1.安装依赖 1.1 安装mysql docker run -d -p 3306:3…

Java面试——锁

​ 公平锁&#xff1a; 是指多个线程按照申请锁的顺序来获取锁&#xff0c;有点先来后到的意思。在并发环境中&#xff0c;每个线程在获取锁时会先查看此锁维护的队列&#xff0c;如果为空&#xff0c;或者当前线程是等待队列的第一个&#xff0c;就占有锁&#xff0c;否则就会…

深入理解指针2

各位小伙伴们&#xff0c;我们继续来学习指针&#xff0c;指针和结构体以及动态内存管理对后面的数据结构学习有非常大的帮助&#xff0c;所有我们一定要把这些知识点学会。OK,正式进入学习之旅吧 1.数组名的理解 在上⼀个章节我们在使⽤指针访问数组的内容时&#xff0c;有这…

【大数据】Flink SQL 语法篇(四):Group 聚合

Flink SQL 语法篇&#xff08;四&#xff09;&#xff1a;Group 聚合 1.基础概念2.窗口聚合和 Group 聚合3.SQL 语义4.Group 聚合支持 Grouping sets、Rollup、Cube 1.基础概念 Group 聚合定义&#xff08;支持 Batch / Streaming 任务&#xff09;&#xff1a;Flink 也支持 G…

SpringMVC 学习(四)之获取请求参数

目录 1 通过 HttpServletRequest 获取请求参数 2 通过控制器方法的形参获取请求参数 3 通过 POJO 获取请求参数&#xff08;重点&#xff09; 1 通过 HttpServletRequest 获取请求参数 public String handler1(HttpServletRequest request) <form action"${pageCont…

7.网络游戏逆向分析与漏洞攻防-游戏网络架构逆向分析-通过逆向分析确定游戏明文接收数据过程

内容参考于&#xff1a;易道云信息技术研究院VIP课 上一个内容&#xff1a;通过逆向分析确定游戏明文发送数据过程 上一个内容中得出它是使用的send函数发送的数据包&#xff0c;所以接收数据它指定用的是recv函数接收的数据 然后在跳转recv函数分析时发现跳转到了wsock32.d…

【嵌入式移植】7、U-Boot源码分析4—链接脚本分析

U-Boot源码分析4—链接脚本分析 1 u-boot-spl.lds1.1 链接脚本的生成1.2 u-boot-spl.lds内容分析1.3 text - 程序代码段1.4 sram其它段定义1.4.1 .rodata只读数据段1.4.2 .data数据段1.4.3 .u_boot_list段 1.5 BSS段1.6 /DISCARD/ 从上一篇文章【嵌入式移植】6、U-Boot源码分析…