ESP8266 RTOS使用IIC连接sdd1306的0.9OLED屏

这里要注意这里IIC通讯时不然大量调用os_printf("---test---");这样的语句,会出现不可意料的错误与系统崩溃。这是我自己的遇到的坑
另IIC通讯一定要多看数据手册,因为没示波器,无法看到波形。所以更要注意相关的问题点。
主程序使用方法

OLED_Init();
OLED_ShowString(0,0,(unsigned char *)"This is test");

c文件

#include <stdlib.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"

#include "esp_log.h"
#include "esp_system.h"
#include "esp_err.h"

#include "lwip/sys.h"

#include "driver/i2c.h"
#include "driver/gpio.h"
#include "user_ssd1306.h"

#define I2C_SCL_IO GPIO_NUM_2
#define I2C_SDA_IO GPIO_NUM_4
#define SSD1306_SENSOR_ADDR  0x78
#define ACK_CHECK_EN      0x1 
typedef enum { 
     OLED_CMD = 0,  /*!< I2C port 0 */
    OLED_DATA =1
} OLED_type;
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
};
static esp_err_t i2c_master_init()
{
i2c_config_t conf;
  conf.mode=I2C_MODE_MASTER;
  conf.sda_io_num = I2C_SDA_IO;
  conf.sda_pullup_en =GPIO_PULLUP_ENABLE;
  conf.scl_io_num = I2C_SCL_IO;
  conf.scl_pullup_en =GPIO_PULLUP_ENABLE;
   conf.clk_stretch_tick = 300;
  i2c_driver_install(I2C_NUM_0,conf.mode);
  i2c_param_config(I2C_NUM_0,&conf);
  os_printf( "-i2c_master_init----ok-");
    return ESP_OK;
}
/**
 * @brief test code to write SSD1306
 * 1. send data
 * ________________________________________________________________________________________
 * | start | slave_addr(7)+ wr_bit + ack | C0_bit D/C#_bit + ack | Databyte + ack  | stop |
 * --------|-----------------------------|-----------------------|-----------------|------|
 *
 * @param i2c_num I2C port number
 * @param reg_address slave reg address
 * @param data data to send
 * @param data_len data length
 *
 * @return
 *     --Co位逻辑“0”,则后面信息的传输将只包含数据字节。
 *     --c#位逻辑“0“  后面数据字节定义为命令,逻辑“1” 数据字节定义为将存储在GDDRAM中的数据
*/
static esp_err_t i2c_example_master_SSD1306_write(i2c_port_t i2c_num, uint8_t reg_address, uint8_t *data, size_t data_len)
{
    
    int ret;
    i2c_cmd_handle_t cmd = i2c_cmd_link_create();
    i2c_master_start(cmd);
    i2c_master_write_byte(cmd, SSD1306_SENSOR_ADDR | I2C_MASTER_WRITE, ACK_CHECK_EN); //7位地址与操作读写位(请查官方手册),读写位设置为写
    i2c_master_write_byte(cmd,reg_address,ACK_CHECK_EN); //
    i2c_master_write(cmd, data, data_len, ACK_CHECK_EN); //发送数据
    i2c_master_stop(cmd); //I2C主设备的队列命令以生成停止信号。
    ret = i2c_master_cmd_begin(i2c_num, cmd, 1000 / portTICK_RATE_MS); //发送排队的命令
    i2c_cmd_link_delete(cmd);
    
    return ret;
}
// 向OLED写入一字节数据/指令
void  OLED_WR_Byte(unsigned char OLED_Byte, unsigned char OLED_Type)
{
	if(OLED_Type)
		// 向OLED写入数据字节
		 i2c_example_master_SSD1306_write(I2C_NUM_0,0x40,&OLED_Byte,1);		
	else
		// 向OLED写入指令字节
		i2c_example_master_SSD1306_write(I2C_NUM_0,0x00,&OLED_Byte,1);
}
// 整屏写入某值
void  OLED_Clear(void)
{
	unsigned char N_Page, N_row;
	for(N_Page=0; N_Page<8; N_Page++)
	{
		OLED_WR_Byte(0xb0+N_Page,OLED_CMD);	// 页地址0xb0,从0~7页依次写入
		OLED_WR_Byte(0x00,OLED_CMD);      	// 列低地址
		OLED_WR_Byte(0x10,OLED_CMD);      	// 列高地址
		for(N_row=0; N_row<128; N_row++)OLED_WR_Byte(0x00,OLED_DATA);
       // vTaskDelay(300/portTICK_RATE_MS);	
	}
}
// 设置数据写入的起始(参数1:页、参数2:列)
void  OLED_Set_Pos(unsigned char x, unsigned char y)
{
	OLED_WR_Byte(0xb0+y,OLED_CMD);				// 写入页地址
	OLED_WR_Byte((x&0x0f),OLED_CMD);  			// 写入列的地址(低半字节)
	OLED_WR_Byte(((x&0xf0)>>4)|0x10,OLED_CMD);	// 写入列的地址(高半字节)
}
void  OLED_Init(void)
{
  i2c_master_init();
	// IIC_Init_JX();					// 初始化IIC
	// system_soft_wdt_feed();			// 喂狗(防止ESP8266复位)
	vTaskDelay(100/portTICK_RATE_MS);					// 延迟(必须要有)
   
    OLED_WR_Byte(0xAE,OLED_CMD);	// 关闭显示
    OLED_WR_Byte(0x00,OLED_CMD);	// 设置低列地址
 	OLED_WR_Byte(0x10,OLED_CMD);	// 设置高列地址
	OLED_WR_Byte(0x40,OLED_CMD);	// 设置起始行地址
	OLED_WR_Byte(0xB0,OLED_CMD);	// 设置页地址
	OLED_WR_Byte(0x81,OLED_CMD); 	// 对比度设置,可设置亮度
	OLED_WR_Byte(0xFF,OLED_CMD);	// 265
	OLED_WR_Byte(0xA1,OLED_CMD);	// 设置段(SEG)的起始映射地址
	OLED_WR_Byte(0xA6,OLED_CMD);	// 正常显示;0xa7逆显示
	OLED_WR_Byte(0xA8,OLED_CMD);	// 设置驱动路数(16~64)
	OLED_WR_Byte(0x3F,OLED_CMD);	// 64duty
	OLED_WR_Byte(0xC8,OLED_CMD);	// 重映射模式,COM[N-1]~COM0扫描
	OLED_WR_Byte(0xD3,OLED_CMD);	// 设置显示偏移
	OLED_WR_Byte(0x00,OLED_CMD);	// 无偏移
	OLED_WR_Byte(0xD5,OLED_CMD);	// 设置震荡器分频
	OLED_WR_Byte(0x80,OLED_CMD);	// 使用默认值
	OLED_WR_Byte(0xD9,OLED_CMD);	// 设置 Pre-Charge Period
	OLED_WR_Byte(0xF1,OLED_CMD);	// 使用官方推荐值
	OLED_WR_Byte(0xDA,OLED_CMD);	// 设置 com pin configuartion
	OLED_WR_Byte(0x12,OLED_CMD);	// 使用默认值
	OLED_WR_Byte(0xDB,OLED_CMD);	// 设置 Vcomh,可调节亮度(默认)
	OLED_WR_Byte(0x40,OLED_CMD);	// 使用官方推荐值
	OLED_WR_Byte(0x8D,OLED_CMD);	// 设置OLED电荷泵
	OLED_WR_Byte(0x14,OLED_CMD);	// 开显示
	OLED_WR_Byte(0xAF,OLED_CMD);	// 开启OLED面板显示
        OLED_Clear();                 // 清屏
	OLED_Set_Pos(0,0); 				    // 设置数据写入的起始行、列
}

// 在指定坐标处显示一个字符
void  OLED_ShowChar(unsigned char x, unsigned char y, unsigned char Show_char)
{
	unsigned char c=0,i=0;
 
	c=Show_char-' '; 				// 获取字符的偏移量
	if(x>128-1){x=0;y=y+2;}	// 当列数超出范围,则另起2页
	if(16 ==16) 					// 字符大小为[8*16]:一个字符分两页
	{
		OLED_Set_Pos(x,y);						// 设置画点起始处
		for(i=0;i<8;i++)  						// 循环8次(8列)
		OLED_WR_Byte(F8X16[c*16+i],OLED_DATA); 	// 找到字模
		OLED_Set_Pos(x,y+1); 					// 页数加1
		for(i=0;i<8;i++)  						// 循环8次
		OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA);// 把第二页画完
	}
}
 
// 在指定坐标起始处显示字符串,参数1列,参数2页,字符串
void  OLED_ShowString(unsigned char x, unsigned char y, unsigned char * Show_char)
{
	unsigned char N_Char = 0;		// 字符序号
	while (Show_char[N_Char]!='\0') 	// 如果不是最后一个字符
	{
		OLED_ShowChar(x,y,Show_char[N_Char]); 	// 显示一个字符
		x += 8;					// 列数加8,一个字符占8列
		if(x>=128){x=0;y+=2;} 	// 当x>=128,另起一页
		N_Char++; 				// 指向下一个字符
	}
}

头文件

#ifndef _USER_SSD1306_H_
#define _USER_SSD1306_H_
#include "driver/gpio.h"

void  OLED_Clear(void);
void OLED_Init(void);
void OLED_ShowChar(unsigned char x, unsigned char y, unsigned char Show_char);
void  OLED_ShowString(unsigned char x, unsigned char y, unsigned char * Show_char);
#endif

猜你喜欢

转载自www.cnblogs.com/praybb/p/12792575.html