Arduino Code example for Newhaven LCD graphic display NHD-19232WG-BTMI-V#T.
//--------------------------------------------------------- /* / Program for writing to NHD-19232WG-BTMI-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! * Copyright (c) 2023, 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. */ //--------------------------------------------------------- /**************************************************** * 192x32 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 /**************************************************** * 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, 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, 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, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFF, 0xF7, 0x60, 0xF9, 0xC6, 0x71, 0x98, 0x38, 0x70, 0xC7, 0xE3, 0x98, 0x03, 0xF0, 0x61, 0xFC, 0x7E, 0x18, 0x07, 0x0C, 0x30, 0x00, 0x00, 0x7F, 0xFF, 0xF7, 0x61, 0xF8, 0xCF, 0x61, 0x98, 0x3C, 0x30, 0xCF, 0xE3, 0xD8, 0x03, 0xF8, 0x63, 0xFC, 0x7F, 0x18, 0x0F, 0x0E, 0x70, 0x00, 0x00, 0x7F, 0x00, 0x07, 0x63, 0x80, 0xCF, 0x61, 0x98, 0x2C, 0x31, 0x8C, 0x03, 0xD8, 0x03, 0x1C, 0x63, 0x00, 0x63, 0x18, 0x0D, 0x86, 0x60, 0x00, 0x00, 0x3E, 0x1F, 0xF7, 0x63, 0xF8, 0xED, 0x61, 0xF8, 0x66, 0x19, 0x8F, 0xE3, 0x58, 0x03, 0x0C, 0x63, 0xF8, 0x63, 0x18, 0x1D, 0x83, 0xC0, 0x00, 0x00, 0x1E, 0x3F, 0xF7, 0xE3, 0xF8, 0x69, 0xE1, 0xF8, 0x66, 0x19, 0x8F, 0xE3, 0x78, 0x03, 0x0C, 0x63, 0xF8, 0x7F, 0x18, 0x18, 0xC1, 0x80, 0x00, 0x1E, 0x00, 0xF0, 0x06, 0xE1, 0x80, 0x79, 0xC1, 0x98, 0xFF, 0x0F, 0x0C, 0x03, 0x38, 0x03, 0x0C, 0x60, 0x1C, 0x7E, 0x18, 0x1F, 0xE1, 0x80, 0x00, 0x3F, 0x01, 0xE0, 0x06, 0xE1, 0xF8, 0x79, 0xC1, 0x98, 0xC3, 0x0F, 0x0F, 0xE3, 0x38, 0x03, 0xFC, 0x63, 0xFC, 0x60, 0x18, 0x3F, 0xE1, 0x80, 0x00, 0x3F, 0xFF, 0x1F, 0xF6, 0x60, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xF0, 0x63, 0xF0, 0x60, 0x1F, 0xB0, 0x61, 0x80, 0x00, 0x3F, 0xFE, 0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x1E, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xC0, 0x01, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xC0, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 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, 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<24;x++) { data(*LCD_String); LCD_String++; delay(1); } } } 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<24;x++) { data(0xFF); delay(1); } } } //void Text_String() //{ // command(0x3A); //RE = 0 (Basic Instruction) // command(0x93); //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<24;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(10); } /***************************************************** * 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 = 0x37; // Port B first 3 pins as output Initialization_Sequence(); delay(10); //Text_String(); //delay(1000); Fill(); delay(500); Clear(); delay(500); disp(NHD_W); delay(500); //Clear(); } /***************************************************** * Loop Function, to run repeatedly * *****************************************************/ void loop() { // put your main code here, to run repeatedly: }