接上一篇文章OLED显示屏VGY12864L-S003产品的应用1四,与8051单片机简单设计图 (HGS1286418 以8080时序为例五,OLED显示屏 HGS128418 示例程序/*OLED模块HGS1286418典型应用示例程序*/ void uDelay(unsigned char l){ while(l--);}void delay(unsigned char n){unsigned char i,j,k;
for(k=0;k<n;k++) { for(i=0;i<131;i++) { for(j=0;j<15;j++) { uDelay(80); } } }void Writecom(uchar com){ DC=0; CS=0;
_WR=0; _nop_(); lcddata=com; _nop_(); _WR=1; _nop_(); _nop_(); CS=1; DC=1;}void Writedata(uchar dat){ DC=1; CS=0; _WR=0; _nop_(); lcddata=dat; _nop_(); _WR=1; _nop_(); CS=1; DC=1;
}uchar Readcom(){ uchar com; DC=0; CS=0; lcddata=0xff; _RD=0; _nop_(); _nop_(); com=lcddata; _RD=1; _nop_(); _nop_(); CS=1; DC=1; return com;}uchar Readdata(){ uchar dat; DC=1; CS=0; lcddata=0xff; _RD=0; _nop_(); _nop_(); dat= lcddata; _RD=1; _nop_(); _nop_(); CS=1; DC=1; return dat;}
void startline(uchar line){ line=line&0x3f;///定义低5位 line=line|0x40;///**行或 Writecom(line);}
void startpage(uchar page){ page=page&0x0f;///定义低4位 page=page|0xb0;///**页 Writecom(page);}/*The beginning of seg is 0x1000*/void startcolumn(uchar column){ uchar temp; temp=column; column=column&0x0f; ///定义A3-A0; column=column|0x00; Writecom(column); column=temp/16; ////////////// >>4 column=column&0x0f; ///定义A7-A4; column=column|0x10;Writecom(column);}
void clear(uchar m){uchar i,j;for(i=0;i<8;i++){Writecom(0xb0+i); //startpage(i)Writecom(0x00);Writecom(0x10); //startcolumn(0)for(j=0;j<128;j++){Writedata(m);}}}
void reset(uchar m){unsigned char i,j; for(i=0;i<8;i++) { startpage(i); for(j=0;j<128;j++) { startcolumn(j); if(j%2==0)Writedata(m); Writedata(~m); } } }
void INT(){RES=0;uDelay(20);RES=1;uDelay(20);
Writecom(0xae);/////////关显示Writecom(0xd5);/////////设定显示频率Writecom(0xf1);
Writecom(0xa8);/////设定占空比 1/64Writecom(0x3f);
Writecom(0xd3);////////设定显示范围 COMWritecom(0x00);
Writecom(0x40);///////起始行Writecom(0x00);
Writecom(0xad);/////内部dc-dcWritecom(0x8e);
Writecom(0x20);/////接口方式 页方式Writecom(0x02);
Writecom(0xa0);/////seg方向 0-132Writecom(0xc8);/////com方向 63-0
Writecom(0xda);////Set COM Pins Hardware ConfigurationWritecom(0x12);///
Writecom(0x81);////////////对比度调节Writecom(0xbf);/////////////对比度为中
Writecom(0xdb);////////////倍压调节Writecom(0x34);///////////
Writecom(0xa4);////////////Entire Display ONWritecom(0xa6);////////////Normal displayclear(0x00);Writecom(0xaf);////////////开显示}}