/*****************************************************************************
/*****************************************************************************
*
* Program for writing to Newhaven Display's 1x16 Character LCD with the ST7066U Controller.
* This code is written for the Arduino Uno R3 using 8-bit or 4-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 (c) 2024, Newhaven Display International
*
* This code is provided as an example only and is not guaranteed 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.
*
*****************************************************************************/
/****************************************************
* PINOUT: Arduino Uno -> Character OLED *
UNO LCD
--------------------------
GND 1 (VSS)
5V 2 (VDD)
* 3 (V0)
13 4 (RS)
12 5 (R/W)
11 6 (E)
0 7 (DB0)
1 8 (DB1)
2 9 (DB2)
3 10 (DB3)
4 11 (DB4)
5 12 (DB5)
6 13 (DB6)
7 14 (DB7)
5V 15 (LED+)
GROUND 16 (LED-)
*Contrast potentiometer: refer to specification for wiring diagram
*****************************************************************************/
#define RS 8
#define RW 9
#define EN 10
/****************************************************
* Text Strings *
****************************************************/
char const _text1[] = ("NEWHAVEN DISPLAY");
char const _text2[] = ("INTERNATIONAL ");
/****************************************************
* Display Write Functions *
****************************************************/
void command(uint8_t command){ // Send a command byte to the display.
digitalWrite(RS, LOW); // Register Select: Command
digitalWrite(RW, LOW); // Read/Write Select: Write
putByte(command);
}
void data(uint8_t data){ //Send a data byte to the display.
digitalWrite(RS, HIGH); // Register Select: Data
digitalWrite(RW, LOW); // Read/Write Select: Write
putByte(data);
}
void putByte(uint8_t data){ //Clock a byte of data on the 4-bit parallel bus.
putNybble(data);
latch();
// Un-Comment for 4-Bit Interface
// data = data << 4; // Shift Lower nybble of the byte to the upper nybble.
// putNybble(data);
// latch();
}
void putNybble(uint8_t data){ //put data on parallel bus.
PORTD = data;
}
void latch(){ //Toggle enable signal to latch data.
digitalWrite(EN, HIGH);
delay(1);
digitalWrite(EN, LOW);
delay(20);
}
void Set_4Bit(){ // put 0x20 on the output port (NEEDED TO SET 4-bit INTERFACE)
putNybble(0x20);
latch();
}
/****************************************************
* Display Commands *
****************************************************/
void clearScreen(){ //Clear the display.
command(0x01);
delay(2);
}
void returnHome(){ //Return the cursor to the home position.
command(0x02);
delay(1);
}
void wake(char i){ // Writes Wake command to display for specified delay.
command(0x30);
delay(i);
}
/****************************************************
* Display Functions *
****************************************************/
void disp(){ //Write "NEWHAVEN DISPLAY" on the display.
clearScreen();
returnHome(); // For 1st 16 characters
for (unsigned int i=0; i<16; i++)
data(_text1[i]);
delay(1000);
returnHome();
for (unsigned int i=0; i<16; i++)
data(_text2[i]);
returnHome();
}
/****************************************************
* Display Setup *
****************************************************/
void initLCD(){ //initialize connected lcd.
DDRD = 0xFF; //first pins port d as output
DDRB = 0x07;
digitalWrite(EN, LOW);
delay(100); //wait > 15 msec after power is applied
wake(30); // command 0x30 = Wake up; Must wait 5ms, busy flag not available
wake(10); // command 0x30 = Wake up #2; Must wait 160us, busy flag not available
wake(10); // command 0x30 = Wake up #3; Must wait 160us, busy flag not available
//Un-Comment for Interface selection: Default 8-Bit
//8-Bit Interface
command(0x38); //8-Bit / 2 Line
command(0x0D); // Display ON; Cursor OFF; Blinking ON;
command(0x06); // Entry Mode set
// 4-Bit Interface update function: putByte (line 85)
// Set_4Bit();
// command(0x20); //4-Bit/ 1 Line
// command(0x0D); // Display ON; Cursor OFF; Blinking ON;
// command(0x06); // Entry Mode set
}
void setup(){
initLCD();
disp();
}
void loop(){
}