Arduino Code example for Newhaven LCD graphic display NHD-14432WG.
//---------------------------------------------------------
/*
/ Program for writing to NHD-14432WG-BTMI-V#T & NHD-14432WG-ATFH-V#T display series
/ with the ST7920-0C controller.
/ This code is written for the Arduino Uno R3 using 8-bit Parallel or Serial Interface
/
/ Newhaven Display invests time and resources providing this open source code,
/ Please support Newhaven Display by purchasing products from Newhaven Display!
Alee Shah Copyright (c) 2020, Newhaven Display International
This code is provided as an example only and without any warranty by Newhaven Display.
Newhaven Display accepts no responsibility for any issues resulting from its use.
The developer of the final application incorporating any parts of this
sample code is responsible for ensuring its safe and correct operation
and for any consequences resulting from its use.
See the GNU General Public License for more details.
Use Horizontal Orientation when converting BMP to hex code
to display custom image using LCD assistant.
*/
//---------------------------------------------------------
/****************************************************
* 144x32 Display Interface Selection *
*****************************************************
** Adjust to Desired Interface As Necessary **
****************************************************/
unsigned char mode = 1; // 0 = 8-bit parallel mode
// 1 = serial mode
/****************************************************
PINOUT: Arduino Uno -> Display
*****************************************************/
#define RS 8 //Register Select signal
#define RW 9 //Read/Write signal
#define E 10 //Enable signal
#define CS 11 //Chip Select signal
#define SDIN 12 //Serial In/Out signal
#define SCK 13 //Serial Clock signal
unsigned char mode = 1; // 0 = 8-bit parallel mode ; 1 = serial mode
/****************************************************
Hex Table for Image Pic
*****************************************************/
unsigned char NHD_W [] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 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01, 0xFF, 0xFC,
0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0xFC, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x78, 0xF8, 0x01, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFE, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xFE, 0x00, 0x0F, 0x00, 0x0F, 0xE0, 0xC1, 0xFE, 0x3F, 0x87, 0x00,
0x70, 0x61, 0x80, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFE, 0x00, 0x0F, 0xF0, 0xC3, 0xFE, 0x3F,
0xC7, 0x00, 0x70, 0x73, 0x80, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFC, 0x00, 0x0C, 0x38, 0xC3,
0x00, 0x30, 0xC7, 0x00, 0xD8, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x0C,
0x18, 0xC3, 0xFC, 0x30, 0xC7, 0x00, 0xD8, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00,
0x00, 0x0C, 0x18, 0xC3, 0xFC, 0x3F, 0xC7, 0x01, 0x8C, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0C, 0x18, 0xC0, 0x0E, 0x3F, 0x87, 0x01, 0xFC, 0x0C, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x38, 0xC0, 0x0E, 0x30, 0x07, 0x03, 0xFC, 0x0C, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xF0, 0xC3, 0xFE, 0x30, 0x07, 0xF3, 0x06, 0x0C,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xC0, 0xC1, 0xF8, 0x30, 0x03, 0xF3,
0x06, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
/****************************************************
Function Commands
*****************************************************/
//--------------------------------------------------------------------------
void command(unsigned char c)
{
unsigned char i, temp;
switch (mode)
{
case 0: PORTD = c;
digitalWrite(RS, LOW); // Command
digitalWrite(RW, LOW); // Write
digitalWrite(E, HIGH);
delay(1);
digitalWrite(E, LOW);
delay(1);
break;
case 1: digitalWrite(CS, HIGH);
temp = 0xF8;
//-=-=-=-=-=-=-=-=-=-=
// Start Byte -=
//-=-=-=-=-=-=-=-=-=-=
for (i=0;i<8;i++)
{
digitalWrite(SCK, LOW);
if ((temp&0x80)>>7==1)
{
digitalWrite(SDIN, HIGH);
}
else
{
digitalWrite(SDIN, LOW);
}
digitalWrite(SCK, HIGH);
temp = temp << 1;
}
//-=-=-=-=-=-=-=-=-=-=
// 1st Byte -=
//-=-=-=-=-=-=-=-=-=-=
for (i=0;i<4;i++)
{
digitalWrite(SCK, LOW);
if ((c&0x80)>>7==1)
{
digitalWrite(SDIN, HIGH);
}
else
{
digitalWrite(SDIN, LOW);
}
digitalWrite(SCK, HIGH);
c = c<<1;
}
for (i=0;i<4;i++)
{
digitalWrite(SCK, LOW);
digitalWrite(SDIN, LOW);
digitalWrite(SCK, HIGH);
}
//-=-=-=-=-=-=-=-=-=-=
// 2nd Byte -=
//-=-=-=-=-=-=-=-=-=-=
for (i=0;i<4;i++)
{
digitalWrite(SCK, LOW);
if ((c&0x80)>>7==1)
{
digitalWrite(SDIN, HIGH);
}
else
{
digitalWrite(SDIN, LOW);
}
digitalWrite(SCK, HIGH);
c = c<<1;
}
for (i=0;i<4;i++)
{
digitalWrite(SCK, LOW);
digitalWrite(SDIN, LOW);
digitalWrite(SCK, HIGH);
}
break;
}
}
//--------------------------------------------------------------------------
void data(unsigned char d)
{
unsigned char i, temp;
switch (mode)
{
case 0: PORTD = d;
digitalWrite(RS, HIGH); // Data
digitalWrite(RW, LOW); // Write
digitalWrite(E, HIGH);
delay(1);
digitalWrite(E, LOW);
delay(1);
break;
case 1: digitalWrite(CS, HIGH);
temp = 0xFA;
//-=-=-=-=-=-=-=-=-=-=
// Start Byte -=
//-=-=-=-=-=-=-=-=-=-=
for (i=0;i<8;i++)
{
digitalWrite(SCK, LOW);
if ((temp&0x80)>>7==1)
{
digitalWrite(SDIN, HIGH);
}
else
{
digitalWrite(SDIN, LOW);
}
digitalWrite(SCK, HIGH);
temp = temp << 1;
}
//-=-=-=-=-=-=-=-=-=-=
// 1st Byte -=
//-=-=-=-=-=-=-=-=-=-=
for (i = 0; i < 4; i++)
{
digitalWrite(SCK, LOW);
if((d&0x80)>>7==1)
{
digitalWrite(SDIN, HIGH);
}
else
{
digitalWrite(SDIN, LOW);
}
digitalWrite(SCK, HIGH);
d = d<<1;
}
for (i=0;i<4;i++)
{
digitalWrite(SCK, LOW);
digitalWrite(SDIN, LOW);
digitalWrite(SCK, HIGH);
}
//-=-=-=-=-=-=-=-=-=-=
// 2nd Byte -=
//-=-=-=-=-=-=-=-=-=-=
for(i=0;i<4;i++)
{
digitalWrite(SCK, LOW);
if((d&0x80)>>7==1)
{
digitalWrite(SDIN, HIGH);
}
else
{
digitalWrite(SDIN, LOW);
}
digitalWrite(SCK, HIGH);
d = d<<1;
}
for(i=0;i<4;i++)
{
digitalWrite(SCK, LOW);
digitalWrite(SDIN, LOW);
digitalWrite(SCK, HIGH);
}
break;
}
}
/****************************************************
Display Commands
*****************************************************/
void disp(unsigned char *LCD_String)
{
unsigned int x, y, page;
page = 0x80;
for (page=0x80;page<0xA0;page++)
{
command(0x3E);
command(page);
command(0x80);
for (x=0;x<18;x++)
{
data(*LCD_String);
LCD_String++;
delayMicroseconds(50);
}
}
}
void Fill()
{
unsigned int x, y, page;
page = 0x80;
for (page=0x80;page<0xA1;page++)
{
command(0x3E);
command(page);
command(0x80);
for (x=0;x<18;x++)
{
data(0xFF);
delayMicroseconds(50);
}
}
}
//void Text_String()
//{
// command(0x3A); //RE = 0 (Basic Instruction)
// command(0x90); //Set DDRAM Address
// data(0x48); //H
// data(0x45); //E
// data(0x4C); //L
// data(0x4C); //L
// data(0x4F); //O
// data(0x20); //Space
// data(0x20); //Space
// data(0x57); //W
// data(0x4F); //O
// data(0x52); //R
// data(0x4C); //L
// data(0x44); //D
//}
void Clear()
{
unsigned int x, y, page;
page = 0x80;
for (page=0x80;page<0xA1;page++)
{
command(0x3E);
command(page);
command(0x80);
for (x=0;x<18;x++)
{
data(0x00);
delayMicroseconds(50);
}
}
}
/****************************************************
Initialization For controller
*****************************************************/
void Initialization_Sequence()
{
command(0x38);
delay(2);
command(0x38);
delay(2);
command(0x0C);
delay(2);
command(0x01);
delay(2);
command(0x06);
delay(2);
command(0x02);
delay(100);
}
/*****************************************************
Setup Function, to run once
*****************************************************/
void setup() {
// put your setup code here, to run once:
DDRD = 0xFF; // First 8 pins of PORT D as output
DDRB = 0x3F; // Port B first 6 pins as output
Initialization_Sequence();
delay(10);
//Text_String();
//delay(1000);
Fill();
delay(500);
Clear();
delay(500);
disp(NHD_W);
delay(500);
}
/*****************************************************
Loop Function, to run repeatedly
*****************************************************/
void loop() {
// put your main code here, to run repeatedly:
}