OLED驱动 (51单片机)

#include "REG51.h"
sbit LCD_SCL=P1^0; //时钟 D0(SCLK)
sbit LCD_SDA=P1^1; //D1(MOSI) 数据
sbit LCD_RST=P1^2; //复位 
sbit LCD_DC =P1^3; //数据/命令控制
#define XLevelL		0x00
#define XLevelH		0x10
#define XLevel	    ((XLevelH&0x0F)*16+XLevelL)
#define Max_Column	128
#define Max_Row		64
#define	Brightness	0xCF 
#define X_WIDTH 128
#define Y_WIDTH 64

void LCD_DLY_ms(unsigned int ms)  //LCD 延时1ms
{                         
   unsigned int a;
   while(ms)
   {
     a=1800;
     while(a--);
     ms--;
}
return;
}

void LCD_WrDat(unsigned char dat)   //**LCD写数据  
{
   unsigned char i=8;					   	
   LCD_DC=1;  
   for(i=0;i<8;i++) //发送一个八位数据 
   {
     LCD_SCL=0;  						  
     LCD_SDA=dat&0x80;
     LCD_SCL=1;             
     dat<<=1;    
   }
}
void LCD_WrCmd(unsigned char cmd) 	 //****LCD写命令
{
  unsigned char i=8;						   
  LCD_DC=0;
  for(i=0;i<8;i++) //发送一个八位数据 
  { 
    LCD_SCL=0; 
    LCD_SDA=cmd&0x80;
    LCD_SCL=1;
    cmd<<=1;;   
  } 	
}

void LCD_Setxy(unsigned char x, unsigned char y) 	//LCD 设置坐标
{ 
  LCD_WrCmd(0xb0+y);
  LCD_WrCmd(((x&0xf0)>>4)|0x10);
  LCD_WrCmd((x&0x0f)|0x01); 
} 
void LCD_Fill(unsigned char bmp_dat)   //bmp_dat=0x00全屏灭,bmp_dat=0xff全屏亮
{
   unsigned char y,x;
   for(y=0;y<8;y++)
   {
     LCD_WrCmd(0xb0+y);
     LCD_WrCmd(0x01);
     LCD_WrCmd(0x10);
     for(x=0;x126)
	    {x=0;y++;}
     LCD_Setxy(x,y);    
     for(i=0;i<6;i++)     
       LCD_WrDat(F6x8[c][i]);  
     x+=6;
     j++;
   }
}
void LCD_Cler_6x8(unsigned char x,y,n)//清除N个6*8字符
{
   unsigned int i=0;
   LCD_Setxy(x,y);
   if(x>126)
	 {x=0;y++;}
   for(i=0;i<6*n;i++)
       LCD_WrDat(0x00);
}
void ready(unsigned char x,y,unsigned int num)
{
      switch (num)
      {
	    case 0:
	       LCD_6x8(x,y,"0");break;
	    case 1:
	       LCD_6x8(x,y,"1");break;
	    case 2:
	       LCD_6x8(x,y,"2");break;
	    case 3:
	       LCD_6x8(x,y,"3");break;
	    case 4:
	       LCD_6x8(x,y,"4");break;
	    case 5:
	       LCD_6x8(x,y,"5");break;
	    case 6:
	       LCD_6x8(x,y,"6");break;
	    case 7:
	       LCD_6x8(x,y,"7");break;
	    case 8:
	       LCD_6x8(x,y,"8");break;
	    case 9:
	       LCD_6x8(x,y,"9");break;  
      }	
}
/*void LCD_8x16(unsigned char x, y,unsigned char ch[])//显示8*16一组标准ASCII字符串	 显示的坐标(x,y),y为页范围0~7
{
  unsigned char c=0,i=0,j=0;
  while (ch[j]!='\0')
  {    
    c =ch[j]-32;
    if(x>120)
	  {x=0;y++;}
    LCD_Setxy(x,y);    
    for(i=0;i<8;i++)     
      LCD_WrDat(F8X16[c*16+i]);
    LCD_Setxy(x,y+1);    
    for(i=0;i<8;i++)     
      LCD_WrDat(F8X16[c*16+i+8]);  
    x+=8;
    j++;
  }
}
void LCD_Cler_8x16(unsigned char x, y,n) //清除n个8*16字符
{
    unsigned char i;
    if(x>120)
	  {x=0;y++;}
	LCD_Setxy(x,y);
	for(i=0;i<8*n;i++)
	  LCD_WrDat(0x00);
    LCD_Setxy(x,y+1);
	for(i=0;i<8*n;i++)
	  LCD_WrDat(0x00);    
}
void LCD_16x16(unsigned char x, y, N)//显示16*16点阵  显示的坐标(x,y),y为页范围0~7
{
  unsigned char wm=0;
  unsigned int adder=32*N;  //  	
  LCD_Setxy(x , y);
  for(wm = 0;wm < 16;wm++)  //             
  {
    LCD_WrDat(F16x16[adder]);	
    adder += 1;
  }      
  LCD_Setxy(x,y + 1); 
  for(wm = 0;wm < 16;wm++) //         
  {
    LCD_WrDat(F16x16[adder]);
    adder += 1;
  } 	  	
}
void LCD_Cler_16x16(unsigned char x,y,n)//清除n个16*16字
{
  unsigned char i=0;
  LCD_Setxy(x,y);
  for(i=0;i<16*n;i++)
     LCD_WrDat(0x00);
  LCD_Setxy(x,y+1);
  for(i=0;i<16*n;i++)
     LCD_WrDat(0x00);
}
void Draw_BMP(unsigned char x0, y0,x1, y1,unsigned char BMP[])//显示显示BMP图片128×64起始点坐标(x,y),x的范围0~127,y为页的范围0~7*
{ 	
 unsigned int j=0;
 unsigned char x,y;
  
  if(y1%8==0)
     y=y1/8;      
  else 
     y=y1/8+1;
  for(y=y0;y


6 * 8

#include
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
};


你可能感兴趣的:(MCU相关)