文章目录
- 原理图
- oled.c
- oled.h
- main.c
原理图
sbit OLED_SCL=P4^3;//SCL-D0
sbit OLED_SDA=P4^1;//SDA-D1
sbit OLED_RES =P3^6;//RES
sbit OLED_DC =P3^7;//DC
sbit OLED_CS=P2^7; //CS
oled.c
#include "OLED.h"//******************************说明*********************************************
//OLED显存存放方式:
// 0列 1列 2列 3列 4列 ... ... ... ... ... 127列
//0行
//1行
//2行
//3行
//4行
//5行
//6行
//7行
//******************************OLED*********************************************
//****************************定义说明*******************************************
//数组名称:ascii_0806[][6]
//数组说明:显示(ASCII)的西方文字点阵字库,点阵(字体)大小6x8
//作 者:
//******************************OLED**********************************************
unsigned char code
ascii_0806[][6] ={
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// space-空格
{ 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};//****************************定义说明*******************************************
//数组名称:ascii_1608[][16]
//数组说明:显示(ASCII)的西方文字点阵字库,点阵(字体)大小16x16
//作 者:
//******************************OLED**********************************************
unsigned char code
ascii_1608[][16]={
{ 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*/
};
//****************************定义说明*******************************************
//数组名称:HanZi[][32]
//数组说明:用户自定中文字库,需要用软件取模
//作 者:
//******************************OLED**********************************************
unsigned char code
HanZi[][32] = {
{0x00,0x80,0x60,0xF8,0x07,0x40,0x20,0x18,0x0F,0x08,0xC8,0x08,0x08,0x28,0x18,0x00,
0x01,0x00,0x00,0xFF,0x00,0x10,0x0C,0x03,0x40,0x80,0x7F,0x00,0x01,0x06,0x18,0x00},/*"你",0*/{0x10,0x10,0xF0,0x1F,0x10,0xF0,0x00,0x80,0x82,0x82,0xE2,0x92,0x8A,0x86,0x80,0x00,
0x40,0x22,0x15,0x08,0x16,0x61,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00},/*"好",1*/{0x24,0x24,0xA4,0xFE,0xA3,0x22,0x00,0x22,0xCC,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,
0x08,0x06,0x01,0xFF,0x00,0x01,0x04,0x04,0x04,0x04,0x04,0xFF,0x02,0x02,0x02,0x00},/*"科",2*/{0x10,0x10,0x10,0xFF,0x10,0x90,0x08,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x08,0x00,
0x04,0x44,0x82,0x7F,0x01,0x80,0x80,0x40,0x43,0x2C,0x10,0x28,0x46,0x81,0x80,0x00},/*"技",3*/
//这里添加用户字模代码
};//****************************函数说明*******************************************
//函数名称:delay_ms()
//函数功能: OLED延时函数
//参数说明:大致延时
//作 者:
//******************************OLED**********************************************
void delay_ms(unsigned int ms) {unsigned int a;while (ms) {a = 100;while (a--);ms--;}return;
}//****************************函数说明*******************************************
//函数名称:OLED_ColorTurn()
//函数功能: 反显函数
//参数说明:阳显示或阴显示。当参数i=0时,为阳显示;当参数i=1时,为阴显示
// 阳显示:初始化OLED128x64个像素点全灭,但需要显示的像素点亮起
// 阴显示:初始化OLED128x64个像素点全亮,但需要显示的像素点熄灭
//注 意:在OLED初始化函数OLED_Init()中,初始化设置为OLED_WrCmd(0xA6,0);
// 即阳显默认为正常显示。所以大多数情况下,需要反向显示为阴时,才需要调用本函数
// 并设定i=1,即OLED_ColorTurn(1);
//作 者:
//******************************OLED**********************************************
void OLED_ColorTurn(u8 i) {if (i == 0) {OLED_WrCmd(0xA6, 0);//阳显}if (i == 1) {OLED_WrCmd(0xA7, 0);//阴显}
}//****************************函数说明*******************************************
//函数名称:OLED_DisplayTurn()
//函数功能: 旋转显示函数
//参数说明:用于将显示的字符旋转180度。
// 当参数i=0时,为正常显示;
// 当参数i=1时,字符旋转180度显示。
//注 意:在OLED初始化函数OLED_Init()中,初始化设置为OLED_WrCmd(0xA1,0);OLED_WrCmd(0xC8,0);
// 即非反转状态为正常显示。如果显示屏的焊接排针更靠近自己,则需要使用反转显示
// 将其显示方向调转180度,需要设定i=1,即OLED_DisplayTurn(1);
//作 者:
//******************************OLED**********************************************
void OLED_DisplayTurn(u8 i) {if (i == 0) {OLED_WrCmd(0xC8, 0);//正常显示OLED_WrCmd(0xA1, 0);}if (i == 1) {OLED_WrCmd(0xC0, 0);//反转显示OLED_WrCmd(0xA0, 0);}
}//****************************函数说明*******************************************
//函数名称:OLED_WrCmd()
//函数功能: OLED命令写入函数
//参数说明:dat为需要写入的命令,cmd为控制位
// OLED的控制分为写命令和写数据。因为OLED数据和命令线共用一根引脚(DC--Data or Command),
// 我们向OLED发送一串数据时,它需要分清这是命令还是数据,所以我们需要控制好OLED上的DC位。
// 当DC=0,表示写命令,DC=1,表示写数据
//作 者:
//*******************************OLED********************************************
void OLED_WrCmd(u8 dat, u8 cmd) {u8 i;if (cmd)OLED_DC = 1;elseOLED_DC = 0;OLED_CS = 0;for (i = 0; i < 8; i++) {OLED_SCL = 0;if (dat & 0x80) {OLED_SDA = 1;} else {OLED_SDA = 0;}OLED_SCL = 1;dat <<= 1;}OLED_CS = 1;OLED_DC = 1;
}//****************************函数说明*******************************************
//函数名称:OLED_Set_Pos()
//函数功能: OLED坐标设置函数
//参数说明:用于确定OLED上需要显示字符的坐标
// x:表示列,范围0~127
// y:表示行,范围0~63
//作 者:
//*********************************OLED*******************************************
void OLED_Set_Pos(u8 x, u8 y) {OLED_WrCmd(0xb0 + y, 0);OLED_WrCmd(((x & 0xf0) >> 4) | 0x10, 0);OLED_WrCmd((x & 0x0f), 0);
}//****************************函数说明********************************************
//函数名称:OLED_Display_On()
//函数功能: 开启OLED显示函数。用于开启OLED显示
//作 者:
//******************************OLED**********************************************
void OLED_Display_On(void) {OLED_WrCmd(0X8D, 0); //SET DCDC命令OLED_WrCmd(0X14, 0); //DCDC ONOLED_WrCmd(0XAF, 0); //DISPLAY ON
}//****************************函数说明********************************************
//函数名称:OLED_Display_Off()
//函数功能: 关闭OLED显示函数。用于关闭OLED显示
//作 者:
//******************************OLED**********************************************
void OLED_Display_Off(void) {OLED_WrCmd(0X8D, 0); //SET DCDC命令OLED_WrCmd(0X10, 0); //DCDC OFFOLED_WrCmd(0XAE, 0); //DISPLAY OFF
}//****************************函数说明********************************************
//函数名称:OLED_CLR()
//函数功能: OLED清屏函数。用于清除全屏OLED显示。这里是所有像素点全灭。用阴显的注意了
//作 者:
//******************************OLED**********************************************
void OLED_CLR(void) {u8 i, n;for (i = 0; i < 8; i++) {OLED_WrCmd(0xb0 + i, 0); //设置页地址(0~7)OLED_WrCmd(0x00, 0); //设置显示位置—列低地址OLED_WrCmd(0x10, 0); //设置显示位置—列高地址for (n = 0; n < 128; n++)OLED_WrCmd(0, 1);} //更新显示
}//****************************函数说明********************************************
//函数名称:OLED_ShowChar()
//函数功能: OLED单字符显示函数
//参数说明:OLED在对应坐标显示一个字符。
// x:表示列,范围0~127
// y:表示行,范围0~63
// sizey:表示字体大小,可以选择6x8(sizey=8)或8x16(sizey=16)大小。
//作 者:
//*********************************OLED*******************************************
void OLED_ShowChar(u8 x, u8 y, u8 chr, u8 sizey) {u8 c = 0, sizex = sizey / 2;u16 i = 0, size1;if (sizey == 8)size1 = 6;else size1 = (sizey / 8 + ((sizey % 8) ? 1 : 0)) * (sizey / 2);c = chr - ' ';//得到偏移后的值OLED_Set_Pos(x, y);for (i = 0; i < size1; i++) {if (i % sizex == 0 && sizey != 8) OLED_Set_Pos(x, y++);if (sizey == 8) OLED_WrCmd(ascii_0806[c][i], 1);//6X8字号else if (sizey == 16) OLED_WrCmd(ascii_1608[c][i], 1);//8x16字号
// else if(sizey==xx) OLED_WrCmd(ascii_xxxx[c][i],1);//用户添加字号else return;}
}//m^n函数
u32 oled_pow(u8 m, u8 n) {u32 result = 1;while (n--)result *= m;return result;
}//****************************函数说明********************************************
//函数名称:OLED_ShowNum()
//函数功能: OLED显示数字(串)函数
//参数说明:OLED从对应坐标开始显示数字(串)。
// x:表示列,范围0~127
// y:表示行,范围0~63
// num:表示需要显示的数字大小
// len:表示需要显示的最大数字长度 【注意:假设要显示1234时,len=3,则只会显示“234”】
// 【注意:假设要显示4时,len=3,则会显示“ 4”,注意4前面有两个数字位空出】
// sizey:表示字体大小,可以选择6x8(sizey=8)或8x16(sizey=16)大小。
//作 者:
//*********************************OLED*******************************************
void OLED_ShowNum(u8 x, u8 y, u32 num, u8 len, u8 sizey) {u8 t, temp, m = 0;u8 enshow = 0;if (sizey == 8)m = 2;for (t = 0; t < len; t++) {temp = (num / oled_pow(10, len - t - 1)) % 10;if (enshow == 0 && t < (len - 1)) {if (temp == 0) {OLED_ShowChar(x + (sizey / 2 + m) * t, y, ' ', sizey);continue;} else enshow = 1;}OLED_ShowChar(x + (sizey / 2 + m) * t, y, temp + '0', sizey);}
}//****************************函数说明********************************************
//函数名称:OLED_ShowString()
//函数功能: OLED显示字符串函数
//参数说明:OLED从对应坐标开始显示数字(串)。
// x:表示列,范围0~127
// y:表示行,范围0~63
// *chr:指针,指向所需显示的字符串,字符串请使用双引号引起来
// sizey:表示字体大小,可以选择6x8(sizey=8)或8x16(sizey=16)大小。
//作 者:
//*********************************OLED*******************************************
void OLED_ShowString(u8 x, u8 y, u8 *chr, u8 sizey) {u8 j = 0;while (chr[j] != '\0') {OLED_ShowChar(x, y, chr[j++], sizey);if (sizey == 8)x += 6;else x += sizey / 2;}
}//*********************************OLED*******************************************
void OLED_ShowChinese(u8 x, u8 y, u8 no, u8 sizey) {u16 i, size1 = (sizey / 8 + ((sizey % 8) ? 1 : 0)) * sizey;for (i = 0; i < size1; i++) {if (i % sizey == 0) OLED_Set_Pos(x, y++);if (sizey == 16) OLED_WrCmd(HanZi[no][i], 1);//16x16字号
// else if(sizey==xx) OLED_WrCmd(xxx[c][i],1);//用户添加字号else return;}
}//****************************函数说明********************************************
//函数名称:OLED_DrawBMP()
//函数功能: OLED显示图片函数
//参数说明:OLED从对应坐标开始显示设定长宽的图片。
// x:表示列,范围0~127
// y:表示行,范围0~63
// sizex:长度,最长128
// sizey:宽度,最宽64
//作 者:
//*********************************OLED*******************************************
void OLED_DrawBMP(u8 x, u8 y, u8 sizex, u8 sizey, u8 BMP[]) {u16 j = 0;u8 i, m;sizey = sizey / 8 + ((sizey % 8) ? 1 : 0);for (i = 0; i < sizey; i++) {OLED_Set_Pos(x, i + y);for (m = 0; m < sizex; m++) {OLED_WrCmd(BMP[j++], 1);}}
}//****************************函数说明********************************************
//函数名称:OLED_Init()
//函数功能: OLED初始化函数
//说 明:用于初始化OLED//作 者:
//*********************************OLED*******************************************
void OLED_Init(void) {OLED_RES = 0;delay_ms(200);OLED_RES = 1;OLED_WrCmd(0xAE, 0);//--turn off oled panel-关OLED屏幕OLED_WrCmd(0x00, 0);//---set low column address-设置低位地址OLED_WrCmd(0x10, 0);//---set high column address-设置高位地址OLED_WrCmd(0x40,0);//--set start line address Set Mapping RAM Display Start Line (0x00~0x3F)-设置起始行地址和映射RAM显示起始行(0x00~0x3F)OLED_WrCmd(0x81, 0);//--set contrast control register-设置对比控制寄存器OLED_WrCmd(0xCF, 0);// Set SEG Output Current Brightness-设置输出电流OLED_WrCmd(0xA1, 0);//--Set SEG/Column Mapping-设置SEG/列映射 0xa0左右反置 0xa1正常OLED_WrCmd(0xC8, 0);//Set COM/Row Scan Direction-设置COM/行扫描方向 0xc0上下反置 0xc8正常OLED_WrCmd(0xA6, 0);//--set normal display-设置正常显示(阳显)OLED_WrCmd(0xA8, 0);//--set multiplex ratio(1 to 64) 设置多路复用比率OLED_WrCmd(0x3f, 0);//--1/64 dutyOLED_WrCmd(0xD3, 0);//-set display offset Shift Mapping RAM Counter (0x00~0x3F)-设置显示偏移移位映射RAM计数器(0OLED~0x3F)OLED_WrCmd(0x00, 0);//-not offset-不偏移OLED_WrCmd(0xd5, 0);//--set display clock divide ratio/oscillator frequency-设置显示时钟分频比/振荡器频率OLED_WrCmd(0x80, 0);//--set divide ratio, Set Clock as 100 Frames/Sec-设置分频比,将时钟设置为100帧/秒OLED_WrCmd(0xD9, 0);//--set pre-charge period-设置预充电周期OLED_WrCmd(0xF1, 0);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock 将预充电设置为15个时钟,放电为1个时钟OLED_WrCmd(0xDA, 0);//--set com pins hardware configuration-设置com引脚硬件配置OLED_WrCmd(0x12, 0);OLED_WrCmd(0xDB, 0);//--set vcomhOLED_WrCmd(0x40, 0);//Set VCOM Deselect LevelOLED_WrCmd(0x20, 0);//-Set Page Addressing Mode (0x00/0x01/0x02)-设置页面地址模式OLED_WrCmd(0x02, 0);//OLED_WrCmd(0x8D, 0);//--set Charge Pump enable/disableOLED_WrCmd(0x14, 0);//--set(0x10) disableOLED_WrCmd(0xA4, 0);// Disable Entire Display On (0xa4/0xa5)OLED_WrCmd(0xA6, 0);// Disable Inverse Display On (0xa6/a7)OLED_CLR(); //清屏OLED_WrCmd(0xAF, 0); /*display ON*///打开OLED屏幕
}
oled.h
#ifndef __OLED_H
#define __OLED_H#include "STC89C5xRC.h"#define u8 unsigned char
#define u16 unsigned int
#define u32 unsigned int //注意,此处定义和u16一样用于节省代码占用空间
//如果OLED_ShowNum()函数需要装下更大的数,则请改此处的数据定义类型/*口袋板OLED电路引脚定义*/
sbit OLED_SCL=P4^3;//SCL-D0
sbit OLED_SDA=P4^1;//SDA-D1
sbit OLED_RES =P3^6;//RES
sbit OLED_DC =P3^7;//DC
sbit OLED_CS=P2^7; //CS/*Proteus仿真引脚定义*/
//sbit OLED_SCL=P1^4;//SCL-D0
//sbit OLED_SDA=P1^3;//SDA-D1
//sbit OLED_RES =P1^2;//RES
//sbit OLED_DC =P1^1;//DC
//sbit OLED_CS=P1^0; //CS//OLED控制用函数
void delay_ms(unsigned int ms);
void OLED_ColorTurn(u8 i);
void OLED_DisplayTurn(u8 i);
void OLED_WrCmd(u8 dat,u8 cmd);
void OLED_Set_Pos(u8 x, u8 y);
void OLED_Display_On(void);
void OLED_Display_Off(void);
void OLED_CLR(void);
void OLED_ShowChar(u8 x,u8 y,u8 chr,u8 sizey);
u32 oled_pow(u8 m,u8 n);
void OLED_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 sizey);
void OLED_ShowString(u8 x,u8 y,u8 *chr,u8 sizey);
void OLED_ShowChinese(u8 x,u8 y,u8 no,u8 sizey);
void OLED_DrawBMP(u8 x,u8 y,u8 sizex, u8 sizey,u8 BMP[]);
void OLED_Init(void);#endif
main.c
#include "STC89C5xRC.h" //STC89C52RC的头文件
#include "OLED.h" //OLED显示头文件
//#include "Codedat.h" //图片取模头文件。将图片取模后,放入该头文件用于显示sbit beep = P2^4; //蜂鸣器引脚
/*******************************************************************************
* 函 数 名 : main
* 函数功能 : 主函数
* 输 入 : 无
* 输 出 : 无
*******************************************************************************/
int main(void)
{beep=0; //蜂鸣器不响OLED_Init(); //初始化OLEDOLED_ShowChinese(31,0,0,16);//“晨”。从第0+1行,第31+1列开始,显示对应位置号0的汉字,字体大小16x16OLED_ShowChinese(47,0,1,16);//“启”。从第1+1行,第47+1列开始,显示对应位置号1的汉字,字体大小16x16OLED_ShowChinese(63,0,2,16);//“科”OLED_ShowChinese(79,0,3,16);//“技”OLED_ShowString(0,2,"asd1234",16);while(1) //while中不进行任何显示显示操作更新,那么OLED就会一直显示上面的“科技” ,不会刷新。{}
}