欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

最全OLED驱动集合,IIC、三线SPI、四线SPI、8080驱动OLED

程序员文章站 2022-06-15 22:37:56
## 阅读须知阅读本文需要有一定的STM32基础。## 前言我经常用的是IIC驱动,因为只有2个IO口,使用也方便。前段时间拿到SPI接口的OLED,于是就去捣鼓了三线SPI驱动。本驱动适用SSD1306,其他芯片的鄙人没有测试,仅供参考。SSD1306手册:https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf代码中的宏定义对应接线: OledCS :CS--->PB12 OledRS :DC-......

 

## 阅读须知

阅读本文需要有一定的STM32基础。

## 前言

我经常用的是IIC驱动,因为只有2个IO口,使用也方便。

前段时间拿到SPI接口的OLED,于是就去捣鼓了三线SPI驱动。

本驱动适用SSD1306,其他芯片的鄙人没有测试,仅供参考。

SSD1306手册:https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf

代码中的宏定义对应接线:

    OledCS  :CS--->PB12
    OledRS  :DC--->PB14
    OledRst  :RES-->PB13,可以直接接单片机RST引脚
    OledSck :D0--->PB0
    OledSdin:D1--->PB1

 

//OLED模式设置
//0: SPI串行模式  (模块的BS1,BS2均接GND)
//1: 并行8080模式 (模块的BS1,BS2均接VCC)
#define  OLED_MODE             0
//SPI模式设置
//0: 4线串行模式 8 bit data send
//1: 3线串行模式 9 bit data send
#define  OLED_SPI_X         0

## 驱动原理

不管是IIC还是三线SPI、四线SPI,乃至8080并口驱动OLED,他们的本质都是一样的:写数据和写命令。也就是说当你已经有一份可以驱动的代码,你就可以很快的修改成其他接口协议来驱动OLED。

如果是7针的OLED,接线和改电阻参考(也可以直接看元器件的丝印):

https://wenku.baidu.com/view/42efcb877cd184254a353584.html

### IIC驱动OLED

没有什么好说的,直接上源码。

最后得出2个函数,写命令和写数据函数,然后拿着这2个函数去写OLED操作。如显示数字、字符、字符串、中文,

void WriteCmd(u8 command);
void WriteDat(u8 data);

只要其他接口实现这2个函数的功能,那么就可以在IIC接口的驱动延伸出其它接口的OLED驱动。开始,写底层驱动~~~。

为了不影响阅读,OLED显示代码我放在最后。

#define  OledSCL_H()        I2CSCLPort->BSRR = I2CSCLPin  
#define  OledSCL_L()        I2CSCLPort->BRR  = I2CSCLPin  
#define  OledSDA_H()        I2CSDAPort->BSRR = I2CSDAPin  
#define  OledSDA_L()        I2CSDAPort->BRR  = I2CSDAPin 

#define  OledSDA_Read       I2CSDAPort->IDR  & I2CSDAPin  

/**
**  设置SDA为输出
**/
void SDA_OUT(void)
{
    GPIO_InitTypeDef GPIO_InitStructer;
    GPIO_InitStructer.GPIO_Pin= I2CSDAPin;
    GPIO_InitStructer.GPIO_Speed=GPIO_Speed_50MHz;
    GPIO_InitStructer.GPIO_Mode=GPIO_Mode_Out_PP;
    GPIO_Init(I2CSDAPort, &GPIO_InitStructer);
}


/**
**  设置SDA为输入
**/
void SDA_IN(void)
{
    GPIO_InitTypeDef GPIO_InitStructer;
    GPIO_InitStructer.GPIO_Pin= I2CSDAPin;
    GPIO_InitStructer.GPIO_Speed=GPIO_Speed_50MHz;
    GPIO_InitStructer.GPIO_Mode=GPIO_Mode_IPU;
    GPIO_Init(I2CSDAPort, &GPIO_InitStructer);
}

//开始信号
void IIC_Start(void)
{
    SDA_OUT();
    OledSDA_H();
    OledSCL_H();
    delay_us(2);
    OledSDA_L();
    delay_us(2);
    OledSCL_L();
    delay_us(2);
}

void IIC_Stop(void)
{
    OledSCL_H();
    OledSDA_L();
    delay_us(2);
    OledSDA_H();
    delay_us(2);
}


/*
*   返回1--应答出错
*   放回0--应答正确
*/
u8 IIC_Wait_Ask(void)
{
    int count=0;
    SDA_IN();
    OledSCL_H();
    delay_us(2);
    while(OledSDA_Read)
    {
        count++;
        if(count>250)
        {
            IIC_Stop();
            return 1;
        }   
    }
    OledSCL_L();
    delay_us(2);
    return 0;
}

//写一个字节
void IIC_WriteByte(u8 data)
{
    u8 i;
    SDA_OUT();
    for(i=0;i<8;i++)
    {
        OledSCL_L();
        delay_us(2);
        if(data & 0x80)     //MSB,从高位开始一位一位传输
            OledSDA_H();
        else
            OledSDA_L();
        OledSCL_H();
        delay_us(2);
        OledSCL_L();
        data<<=1;

    }
}

u8 IIC_ReadByte(void)
{
    u8 data,i;
    OledSDA_H();
    delay_us(3);
    for(i=0;i<8;i++)
    {
        data<<=1;
        OledSCL_L();
        delay_us(1);
        OledSCL_H();
        delay_us(1);
        if(GPIO_ReadInputDataBit(I2CSDAPort, I2CSDAPin))
            data=data | 0x01;
        else 
            data=data & 0xFE;

    }
    OledSCL_L();
    delay_us(3);
    return data;

}

void WriteCmd(u8 command)
{
    IIC_Start();
    IIC_WriteByte(0x78);//OLED地址
    IIC_Wait_Ask();
    IIC_WriteByte(0x00);//寄存器地址
    IIC_Wait_Ask();
    IIC_WriteByte(command);
    IIC_Wait_Ask();
    IIC_Stop();
}


void WriteDat(u8 data)
{
    IIC_Start();
    IIC_WriteByte(0x78);//OLED地址
    IIC_Wait_Ask();
    IIC_WriteByte(0x40);//寄存器地址
    IIC_Wait_Ask();
    IIC_WriteByte(data);
    IIC_Wait_Ask();
    IIC_Stop();
}

### 四线SPI驱动OLED

四线SPI使用CS、D0、D1、DC。分别对应SPI的CS、Sck、Sdin、命令数据选择。

注:RES是要使用的。

官方说明:

最全OLED驱动集合,IIC、三线SPI、四线SPI、8080驱动OLED

第一段是说使用到什么线的,每一个IO的功能。

第二段是告诉你怎么编程的。

### 对应的编程,这里只考虑写,不考虑读取。以下为写8bit。

void OLED_WR_Byte(u8 dat,u8 cmd)
{
    char i;
    OledCs_L();//片选
    if(cmd)    //判断是写数据还是写命令
        OledRS_H();
    else
        OledRS_L();
    for(i=0;i<8;i++)//8bit
    {			  
        OledSck_L();
        if(dat&0x80)
            OledSdin_H();
        else 
            OledSdin_L();
        OledSck_H();
        dat<<=1;   
    }    
    OledCs_H();
    OledRS_H();
     
}

### 三线SPI驱动OLED

三线SPI使用CS、D0、D1。分别对应SPI的CS、Sck、Sdin。

注:RES是要使用的。

官方的说明:

最全OLED驱动集合,IIC、三线SPI、四线SPI、8080驱动OLED

第一段是说使用到什么线的,每一个IO的功能。

第二段是告诉你怎么编程的。这里说一下三线SPI的原理:其实就是一次发9bit数据,把命令/数据使用Sdin线的1bit,(1:写数据,0:写命令)而在四线SPI中,根据D/C线的电平判断写命令还是写数据。

### 对应的编程,这里只考虑写,不考虑读取。

那么我们就再四线SPI的基础上加上几行(配合宏定义):

void OLED_WR_Byte(u8 dat,u8 cmd)
{
    char i;
    OledCs_L();    //片选
#if OLED_SPI_X == 1//如果定义了三线SPI
    OledSck_L();
    if(cmd)        //判断是写数据还是写命令
        OledSdin_H();
    else 
        OledSdin_L();
    OledSck_H();
#else               //四线SPI
    if(cmd)        //判断是写数据还是写命令
        OledRS_H();
    else
        OledRS_L();
#endif
    for(i=0;i<8;i++)//8bit
    {			  
        OledSck_L();
        if(dat&0x80)
            OledSdin_H();
        else 
            OledSdin_L();
        OledSck_H();
        dat<<=1;   
    }    
    OledCs_H();
#if OLED_SPI_X == 0//四线SPI
    OledRS_H();
#endif
     
}

### 8080并口驱动OLED

并口比较简单,和以前使用的LCD12864差不多,鄙人没有条件测试。不做任何保证,仅供参考。

void OLED_WR_Byte(u8 dat,u8 cmd)
{
    DATAOUT(dat);    //先输出数据
    if(cmd)          //判断是写数据还是写命令
        OledRS_H();
    else
        OledRS_L();
    OledCs_L();	   
    OledWR_L(); 
    OledWR_H();    
    OledCs_H();	  
    OledRS_H();	 
} 

### 写数据和写命令函数

上面的所有驱动,都要实现OLED_WR_Byte函数的功能,然后使用OLED_WR_Byte封装出写命令和写数据的函数和IIC驱动一致。这样就可以使用原本IIC驱动的操作函数。封装如下:

void WriteCmd(u8 command)
{
    OLED_WR_Byte(command,OLED_CMD);
}
void WriteDat(u8 data)
{
    OLED_WR_Byte(data,OLED_DATA);
}

## 效果

最全OLED驱动集合,IIC、三线SPI、四线SPI、8080驱动OLED

最全OLED驱动集合,IIC、三线SPI、四线SPI、8080驱动OLED

最全OLED驱动集合,IIC、三线SPI、四线SPI、8080驱动OLED

## 代码

### 完整的项目工程

可以查看鄙人上传的资源,点击进去传送门

### 部分摘要

config.h文件:

#ifndef _config_H
#define _config_H
#include "stm32f10x.h"
#include "stm32f10x_it.h"

#define SYS_CLOCK_FREQ_HZ   72000000
//#define OLEDIIC
/********************************
	定义
	OledCS  :CS--->PB12
	OledRS  : DC--->PB14
	OledRst :RES-->PB13,可以直接接单片机RST引脚
	OledSck : D0--->PB0
	OledSdin: D1--->PB1
	

******************************************/
#ifdef  OLEDIIC  
#define  I2CSCLPort         GPIOC
#define  I2CSDAPort         GPIOC
#define  I2CSCLPin          GPIO_Pin_14
#define  I2CSDAPin          GPIO_Pin_15
#else

//OLED模式设置
//0: SPI串行模式  (模块的BS1,BS2均接GND)
//1: 并行8080模式 (模块的BS1,BS2均接VCC)
#define  OLED_MODE 	        0
//SPI模式设置
//0: 4线串行模式 8 bit data send
//1: 3线串行模式 9 bit data send
#define  OLED_SPI_X         1

#define  OledCsPort         GPIOB
#define  OledCsPin          GPIO_Pin_12

#define  OledRstPort        GPIOB
#define  OledRstPin         GPIO_Pin_13

#define  OledRSPort         GPIOB
#define  OledRSPin          GPIO_Pin_14

#define  OledCs_H()         OledCsPort->BSRR = OledCsPin
#define  OledCs_L()         OledCsPort->BRR  = OledCsPin  

#define  OledRst_H()        OledRstPort->BSRR = OledRstPin
#define  OledRst_L()        OledRstPort->BRR  = OledRstPin  

#if OLED_MODE ==1
#define  OledWRPort         GPIOB
#define  OledWRPin          GPIO_Pin_15

#define  OledRDPort         GPIOB
#define  OledRDPin          GPIO_Pin_11

#define  OledWR_H()         OledWRPort->BSRR = OledWRPin
#define  OledWR_L()         OledWRPort->BRR  = OledWRPin

#define  OledRD_H()         OledRDPort->BSRR = OledRDPin
#define  OledRD_L()         OledRDPort->BRR  = OledRDPin

#define  DATAOUT(x)         GPIO_Write(GPIOA,x);//输出  //PA0~7,作为数据线

#else
#define  OledSckPort        GPIOB
#define  OledSckPin         GPIO_Pin_0

#define  OledSdinPort       GPIOB
#define  OledSdinPin        GPIO_Pin_1

#define  OledSck_H()        OledSckPort->BSRR = OledSckPin
#define  OledSck_L()        OledSckPort->BRR  = OledSckPin

#define  OledSdin_H()       OledSdinPort->BSRR = OledSdinPin
#define  OledSdin_L()       OledSdinPort->BRR  = OledSdinPin
#endif

#define  OledRS_H()         OledRSPort->BSRR = OledRSPin
#define  OledRS_L()         OledRSPort->BRR  = OledRSPin

#endif

#define  LedPort            GPIOC
#define  LedPIN             GPIO_Pin_13

#define  LedState(State)    State?GPIO_SetBits(LedPort,LedPIN):GPIO_ResetBits(LedPort,LedPIN);
#define  LedXor(PIN)        LedPort->ODR ^= PIN

#define  OLED_ADDRESS       0x78    //IIC模式下的地址,需要结合硬件
#define  OLED_CMD           0x00	//写命令
#define  OLED_DATA          0x01	//写数据

void RCC_Configuration(void);
void delay_ms(u16 time);
void delay_us(u16 time);

void OLED_ON(void);
void OLED_CLS(void);
void OLED_OFF(void);
void OLED_Init(void);
void WriteDat(u8 I2C_Data);
void OLED_SetPos(u8 x, u8 y);
void OLED_Fill(u8 fill_Data);
void I2C_Configuration(void);
void WriteCmd(u8 I2C_Command);
void OLED_ShowCN(u8 x, u8 y, u8 N);
void OLED_ShowCHinese(u8 x,u8 y,u8 no);
void I2C_WriteByte(uint8_t addr,uint8_t data);
void OLED_ShowStr(u8 x, u8 y, u8 ch[], u8 TextSize);
void OLED_DrawBMP(u8 x0,u8 y0,u8 x1,u8 y1,u8 BMP[]);
void OLED_ShowString(u8 x,u8 y,char *chr,u8 Char_Size);

#endif


OLED.c

#include "config.h" 
#include "codetab.h"
//OLED的显存
//存放格式如下.
//[0]0 1 2 3 ... 127	
//[1]0 1 2 3 ... 127	
//[2]0 1 2 3 ... 127	
//[3]0 1 2 3 ... 127	
//[4]0 1 2 3 ... 127	
//[5]0 1 2 3 ... 127	
//[6]0 1 2 3 ... 127	
//[7]0 1 2 3 ... 127 
#ifdef OLEDIIC 

#define  OledSCL_H()        I2CSCLPort->BSRR = I2CSCLPin  
#define  OledSCL_L()        I2CSCLPort->BRR  = I2CSCLPin  
#define  OledSDA_H()        I2CSDAPort->BSRR = I2CSDAPin  
#define  OledSDA_L()        I2CSDAPort->BRR  = I2CSDAPin 

#define  OledSDA_Read       I2CSDAPort->IDR  & I2CSDAPin  

/**
**  设置SDA为输出
**/
void SDA_OUT(void)
{
    GPIO_InitTypeDef GPIO_InitStructer;
    GPIO_InitStructer.GPIO_Pin= I2CSDAPin;
    GPIO_InitStructer.GPIO_Speed=GPIO_Speed_50MHz;
    GPIO_InitStructer.GPIO_Mode=GPIO_Mode_Out_PP;
    GPIO_Init(I2CSDAPort, &GPIO_InitStructer);
}


/**
**  设置SDA为输入
**/
void SDA_IN(void)
{
    GPIO_InitTypeDef GPIO_InitStructer;
    GPIO_InitStructer.GPIO_Pin= I2CSDAPin;
    GPIO_InitStructer.GPIO_Speed=GPIO_Speed_50MHz;
    GPIO_InitStructer.GPIO_Mode=GPIO_Mode_IPU;
    GPIO_Init(I2CSDAPort, &GPIO_InitStructer);
}

//开始信号
void IIC_Start(void)
{
    SDA_OUT();
    OledSDA_H();
    OledSCL_H();
    delay_us(2);
    OledSDA_L();
    delay_us(2);
    OledSCL_L();
    delay_us(2);
}

void IIC_Stop(void)
{
    OledSCL_H();
    OledSDA_L();
    delay_us(2);
    OledSDA_H();
    delay_us(2);
}


/*
*   返回1--应答出错
*   放回0--应答正确
*/
u8 IIC_Wait_Ask(void)
{
    int count=0;
    SDA_IN();
    OledSCL_H();
    delay_us(2);
    while(OledSDA_Read)
    {
        count++;
        if(count>250)
        {
            IIC_Stop();
            return 1;
        }   
    }
    OledSCL_L();
    delay_us(2);
    return 0;
}

//写一个字节
void IIC_WriteByte(u8 data)
{
    u8 i;
    SDA_OUT();
    for(i=0;i<8;i++)
    {
        OledSCL_L();
        delay_us(2);
        if(data & 0x80)     //MSB,从高位开始一位一位传输
            OledSDA_H();
        else
            OledSDA_L();
        OledSCL_H();
        delay_us(2);
        OledSCL_L();
        data<<=1;

    }
}

u8 IIC_ReadByte(void)
{
    u8 data,i;
    OledSDA_H();
    delay_us(3);
    for(i=0;i<8;i++)
    {
        data<<=1;
        OledSCL_L();
        delay_us(1);
        OledSCL_H();
        delay_us(1);
        if(GPIO_ReadInputDataBit(I2CSDAPort, I2CSDAPin))
            data=data | 0x01;
        else 
            data=data & 0xFE;

    }
    OledSCL_L();
    delay_us(3);
    return data;

}
 
void WriteCmd(u8 command)
{
    IIC_Start();
    IIC_WriteByte(0x78);//OLED地址
    IIC_Wait_Ask();
    IIC_WriteByte(0x00);//寄存器地址
    IIC_Wait_Ask();
    IIC_WriteByte(command);
    IIC_Wait_Ask();
    IIC_Stop();
}

void WriteDat(u8 data)
{
    IIC_Start();
    IIC_WriteByte(0x78);//OLED地址
    IIC_Wait_Ask();
    IIC_WriteByte(0x40);//寄存器地址
    IIC_Wait_Ask();
    IIC_WriteByte(data);
    IIC_Wait_Ask();
    IIC_Stop();
}

#else
#if OLED_MODE==1	//8080并口 
/*****************************************************************
    向SSD1306写入一个字节
    dat:要写入的数据/命令
    cmd:数据/命令标志 0,表示命令;1,表示数据
*****************************************************************/
void OLED_WR_Byte(u8 dat,u8 cmd)
{
	DATAOUT(dat);	    
    if(cmd)
        OledRS_H();
    else
        OledRS_L();
	OledCs_L();	   
	OledWR_L(); 
    OledWR_H();    
	OledCs_H();	  
	OledRS_H();	 
} 	    	    
#else
void OLED_WR_Byte(u8 dat,u8 cmd)
{
    char i;
    OledCs_L();
#if OLED_SPI_X == 1
    OledSck_L();
    if(cmd)OledSdin_H();
    else OledSdin_L();
    OledSck_H();
#else
    if(cmd)
        OledRS_H();
    else
        OledRS_L();
#endif
	for(i=0;i<8;i++)
	{			  
		OledSck_L();
		if(dat&0x80)OledSdin_H();
		else OledSdin_L();
		OledSck_H();
		dat<<=1;   
	}    
    OledCs_H();
#if OLED_SPI_X == 0
    OledRS_H();
#endif
     
}
#endif
void WriteCmd(u8 command)
{
	OLED_WR_Byte(command,OLED_CMD);
}
void WriteDat(u8 data)
{
	OLED_WR_Byte(data,OLED_DATA);
}
#endif

// 公共部分

/*****************************************************************
    将OLED从休眠中唤醒
*****************************************************************/
void OLED_ON(void)
{
    WriteCmd(0X8D);  //设置电荷泵
    WriteCmd(0X14);  //开启电荷泵
    WriteCmd(0XAF);  //OLED唤醒
}

/*****************************************************************
  设置光标
  x,光标x位置 0-127
  y,光标y位置 0-7
*****************************************************************/
void OLED_SetPos(u8 x, u8 y)
{ 
    WriteCmd(0xb0+y);
    WriteCmd(((x&0xf0)>>4)|0x10);
    WriteCmd((x&0x0f)|0x01);
}

/*****************************************************************
  填充整个屏幕
  fill_Data:要填充的数据
*****************************************************************/
void OLED_Fill(u8 fill_Data)
{
    u8 m,n;
    for(m=0;m<8;m++)
    {
        WriteCmd(0xb0+m);       //page0-page1
        WriteCmd(0x00);     //low column start address
        WriteCmd(0x10);     //high column start address
        for(n=0;n<128;n++)
        {
            WriteDat(fill_Data);
        }
    }
}

void OLED_CLS(void)//清屏
{
	u8 i,n;		    
	for(i=0;i<8;i++)  
	{  
		WriteCmd (0xb0+i);
		WriteCmd (0x00);
		WriteCmd (0x10);   
		for(n=0;n<128;n++)
        WriteDat(0); 
	}
}

/*****************************************************************
  显示codetab.h中的ASCII字符,有6*8和8*16可选择
  x,y : 起始点坐标(x:0~127, y:0~7);
                     ch[] :- 要显示的字符串; 
                     TextSize : 字符大小(1:6*8 ; 2:8*16)
*****************************************************************/
void OLED_ShowStr(u8 x, u8 y, u8 ch[], u8 TextSize)
{
    u8 c = 0,i = 0,j = 0;
    switch(TextSize)
    {
        case 1:
        {
            while(ch[j] != '\0')
            {
                c = ch[j] - 32;
                if(x > 126)
                {
                    x = 0;
                    y++;
                }
                OLED_SetPos(x,y);
                for(i=0;i<6;i++)
                    WriteDat(F6x8[c][i]);
                x += 6;
                j++;
            }
        }break;
        case 2:
        {
            while(ch[j] != '\0')
            {
                c = ch[j] - 32;
                if(x > 120)
                {
                    x = 0;
                    y++;
                }
                OLED_SetPos(x,y);
                for(i=0;i<8;i++)
                    WriteDat(F8X16[c*16+i]);
                OLED_SetPos(x,y+1);
                for(i=0;i<8;i++)
                    WriteDat(F8X16[c*16+i+8]);
                x += 8;
                j++;
            }
        }break;
    }
}

void OLED_ShowChar(u8 x,u8 y,char chr,u8 Char_Size)
{      	
	u8 c=0,i=0;	
	c=chr-' ';		
	if(x>128-1){x=0;y=y+2;}
	if(Char_Size ==16)
	{
		OLED_SetPos(x,y);	
		for(i=0;i<8;i++)
		WriteDat(F8X16[c*16+i]);
		OLED_SetPos(x,y+1);
		for(i=0;i<8;i++)
		WriteDat(F8X16[c*16+i+8]);
	}
	else 
	{	
		OLED_SetPos(x,y);
		for(i=0;i<6;i++)
		{
			WriteDat(F6x8[c][i]);
		}
	}
}
/*****************************************************************
    显示字符串
    示例:OLED_ShowString(0,0,"4Wire SPI Runing",16);
*****************************************************************/
void OLED_ShowString(u8 x,u8 y,char *chr,u8 Char_Size)
{
	u8 j=0;
	while (chr[j]!='\0')
	{
		OLED_ShowChar(x,y,chr[j],Char_Size);
		x+=8;
		if(x>120){x=0;y+=2;}
		{
			j++;
		}
	}
}
/*****************************************************************
    显示中文
    no  :中文数组Hzk[] 编号
    示例:OLED_ShowCHinese(32,4,2);
*****************************************************************/
void OLED_ShowCHinese(u8 x,u8 y,u8 no)
{      			    
	u8 t,adder=0;
	OLED_SetPos(x,y);	
    for(t=0;t<16;t++)
    {
        WriteDat(Hzk[2*no][t]);
        adder+=1;
     }	
    OLED_SetPos(x,y+1);	
    for(t=0;t<16;t++)
    {	
        WriteDat(Hzk[2*no+1][t]);
        adder+=1;
    }					
}
/*****************************************************************
    OLED初始化
*****************************************************************/
void OLED_Init(void)
{
    GPIO_InitTypeDef  GPIO_InitStructure;
    delay_ms(100);
    
#ifdef OLEDIIC 
    
    GPIO_InitStructure.GPIO_Pin=I2CSCLPin | I2CSDAPin;
    GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;

    GPIO_Init(I2CSCLPort, &GPIO_InitStructure);
#else    
 	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Pin = OledCsPin;
 	GPIO_Init(OledCsPort, &GPIO_InitStructure);
    GPIO_SetBits(OledCsPort,OledCsPin);
    
    GPIO_InitStructure.GPIO_Pin = OledRstPin;
 	GPIO_Init(OledRstPort, &GPIO_InitStructure);
    GPIO_SetBits(OledRstPort,OledRstPin);
    
    GPIO_InitStructure.GPIO_Pin =OledRSPin ;
 	GPIO_Init(OledRSPort, &GPIO_InitStructure);
    GPIO_SetBits(OledRSPort,OledRSPin);
    
#if OLED_MODE==1
 
 	GPIO_InitStructure.GPIO_Pin =0xFF; //PA0~7 OUT推挽输出
 	GPIO_Init(GPIOA, &GPIO_InitStructure);
 	GPIO_SetBits(GPIOA,0xFF); //PA0~7输出高
	
	GPIO_InitStructure.GPIO_Pin = OledWRPin;
 	GPIO_Init(OledWRPort, &GPIO_InitStructure);
    GPIO_SetBits(OledWRPort,OledWRPin);

    GPIO_InitStructure.GPIO_Pin = OledRDPin;
 	GPIO_Init(OledRDPort, &GPIO_InitStructure);
    GPIO_SetBits(OledRDPort,OledRDPin);

#else
 	GPIO_InitStructure.GPIO_Pin = OledSckPin;
 	GPIO_Init(OledSckPort, &GPIO_InitStructure);
 	GPIO_SetBits(OledSckPort,OledSckPin);

 	GPIO_InitStructure.GPIO_Pin = OledSdinPin;
 	GPIO_Init(OledSdinPort, &GPIO_InitStructure);
 	GPIO_SetBits(OledSdinPort,OledSdinPin);

#endif
  							  
	OledCs_H();
    OledRS_H();
	OledRst_L();
	delay_ms(100);
	OledRst_H();
#endif    
    
    WriteCmd(0xAE); //display off
    WriteCmd(0x20); //Set Memory Addressing Mode    
    WriteCmd(0x10); //00,Horizontal Addressing Mode;01,Vertical Addressing Mode;10,Page Addressing Mode (RESET);11,Invalid
    WriteCmd(0xb0); //Set Page Start Address for Page Addressing Mode,0-7
    WriteCmd(0xc8); //Set COM Output Scan Direction
    WriteCmd(0x00); //---set low column address
    WriteCmd(0x10); //---set high column address
    WriteCmd(0x40); //--set start line address
    WriteCmd(0x81); //--set contrast control register
    WriteCmd(0xdf); //亮度调节 0x00~0xff
    WriteCmd(0xa1); //--set segment re-map 0 to 127
    WriteCmd(0xa6); //--set normal display
    WriteCmd(0xa8); //--set multiplex ratio(1 to 64)
    WriteCmd(0x3F); //
    WriteCmd(0xa4); //0xa4,Output follows RAM content;0xa5,Output ignores RAM content
    WriteCmd(0xd3); //-set display offset
    WriteCmd(0x00); //-not offset
    WriteCmd(0xd5); //--set display clock divide ratio/oscillator frequency
    WriteCmd(0xf0); //--set divide ratio
    WriteCmd(0xd9); //--set pre-charge period
    WriteCmd(0x22); //
    WriteCmd(0xda); //--set com pins hardware configuration
    WriteCmd(0x12);
    WriteCmd(0xdb); //--set vcomh
    WriteCmd(0x20); //0x20,0.77xVcc
    WriteCmd(0x8d); //--set DC-DC enable
    WriteCmd(0x14); //
    WriteCmd(0xaf); //--turn on oled panel
    OLED_CLS();
}

字库文件

codetab.h

#ifndef __CODETAB_H
#define	__CODETAB_H
#include "config.h"
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,// 0
  0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1
  0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2
  0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3
  0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4
  0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5
  0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6
  0x10,0x16,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,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14
  0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15
  0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16
  0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17
  0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18
  0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19
  0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20
  0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21
  0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22
  0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23
  0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24
  0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,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,0x80,0x60,0x00,0x00,0x00,0x00,//; 27
  0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28
  0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29
  0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30
  0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31
  0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,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,0x00,0x3F,0x00,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,0x18,0x24,0x24,0x38,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
  0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,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,0x0C,0x30,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,0x02,0x04,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,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65
  0x08,0xF8,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,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69
  0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,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
  0x08,0xF8,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
  0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75
  0x00,0x08,0x08,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,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80
  0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,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,0x00,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,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86
  0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87
  0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88
  0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,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,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91
  0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92
  0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93
  0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94
};
unsigned char Hzk[][32]={

{0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x88,0xF8,0x00,0x00,0x00},
{0x00,0x00,0x1F,0x08,0x08,0x08,0x08,0x7F,0x88,0x88,0x88,0x88,0x9F,0x80,0xF0,0x00},/*"µç",0*/
/* (16 X 16 , 电 )*/

{0x00,0x00,0xFE,0x02,0x82,0x82,0x82,0x82,0xFA,0x82,0x82,0x82,0x82,0x82,0x02,0x00},
{0x80,0x60,0x1F,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,0x44,0x58,0x40,0x40,0x00},/*"ѹ",1*/
/* (16 X 16 , 压 )*/

{0x10,0x10,0xD0,0xFF,0x90,0x14,0xE4,0xAF,0xA4,0xA4,0xA4,0xAF,0xE4,0x04,0x00,0x00},
{0x04,0x03,0x00,0xFF,0x00,0x89,0x4B,0x2A,0x1A,0x0E,0x1A,0x2A,0x4B,0x88,0x80,0x00},/*"Ä£",2*/
/* (16 X 16 , 模 )*/

{0x10,0x10,0x90,0x90,0x90,0x90,0x90,0x10,0x10,0xFF,0x10,0x10,0x11,0x16,0x10,0x00},
{0x00,0x20,0x60,0x20,0x3F,0x10,0x10,0x10,0x00,0x03,0x0C,0x10,0x20,0x40,0xF8,0x00},/*"ʽ",3*/
/* (16 X 16 , 式 )*/
};

#endif

main.c

#ifdef LedPort
void LedInit()
{
    GPIO_InitTypeDef  GPIO_InitStructure;
    GPIO_InitStructure.GPIO_Pin = LedPIN;              
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(LedPort, &GPIO_InitStructure);
    GPIO_ResetBits(LedPort,LedPIN);   
}
#endif

void System_Init()
{
    RCC_Configuration();
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
    
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);        // GPIOA clock 
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);        // GPIOB clock 
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);        // GPIOC clock 
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO ,ENABLE);        // AFIO  clock 
    GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE );   // JTAG Disable

#ifdef LedPort    
    LedInit();	        // Led Init 
#endif
#ifdef OLEDIIC     
    OLED_Init();
    OLED_ShowString(0,1,"oled is OK",16);
    OLED_CLS();
    OLED_ShowString(0,0," IIC bus Runing",16);
#else
#if OLED_SPI_X == 1
    OLED_Init();
    OLED_ShowString(0,1,"oled is OK",16);
    OLED_CLS();
    OLED_ShowString(0,0,"3Wire SPI Runing",16);
#else
    OLED_Init();
    OLED_ShowString(0,1,"oled is OK",16);
    OLED_CLS();
    OLED_ShowString(0,0,"4Wire SPI Runing",16);
#endif
#endif
    
}
int main(void)
{
    System_Init();
    while(1)
    {
        LedXor(LedPIN);
        OLED_ShowCHinese( 0,4,0);
        OLED_ShowCHinese(16,4,1);
        OLED_ShowCHinese(32,4,2);
        OLED_ShowCHinese(48,4,3);
        while(1);
    }
	
}

 

 

 

本文地址:https://blog.csdn.net/Corner_L/article/details/107645283