Author Topic: NHD-0216KZW-AG5 - serial interface - initialization  (Read 498 times)

bw

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
    • View Profile
NHD-0216KZW-AG5 - serial interface - initialization
« on: January 23, 2018, 10:06:07 AM »
Hello
I use mentioned above OLED 2x16 display with serial interface.
Everything is almost ok, but i cannot find initialization procedure for serial interface.
For now i tried with 8bit parallel initialization sequence, but sometimes my oled doesn't start. Is that timing problem or something else?

What is proper way of init this display in serial mode? This is not specified in datasheet.

Saurabh_B

  • Administrator
  • Hero Member
  • *****
  • Posts: 377
  • Karma: 10
    • View Profile
Re: NHD-0216KZW-AG5 - serial interface - initialization
« Reply #1 on: January 30, 2018, 03:46:53 PM »
Hello,

You can find an example on how to use the Serial OLED below:
Code: [Select]
sbit SCL = P3^4;
sbit SDOUT = P1^0;
sbit SDIN = P1^1;
sbit C_S = P3^3;

void delay(unsigned int n) //Delay subroutine
{
unsigned int i,j;
for (i=0;i<n;i++)
  for (j=0;j<250;j++)
  {;}
}
 

void WriteCommand(unsigned char ins)
{
unsigned char i;
C_S=0;
SCL = 0;
SDOUT = 0; //RS = 0 (Command)
SCL = 1; //RS registered
SCL = 0;
SDOUT = 0; //RW = 0
SCL = 1; //RW registered
SCL = 0;

for (i=0x80;i;i>>=1)
{
if((ins&0x80)==0x80)
SDOUT = 1;
else
SDOUT = 0;
ins=(ins<<1);
SCL = 0;
SCL = 1;
SCL = 0;
}

    C_S=1;
}

void WriteDataInit()
{

C_S=0;
SCL = 0;
SDOUT = 1; //RS = 1 (Data)
SCL = 0; //RS registered
SCL = 1;
SCL = 0;
SDOUT = 0; //RW = 0
SCL = 1; //RS registered
SCL = 0;

}
void WriteData(unsigned char dat)
{
unsigned char i;
for (i=0x80;i;i>>=1)
{
if((dat&0x80)==0x80)
SDOUT = 1;
else
SDOUT = 0;
dat=(dat<<1);
SCL = 0;
SCL = 1;
SCL = 0;
}

}

void init()
{
WriteCommand(0x38);//function set
delay(30);
WriteCommand(0x06);//entry mode set
delay(30);
WriteCommand(0x02);//return home
delay(30);
WriteCommand(0x01);//clear display
delay(30);
WriteCommand(0x0c);//display on
delay(30);
WriteCommand(0x80);//line 1 character 1
delay(30);
}

void main()
{
char i=0x21, j;



init();

while(1)
{
C_S = 1;
WriteCommand(0x80); //Line 1

WriteDataInit();
//WriteDataInit() must only be executed once before starting to write data
//if WriteDataInit() is executed between writes, the display will recognize the two bits as data bits and not RS/RW bits. 
for(j=0; j<20; j++)
{
WriteData(i++);
delay(10);
}

C_S = 1;
//Pulling C_S High means write data is completed
//if next instruction to the display is data, must use WriteDataInit() first
//if write command is executed without pulling C_S high, it will recognize the following instruction on the bus as data regardless
WriteCommand(0xC0); //Line 2

WriteDataInit();
for(j=0; j<20; j++)
{
WriteData(i++);
delay(10);
}

C_S = 1;
WriteCommand(0x94); //Line 3

WriteDataInit();
for(j=0; j<20; j++)
{
WriteData(i++);
delay(10);
}


C_S = 1;
WriteCommand(0xD4); //Line 4

WriteDataInit();
for(j=0; j<20; j++)
{
WriteData(i++);
delay(10);
}

}
}

 

NHD‐0420CW‐AB3 I2C Interface

Started by andersonpdBoard OLEDs

Replies: 1
Views: 3623
Last post January 23, 2015, 10:00:06 AM
by Michael_L
NHD‐0420DZW‐AY5 SPI Interface

Started by vinaykBoard OLEDs

Replies: 0
Views: 2878
Last post October 26, 2015, 05:13:10 AM
by vinayk
NHD‐3.12‐25664UMB3 3 or 4 wire interface

Started by cliffgBoard OLEDs

Replies: 1
Views: 3300
Last post February 13, 2015, 04:43:21 PM
by Michael_L
NHD‐C12864A1Z‐FS(RGB)‐FBW‐HT1 Initialization

Started by BMohlmanBoard Graphic LCDs

Replies: 5
Views: 5296
Last post January 13, 2016, 07:44:16 AM
by Paul_B
NHD-2.4-240320CF-CTXI#-FT (ST7789S controller) and STM32F4 FSMC LCD Interface

Started by deshayesBoard TFTs

Replies: 1
Views: 3782
Last post March 17, 2016, 06:25:18 PM
by fahad