文档库 最新最全的文档下载
当前位置:文档库 › OLED驱动ICssd1305初始化代码

OLED驱动ICssd1305初始化代码

extern unsigned char daoxian;
extern void delay(long v);

#define CS_0 P2OUT &=~BIT0
#define CS_1 P2OUT |= BIT0

#define DC_0 P2OUT &=~BIT2
#define DC_1 P2OUT |= BIT2

#define WR_0 P4OUT &=~BIT0
#define WR_1 P4OUT |= BIT0

#define RDE_1 P4OUT |= BIT1
#define RDE_0 P4OUT &=~BIT1
#define XDATA P3OUT
/* ************************* */
// 函数名称: wcode
// 函数功能: 显示器写指令
// 入口变量:
// 出口变量:
// 修改记录:
//***********************
// 写指令
// 模式:bs1=1,bs2=1,硬件直接配置
// 选8080模式
// 先片选:CS, :P2.0=0
// D-C=1 :P2.2=0
// W-R=0 :P4.0=0
// R-D(E):0-1-0 :P4.1
// 数据 :P3口
/* ************************* */
void wcode(unsigned char c) // 写指令
{
CS_0;
DC_0;
RDE_1;
WR_0;
delay(3);
XDATA=c;
delay(10);
WR_1;
delay(3);
CS_1;

}
/* ************************* */
// 函数名称: wdata
// 函数功能: 显示器写数据
// 入口变量:
// 出口变量:
// 修改记录:
//***********************
// 写数据
// 模式:bs1=1,bs2=1,硬件直接配置
// 选8080模式
// 先片选:CS, :P2.0=0
// D-C=1 :P2.2=1
// W-R=0 :P4.0=0
// R-D(E):0-1-0 :P4.1
// 数据 :P3口
/* ************************* */

void wdata(unsigned char c)
{
CS_0;
DC_1;
RDE_1;
WR_0;
delay(3);
XDATA=c;
delay(10);
WR_1;
delay(3);
CS_1;

}
/* ************************* */
// 函数名称: lcd_init
// 函数功能: 显示器初始化
// 入口变量:
// 出口变量:
// 修改记录:
//***********************
void OLED_init(void)
{ wcode(0xae);

wcode(0x21); // set column address
wcode(0x00); // start column 0
wcode(0x7f); // end column 127

delay(10);
wcode(0xa1); //segment remap
delay(10);
wcode(0xc8); //common output scan direction:com63~com0
delay(10);
wcode(0xda); //common pads hardware: alternative
delay(10);
wcode(0x12);
delay(10);
wcode(0xa8); //multiplex ration mode:63
delay(10);
wcode(0x3f);
delay(10);
wcode(0xd5); //display divide ratio/osc. freq. mode
delay(10);
wcode(0x70); //Osc. Freq:320kHz,DivideRation:1
delay(10);
wcode(0x81); //contrast control
delay(10);
wcode(0x70); // mode:64
delay(10);
wcode(0xd9); //set pre-charge period
delay(10);
wcode(0x22); //set period 1:1;period 2:15
delay(10);
wcode(0x20); //Set Memory Addressing Mode
delay(10);
wcode(0x02); //page addressing mode
delay(10);
wcode(0xdb); //VCOM desel

ect level mode
delay(10);
wcode(0x3c); //set Vvcomh=0.83*Vcc
delay(10);
wcode(0xad); //master configuration
delay(10);
wcode(0x8e); //external VCC supply
delay(10);
wcode(0xa4); //out follows RAM content
delay(10);
wcode(0xa6); //set normal display
delay(10);
wcode(0xaf);
delay(10);

}
/* ************************* */
// 设置开始页
/* ************************* */
void set_startpage(unsigned char p)
{
p=0xb0+p; // 开始页
wcode(p);
}
/* ************************* */
// 设置开始行
/* ************************* */
void set_startline(unsigned char x)
{
x=0x40+x; // 开始行
wcode(x);
}
/* ************************* */
// 设置开始列
/* ************************* */
void set_startcol(unsigned char y)
{ unsigned char yh,yl;
yl = y;
yh = y;
yl &=0x0f;
yh =yh>>4;
yh &=0x0f;
yh =yh+0x10;
wcode(yh); // 页地址
wcode(yl); // 列地址
}
/* ************************* */
// 显示开关
//
/* ************************* */
void dison_off(unsigned char o)
{
o=o+0xae;
wcode(o);
}
/* ************************* */
// 整屏清除
//
/* ************************* */
void clr(void)
{ unsigned char loop,i;
wcode(0xaf);
wcode(0x40);
for(i=0;i<8;i++)
{
wcode(0xb0+i);
wcode(0x10);
wcode(0x00);
for(loop=0;loop<132;loop++)
{ wdata(0xff);}
}
}

/* ************************* */
// 写整屏
//
/* ************************* */

void full(void)
{ unsigned char loop,i;
wcode(0xaf);
wcode(0x40);
for(i=0;i<8;i++)
{
wcode(0xb0+i);
wcode(0x00);
wcode(0x10);
for(loop=0;loop<132;loop++)
wdata(0xff);
}

}
/* ************************* */
// 写垂直线
/* ************************* */

void vhl(void)
{ unsigned char i;

for(i=0;i<8;i++)
{
set_startpage(i); // 第i页,第0列
set_startline(0); // 第0行
set_startcol (63); // 写第n=63列
wdata(0xff);
}
for(i=0;i<8;i++)
{
set_startpage(i); // 第i页,第0列
set_startline(0); // 第0行
set_startcol (64); // 写第n=64列
wdata(0xff);
}
}
/* ************************* */
// 写水平线
/* ************************* */
void hol(void)
{ unsigned char i;
set_startpage(4); // 第i页,第0列
set_startline(0); // 第0行
for(i=0;i<132;i++)
{
set_startcol (i); // 写第n=64列
wdata(0x01);
}
}
/* ************************* */
// 写128*64点阵图片
/* ************************* */

void wpicdot(const char *

pic)
{ unsigned char loop,i;
if (daoxian==0x01)
{
wcode(0xa1); //ADC set from seg1~128
wcode(0xc8); //shl set form com1~64
}
for(i=0;i<8;i++)
{
set_startpage(i); // 第i页,第0列
if (daoxian==0x01)
{set_startline(0); // 第4列
set_startcol (4);
}
else
{set_startline(0); // 第0行
set_startcol (0);
}
for(loop=0;loop<128;loop++)
{ wdata(pic[i*128+loop]);}
}
_NOP();
}


相关文档