////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /********************************************************************************************************************/ // NHD_SlimOLED2x16.ino // // Program for writing to Newhaven Display 2 Line x 16 Character Slim OLED display module with US2066 controller. // // This code is written for the Arduino Mega 2560. // // // // (c)2014 Michael LaVine - Newhaven Display International, Inc. // // // // This program is free software; you can redistribute it and/or modify // // it under the terms of the GNU General Public License as published by // // the Free Software Foundation; either version 2 of the License, or // // (at your option) any later version. // // // // This program is distributed in the hope that it will be useful, // // but WITHOUT ANY WARRANTY; without even the implied warranty of // // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // // GNU General Public License for more details. // /********************************************************************************************************************/ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #define DC 30 // D/C signal connected to digital pin 30 of Arduino Mega #define E 31 // E signal connected to digital pin 31 of Arduino Mega #define CS 32 // /CS signal connected to digital pin 32 of Arduino Mega #define RES 33 // /RES signal connected to digital pin 33 of Arduino Mega #define BS0 34 // BS0 signal connected to digital pin 34 of Arduino Mega #define BS1 35 // BS1 signal connected to digital pin 35 of Arduino Mega #define BS2 36 // BS2 signal connected to digital pin 36 of Arduino Mega // REGVDD (pin 3) is tied HIGH (5.0V) for 5V operation // R/W signal tied LOW (always write) // The 8-bit data bus is connected to PORTA[7..0] of the Arduino Due // DB0 ---> digital pin 22 // DB1 ---> digital pin 23 // DB2 ---> digital pin 24 // DB3 ---> digital pin 25 // DB4 ---> digital pin 26 // DB5 ---> digital pin 27 // DB6 ---> digital pin 28 // DB7 ---> digital pin 29 unsigned char text1[] = {"Newhaven Display"}; unsigned char text2[] = {" 2x16 Slim OLED "}; unsigned char text3[] = {"0123456789:;<=>?"}; unsigned char text4[] = {"ABCDEFGHabcdefgh"}; void command(unsigned char c) { digitalWrite(CS, LOW); // /CS = LOW PORTA = c; // put data on Arduino Mega PORTA[7..0] digitalWrite(DC, LOW); // D/C = LOW digitalWrite(E, HIGH); // E = HIGH delayMicroseconds(10); digitalWrite(E, LOW); // E = LOW digitalWrite(CS, HIGH); // /CS = HIGH } void data(unsigned char d) { digitalWrite(CS, LOW); // /CS = LOW PORTA = d; // put data on Arduino Mega PORTA[7..0] digitalWrite(DC, HIGH); // D/C = HIGH digitalWrite(E, HIGH); // E = HIGH delayMicroseconds(10); digitalWrite(E, LOW); // E = LOW digitalWrite(CS, HIGH); // /CS = HIGH } void disp() { int i; command(0x01); // clear display and set DDRAM address to line 1 position 1 delay(2); // 2ms delay (required after clear display command) for(i=0;i<16;i++) { data(text1[i]); } command(0xA0); // set DDRAM address to line 2 position 1 for(i=0;i<16;i++) { data(text2[i]); } delay(2000); command(0x01); // clear display and set DDRAM address to line 1 position 1 delay(2); // 2ms delay (required after clear display command) for (i=0;i<16;i++) { data(text3[i]); } command(0xA0); // set DDRAM address to line 2 position 1 for (i=0;i<16;i++) { data(text4[i]); } } void setup() // runs once at power on { DDRA = 0xFF; // set PORTA as output PORTA = 0x00; // set PORTA as LOW DDRC = 0xFF; // set PORTC as output PORTC = 0x00; // set PORTC as LOW digitalWrite(BS2, HIGH); // BS2 = HIGH (8-bit parallel 6800 mode) digitalWrite(RES, HIGH); // hold reset signal HIGH for operation delay(10); command(0x2A); // function set (extended command set) command(0x71); // function selection A, disable internal Vdd regulator data(0x00); command(0x28); // function set (fundamental command set) command(0x08); // display off, cursor off, blink off command(0x2A); // function set (extended command set) command(0x79); // OLED command set enabled command(0xD5); // set display clock divide ratio/oscillator frequency command(0x70); // set display clock divide ratio/oscillator frequency command(0x78); // OLED command set disabled command(0x09); // extended function set (4-lines) command(0x06); // COM SEG direction command(0x72); // function selection B, disable internal Vdd regualtor data(0x04); // ROM CGRAM selection command(0x2A); // function set (extended command set) command(0x79); // OLED command set enabled command(0xDA); // set SEG pins hardware configuration command(0x10); // set SEG pins hardware configuration command(0xDC); // function selection C command(0x00); // function selection C command(0x81); // set contrast control command(0xFF); // set contrast control command(0xD9); // set phase length command(0xF1); // set phase length command(0xDB); // set VCOMH deselect level command(0x40); // set VCOMH deselect level command(0x78); // OLED command set disabled command(0x28); // function set (fundamental command set) command(0x01); // clear display command(0x80); // set DDRAM address to 0x00 command(0x0C); // display ON } void loop() // main loop { disp(); delay(2000); }