联系人:刘小姐,李小姐,王小姐
Tel:010-62000662,62051209
Fax:010-82036512
Mobile:13701081790
Email:bjqingda@126.com
Web:www.tsingtek.com
QQ:453189731
微信:13701081790
地址:北京市海淀区花园东路32号花园公寓A402室OLED显示屏与8051单片机的接口设计2
OLED显示屏与8051单片机的接口设计2
接上一篇文章
4,OLED显示屏 HGS128641主要指令集
更详细的指令集请联系清达光电 索取 010-62000662 13701081790
5,OLED显示屏 与8051单片机典型应用
6, OLED显示屏 HGS128641 典型应用程序
/******************************************************************
延时子程序
*****************************************************************/
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<120;i++)
{_nop_();}}
}
void delay100ms(unsigned char n)
{
unsigned char i,j,k;
for(k=0;k<n;k++)
{
for(i=0;i<100;i++)
{delay(1);}}
}
#ifdef I80
/*********************************************************************
写入指令和数据
************************************************************************/
void WriteCommand(unsigned char Data)
{
DC=0;
CS=0;
xData=Data;
WR=0;
_nop_();
_nop_();
WR=1;
_nop_();
_nop_();
CS=1;
DC=1;
}
void WriteData(unsigned char Data)
{
DC=1;
CS=0;
xData=Data;
WR=0;
_nop_();
_nop_();
WR=1;
_nop_();
_nop_();
CS=1;
DC=1;
}
#endif
/*****************************************************************
OLED初始化
*****************************************************************/
void oled_init()
{
_nop_();
RES=0; //oled reset
_nop_(); _nop_();
RES=1;
_nop_(); _nop_();
/**********************************************************
// OLED HGS128646 Initialization Command
********************************************************/
// Column Address
WriteCommand(0x15); /* Set Column Address */
WriteCommand(0x00); /* Start = 0 */
WriteCommand(0x3F); /* End = 127 */
// Row Address
WriteCommand(0x75); /* Set Row Address */
WriteCommand(0x0c); /* Start = 0 */
WriteCommand(0x4b); /* End = 63 */
// Contrast Control
WriteCommand(0x81); /* Set Contrast Control */
WriteCommand(0x7f); /* 0 ~ 127 */
// Current Range
WriteCommand(0x86); /* Set Current Range84h:Quarter, 85h:Half,86h:Full*/
// Re-map
WriteCommand(0xA0); /* Set Re-map */
WriteCommand(0x52); /* [0]:MX, [1]:Nibble, [2]:H/Vaddress [4]:MY, [6]:Com Split Odd/Even "1000010"*/
// Display Start Line
WriteCommand(0xA1); /* Set Display Start Line */
WriteCommand(0x0c); /* Top */
// Display Offset
WriteCommand(0xA2); /* Set Display Offset */
WriteCommand(0x4c); /* No offset */
// Display Mode
WriteCommand(0xA4); /* Set DisplaMode,A4:Normal,A5:All ON, A6: All OFF,A7:Inverse */
// Multiplex Ratio
WriteCommand(0xA8); /* Set Multiplex Ratio */
WriteCommand(0x3F); /* [6:0]16~128, 64 rows=3Fh*/
// Phase Length
WriteCommand(0xB1); /* Set Phase Length */
// WriteCommand(0x22); /* [3:0]:Phase 1 period of 1~16clocks */
WriteCommand(0x02); /* [7:4]:Phase 2 period of 1~16clocks /* POR = 0111 0100 */
// Row Period
WriteCommand(0xB2); /* Set Row Period */
WriteCommand(0x46); /* [7:0]:18~255,K=P1+P2+GS15 (POR:4+7+29)*/
// Display Clock Divide
WriteCommand(0xB3); /* Set Clock Divide */
WriteCommand(0x41); /* [3:0]:1~16, [7:4]:0~16 */
/* POR = 0000 0001 */
// VSL
WriteCommand(0xBF); /* Set VSL */
WriteCommand(0x0D); /* [3:0]:VSL */
// CCOMH
WriteCommand(0xBE); /* Set VCOMH */
WriteCommand(0x00); /* [7:0]:VCOMH */
// VP
WriteCommand(0xBC); /* Set VP */
WriteCommand(0x0B); /* [7:0]:VP */
// Gamma
WriteCommand(0xB8); /* Set Gamma with next 8 bytes*/
WriteCommand(0x01); /* L1[2:1] */
WriteCommand(0x11); /* L3[6:4], L2[2:0] 0001 0001*/
WriteCommand(0x22); /* L5[6:4], L4[2:0] 0010 0010*/
WriteCommand(0x32); /* L7[6:4], L6[2:0] 0011 1011*/
WriteCommand(0x43); /* L9[6:4], L8[2:0] 0100 0100*/
WriteCommand(0x54); /* LB[6:4], LA[2:0] 0101 0101*/
WriteCommand(0x65); /* LD[6:4], LC[2:0] 0110 0110*/
WriteCommand(0x76); /* LF[6:4], LE[2:0] 1000 0111*/
// Set DC-DC
WriteCommand(0xAD); /* Set DC-DC */
WriteCommand(0x02); /* 03=ON, 02=Off */
all_screen(0x00);
// Display ON/OFF
WriteCommand(0xAF); /* AF=ON, AE=Sleep Mode */
}