Arduino Code example for Newhaven COG LCD display NHD-C0220BA-FSW-FTW.
/***************************************************************************** * Program for writing to Newhaven Display NHD-C0220BA-FSW-FTW or NHD-C0220BA-FSW-FTW-3V3 with ST7036 controller. * This code is written for the Arduino Uno in 6800 Mode 8-Bit Parallel Interface * * Newhaven Display invests time and resources providing this open source code, * Please support Newhaven Display by purchasing products from Newhaven Display! * * Copyright: M Arce (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. *****************************************************************************/ /* COG UNO */ #define RS 10 #define RW 11 #define E 12 #define DB0 2 #define DB1 3 #define DB2 4 #define DB3 5 #define DB4 6 #define DB5 7 #define DB6 8 #define DB7 9 char const text1[] = ("NHD-C0220BA-FSW-FTW."); char const text2[] = ("Newhaven Display COG"); void write_8bit(unsigned char c){ /*This function outputs data to the LCD*/ for(int i=7;i>=0;i--){ //Cycles through the bits. if(bitRead(c,i)==0){//if the bit is '0' then set output as 0 digitalWrite(i+2,LOW); } else { //if the bit is '1' then set output as 1 digitalWrite(i+2,HIGH); } delayMicroseconds(2000); } delayMicroseconds(2000); } void command(unsigned char c){ //To send commands write_8bit(c); digitalWrite(RS,LOW); // RS set to LOW for command delayMicroseconds(2000); // Delay by 2000 Microseconds digitalWrite(RW,LOW); // RW set to LOW for writing digitalWrite(E, HIGH); // E set HIGH delayMicroseconds(1000); // Delay by 1000 Microseconds digitalWrite(E,LOW); // E set to LOW for latching delayMicroseconds(1000); // Delay by 1000 Microseconds } void data(unsigned char d){ //To send data write_8bit(d); digitalWrite(RS,HIGH); // RS set to HIGH for data delayMicroseconds(2000); // Delay by 2000 Microseconds digitalWrite(RW,LOW); // RW set to LOW for writing digitalWrite(E, HIGH); // E set HIGH delayMicroseconds(1000); // Delay by 1000 Microseconds digitalWrite(E,LOW); // E set to LOW for latching delayMicroseconds(1000); // Delay by 1000 Microseconds } void Write_Text(void){ command(0x01); // Clear Screen (returns home) for(int i=0; i<20; i++){ data(text2[i]); // Write the characters from text2 } command(0xC0); // Move CGRAM address to 40(second line) for(int i=0; i<20; i++){ data(text1[i]); // Write the characters from text1 } } void Display_all_Characters(void){ /*Cycle through the whole font table.*/ for (int i=0; i<260;i++){ data(i); if(i==20){ command(0xc0); data(i); } if(i==40){ command(0x80); data(i); } if(i==60){ command(0xc0); data(i); } if(i==80){ command(0x80); data(i); } if(i==100){ command(0xc0); data(i); } if(i==120){ command(0x80); data(i); } if(i==140){ command(0xc0); data(i); } if(i==160){ command(0x80); data(i); } if(i==180){ command(0xc0); data(i); } if(i==200){ command(0x80); data(i); } if(i==220){ command(0xc0); data(i); } if(i==240){ command(0x80); data(i); } delay(100); } } void Init_Ports(){ /*Set the following as output*/ pinMode(RS,OUTPUT); pinMode(RW,OUTPUT); pinMode(E,OUTPUT); pinMode(DB0,OUTPUT); pinMode(DB1,OUTPUT); pinMode(DB2,OUTPUT); pinMode(DB3,OUTPUT); pinMode(DB4,OUTPUT); pinMode(DB5,OUTPUT); pinMode(DB6,OUTPUT); pinMode(DB7,OUTPUT); } void Init_LCD() { /*Initialize the display*/ command(0x39); // Function Set command(0x14); // Bias Set command(0x78); // Constrast Set command(0x5E); // Power/Icon/Constrast Control command(0x6A); // Follower Control command(0x0C); // Display ON/OFF Control command(0x01); // Clear Display } void setup(){ Init_Ports(); // Call to set the ports as Output Init_LCD(); // Call to initialize the display delay(2); // Wait for 2 Miliseconds } void loop(){ Write_Text(); // Write text1 and text2 to the LCD delay(2000); // Delay for 2 seconds command(0x01); // Clear Screen Display_all_Characters(); // Display all characters delay(2000); // Delay for 2 seconds }