OLED液晶屏笔记

时间:2021-05-14 08:46:54

硬件:龙邱的OLED,不确定接5V还是3.3V,接上5V之后,有一个二极管很烫,接3.3V正常,还好有这样一个现象,否则可能会烧毁液晶屏。

由于没有使用这个硬件条件,用的是5V单片机,只是将电源接到了3.3V,也是可以用的。

OLED液晶屏笔记

有关OLED液晶显示地址的定位函数:

void LCD_Set_Pos(unsigned char x, unsigned char y)


  LCD_WrCmd(0xb0+y); //设置页地址
  LCD_WrCmd(((x&0xf0)>>4)|0x10);   //设置行高四位地址

  LCD_WrCmd((x&0x0f)|0x00); //设置行低四位地址

}

OLED液晶屏笔记

手册页地址设置命令

X2/X1/X0 = 000~111  对应PAGE0~PAGE7

OLED液晶屏笔记

手册行地址设置命令

有关LED写数据或命令的函数:

//SD1306写入一个数据或命令
//dat:要写入的数据或命令
//cmd:1:数据  0:命令
void OLED_WR_Byte(u8 dat,u8 cmd)
{

u8 i; 
if(cmd)
 OLED_DC=1;
else 
 OLED_DC=0; 
OLED_CS=0;
for(i=0;i<8;i++)
{ 
OLED_SCLK=0;

if(dat&0x80)
  OLED_SDIN_=1;
else

  OLED_SDIN=0;

OLED_SCLK=1;
dat<<=1;   
} 
OLED_CS=1;
       //OLED_DC=1;   

OLED液晶屏笔记

OLED写数据时序图

OLED清屏写法

LCD_Clear(0x00);

void LCD_Clear(unsigned char bmp_dat)
{
unsigned char y,x;

for(y=0;y<8;y++)//PAGE0~PAGE7
{
LCD_WrCmd(0xb0+y);

//设置每页X起始地址均从头开始
LCD_WrCmd(0x00);//低四位行地址设置
LCD_WrCmd(0x10); //四位行地址设置
for(x=0;x<X_WIDTH;x++)                    //X_WIDTH=128,写数据将每一个点均设置为0x00
LCD_WrDat(bmp_dat);
}
}

有关OLED初始化函数

void LCD_Init(void)        
{  
LCD_SCL=1;
//LCD_CS=1;
LCD_RST=0;
LCD_DLY_ms(50);
LCD_RST=1;

//从上面到下面开始初始化要有足够的时间,即等待RC复位完毕

//写程序时曾试图屏蔽掉这些命令,但是OLED不显示,具体没有细究

  LCD_WrCmd(0xae);//--turn off oled panel
  LCD_WrCmd(0x00);//---set low column address
  LCD_WrCmd(0x10);//---set high column address
  LCD_WrCmd(0x40);//--set start line address  Set Mapping RAM Display Start Line (0x00~0x3F)
  LCD_WrCmd(0x81);//--set contrast control register
  LCD_WrCmd(0xcf); // Set SEG Output Current Brightness
  LCD_WrCmd(0xa1);//--Set SEG/Column Mapping     0xa0左右反置 0xa1正常
  LCD_WrCmd(0xc8);//Set COM/Row Scan Direction   0xc0上下反置0xc8正常
  LCD_WrCmd(0xa6);//--set normal display
  LCD_WrCmd(0xa8);//--set multiplex ratio(1 to 64)
  LCD_WrCmd(0x3f);//--1/64 duty
  LCD_WrCmd(0xd3);//-set display offset Shift Mapping RAM Counter (0x00~0x3F)
  LCD_WrCmd(0x00);//-not offset
  LCD_WrCmd(0xd5);//--set display clock divide ratio/oscillator frequency
  LCD_WrCmd(0x80);//--set divide ratio, Set Clock as 100 Frames/Sec
  LCD_WrCmd(0xd9);//--set pre-charge period
  LCD_WrCmd(0xf1);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
  LCD_WrCmd(0xda);//--set com pins hardware configuration
  LCD_WrCmd(0x12);
  LCD_WrCmd(0xdb);//--set vcomh
  LCD_WrCmd(0x40);//Set VCOM Deselect Level
  LCD_WrCmd(0x20);//-Set Page Addressing Mode (0x00/0x01/0x02)
  LCD_WrCmd(0x02);//
  LCD_WrCmd(0x8d);//--set Charge Pump enable/disable
  LCD_WrCmd(0x14);//--set(0x10) disable
  LCD_WrCmd(0xa4);// Disable Entire Display On (0xa4/0xa5)
  LCD_WrCmd(0xa6);// Disable Inverse Display On (0xa6/a7) 

OLED_WR_Byte(0xAF,0);   
LCD_Clear(0x00);
  LCD_Set_Pos(0,0);

}

OLED液晶屏笔记

开关液晶显示命令

//在指定位置显示一个6X8字符

/************************************6*8字符************************************/
const unsigned char code 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
};

void LCD_P6x8Str(unsigned char x,unsigned char y,unsigned char ch[])
{
  unsigned char c=0,i=0,j=0;      
  while (ch[j]!='\0')
  {    
    c =ch[j]-32;
    if(x>126){x=0;y++;}    //0~128中6的最大倍数是126,如果大于126,最后一个字符显示不出来
    LCD_Set_Pos(x,y);    
  for(i=0;i<6;i++)     
   LCD_WrDat(F6x8[c][i]);  
  x+=6;
  j++;
  }

}

显示汉字

const unsigned char F14x16[] = {  
0x10,0x10,0x10,0x10,0x10,0xFF,0x10,0xF0,0x12,0x1C,0xD0,0x10,0x10,0x10,
0x40,0x20,0x10,0x0C,0x03,0x10,0x08,0x3F,0x42,0x41,0x40,0x40,0x40,0x70,//龙
0x00,0x00,0xFE,0x84,0x84,0x84,0x84,0x82,0x82,0x82,0x82,0xC0,0x80,0x00,
0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x30,0x20,//邱
0x14,0x13,0x92,0x7E,0x32,0x52,0x92,0x00,0x7C,0x44,0x44,0x44,0x7C,0x00,
0x01,0x01,0x00,0xFF,0x49,0x49,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,0x00,//智
0xB8,0x97,0x92,0x90,0x94,0xB8,0x10,0x00,0x7F,0x48,0x48,0x44,0x74,0x20,
0xFF,0x0A,0x0A,0x4A,0x8A,0x7F,0x00,0x00,0x3F,0x44,0x44,0x42,0x72,0x20,//能
};

//显示6X14的汉字:N代表第几个28的倍数,因为14X16,一个汉字占一维数组中的28个元素

//行列扫描

//比起Nokia的汉字用结构体显示的程序,相对来说通俗易懂,比较简单

void LCD_P14x16Ch(unsigned char x,unsigned char y,unsigned char N)
{
unsigned char wm=0,ii = 0;
unsigned int adder=28*N;    //目的是指向某一个汉字的起始元素
  LCD_Set_Pos(x , y);
  for(wm = 0;wm < 14;wm++)               
  {
  LCD_WrDat(F14x16[adder]);
  adder += 1;
  }      
  LCD_Set_Pos(x,y + 1); 
  for(wm = 0;wm < 14;wm++)          
  {
  LCD_WrDat(F14x16[adder]);
  adder += 1;
  }  
}

LCD_P14x16Ch(36,0,0); //龙                //每个汉字占两个PAGE
LCD_P14x16Ch(50,0,1);//邱
LCD_P14x16Ch(64,0,2);//智
LCD_P14x16Ch(78,0,3); //能    
LCD_P6x8Str(16,6,"chiusir@yahoo.cn"); //6X8字体OLED显示占一个PAGE

 LCD_P6x8Str(34,7,"2011-09-03");