/*
/ Program for writing to NHD-3.12-25664 OLED with SSD1322 controller with Serial Interface
/ This code is written for the Arduino Due using 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.
*/
//---------------------------------------------------------
#define OLED_DC 49 //Register Select signal
#define OLED_RESET 48 //Reset signal
#define OLED_CS 47 //Chip select signal
#define OLED_CLK 52 //Serial clock signal //PB1
#define OLED_MOSI 51 //Serial data signal //PB2
/****************************************************
* Hex Table for Image Pic *
*****************************************************/
unsigned char NHD_Logo [] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xFF, 0xEE, 0x60, 0xFC, 0x71, 0x8E, 0x31, 0x81, 0xC1, 0xC3,
0x8F, 0xE3, 0x8C, 0x00, 0xFE, 0x0C, 0x1F, 0xE3, 0xF8, 0x70, 0x07, 0x06, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xFF, 0xEE, 0x61, 0xFC, 0x73, 0xCC, 0x31, 0x81, 0xE0, 0xC3,
0x1F, 0xE3, 0xCC, 0x00, 0xFF, 0x0C, 0x3F, 0xE3, 0xFC, 0x70, 0x07, 0x07, 0x38, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xFC, 0x00, 0x0F, 0x61, 0x80, 0x33, 0xCC, 0x31, 0x81, 0x60, 0xC7,
0x18, 0x03, 0xCC, 0x00, 0xC3, 0x8C, 0x30, 0x03, 0x0C, 0x70, 0x0D, 0x83, 0x30, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xF8, 0x7F, 0xED, 0x61, 0xFC, 0x3B, 0x4C, 0x3F, 0x83, 0x30, 0x66,
0x1F, 0xE3, 0x6C, 0x00, 0xC1, 0x8C, 0x3F, 0xC3, 0x0C, 0x70, 0x0D, 0x81, 0xE0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, 0xED, 0xE1, 0xFC, 0x1A, 0x6C, 0x3F, 0x83, 0x30, 0x66,
0x1F, 0xE3, 0x6C, 0x00, 0xC1, 0x8C, 0x3F, 0xC3, 0xFC, 0x70, 0x18, 0xC0, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xF0, 0x03, 0xC0, 0x0D, 0xE1, 0x80, 0x1E, 0x78, 0x31, 0x87, 0xF0, 0x3C,
0x18, 0x03, 0x3C, 0x00, 0xC1, 0x8C, 0x00, 0xE3, 0xF8, 0x70, 0x1F, 0xC0, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03, 0xF8, 0x07, 0x80, 0x0C, 0xE1, 0xFC, 0x1E, 0x78, 0x31, 0x86, 0x18, 0x3C,
0x1F, 0xE3, 0x1C, 0x00, 0xC3, 0x8C, 0x00, 0xE3, 0x00, 0x70, 0x3F, 0xC0, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03, 0xF8, 0x0F, 0x3F, 0xEC, 0x60, 0xFC, 0x0E, 0x70, 0x31, 0x8E, 0x1C, 0x38,
0x0F, 0xE3, 0x1C, 0x00, 0xFF, 0x0C, 0x3F, 0xE3, 0x00, 0x7F, 0x30, 0x60, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03, 0xFF, 0xFC, 0x7F, 0xEC, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xFC, 0x0C, 0x1F, 0x83, 0x00, 0x3F, 0x30, 0x60, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03, 0xFF, 0xF8, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03, 0xF8, 0x01, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xF1, 0xF0, 0x03, 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, 0x01, 0xFC, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x03, 0xFC, 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, 0x00, 0x00, 0x00,
0x00, 0x00, 0x03, 0xFF, 0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x03, 0xFF, 0xFF, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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 data(unsigned char d) //Data Output Serial Interface
{
unsigned int n;
digitalWrite(OLED_CS, LOW);
digitalWrite(OLED_DC, HIGH);
for(n=0;n<8;n++){
if((d&0x80)==0x80)
digitalWrite(OLED_MOSI, HIGH);
else
digitalWrite(OLED_MOSI, LOW);
while(0);
d=(d<<1);
digitalWrite(OLED_CLK, LOW);
while(0);
digitalWrite(OLED_CLK, HIGH);
while(0);
digitalWrite(OLED_CLK, LOW);
}
digitalWrite(OLED_CS, HIGH);
}
void command(unsigned char d){ //Command Output Serial Interface
unsigned int n;
digitalWrite(OLED_CS, LOW);
digitalWrite(OLED_DC, LOW);
for(n=0;n<8;n++){
if((d&0x80)==0x80)
digitalWrite(OLED_MOSI, HIGH);
else
digitalWrite(OLED_MOSI, LOW);
while(0);
d=(d<<1);
digitalWrite(OLED_CLK, LOW);
while(0);
digitalWrite(OLED_CLK, HIGH);
while(0);
digitalWrite(OLED_CLK, LOW);
}
digitalWrite(OLED_CS, HIGH);
}
/****************************************************
* Display Commands *
*****************************************************/
void Set_Column_Address_25664(unsigned char a, unsigned char b)
{
command(0x15); // Set Column Address
data(a); // Default => 0x00
data(b); // Default => 0x77
}
//--------------------------------------------------------------------------
void Set_Write_RAM_25664()
{
command(0x5C); // Enable MCU to Write DATA RAM
}
//--------------------------------------------------------------------------
void Set_Read_RAM_25664()
{
command(0x5D); // Enable MCU to Write DATA RAM
}
//--------------------------------------------------------------------------
void Set_Row_Address_25664(unsigned char a, unsigned char b)
{
command(0x75); // Set Row Start and End Address
data(a); // Default => 0x00
data(b); // Default => 0x7F
}
//--------------------------------------------------------------------------
void Set_Remap_25664(unsigned char a, unsigned char b)
{
command(0xA0); // Set Remap
data(a); // Default => 0x00
data(b); // Default => 0x00
}
//--------------------------------------------------------------------------
void Set_Display_Start_Line_25664(unsigned char a)
{
command(0xA1); // Set Display RAM Display Start Line
data(a); // Default => 0x00
}
//--------------------------------------------------------------------------
void Set_Display_Offset_25664(unsigned char a)
{
command(0xA2); // Set Verticle Shift
data(a); // Default => 0x00
}
//--------------------------------------------------------------------------
void Display_Mode_25664(unsigned char a)
{
command(a); // 0xA4 => Entire Display OFF
// 0xA5 => Entire Display ON, all pixels Grayscale level 15
// 0xA6 => Normal Display (Default)
// 0xA7 => Inverse Display
}
//--------------------------------------------------------------------------
void Enable_Partial_Display_25664(unsigned char a, unsigned char b)
{
command(0xA8); // Turns ON partial mode
data(a); // Address of start row
data(b); // Address of end row.
}
//--------------------------------------------------------------------------
void Exit_Partial_Display_25664()
{
command(0xA9); // Exit Partial Display Mode
}
//--------------------------------------------------------------------------
void Function_Selection_25664(unsigned char a)
{
command(0xAB); // Function Selection
data(a); // Default => 0x01
}
//--------------------------------------------------------------------------
void Set_Sleep_Mode_25664(unsigned char a)
{
command(a); // 0xAE => Sleep Mode ON
// 0xAF => Sleep Mode OFF
}
//--------------------------------------------------------------------------
void Set_Phase_Length_25664(unsigned char a)
{
command(0xB1); // Set Phase Length
data(a); // Default => 0x97
}
//--------------------------------------------------------------------------
void Set_Display_Clock__Oscillator_Frequency_25664(unsigned char a)
{
command(0xB3); // Set Osc Frequency
data(a); //
}
//--------------------------------------------------------------------------
void Enable_External_VSL(unsigned char a, unsigned char b)
{
command(0xB4); // Enable External VSL
data(a); //
data(b); //
}
//--------------------------------------------------------------------------
void Set_GPIO_25664(unsigned char a)
{
command(0xB5); // Set GPIO
data(a); //
}
//--------------------------------------------------------------------------
void Set_Second_Precharge_Period_25664(unsigned char a)
{
command(0xB6); // Set Second Precharge Period
data(a); //
}
//--------------------------------------------------------------------------
void Default_Grayscale_Command_25664()
{
command(0xB9); // Sets Default Grayscale
}
//--------------------------------------------------------------------------
void Set_Precharge_Voltage_25664(unsigned char a)
{
command(0xBB); // Set Precharge Voltage Level
data(a); // Default => 0x17
}
//--------------------------------------------------------------------------
void Set_VCOMH_Voltage_25664(unsigned char a)
{
command(0xBE); // Set Second Precharge Period
data(a); // Default => 0x04
}
//--------------------------------------------------------------------------
void Set_Contrast_Control_25664(unsigned char a)
{
command(0xC1); // Set Contrast Control Level
data(a); // Default => 0x7F
}
//--------------------------------------------------------------------------
void Master_Contrast_Control_25664(unsigned char a)
{
command(0xC7); // Master Contrast Control
data(a); // Default => 0x0F
}
//--------------------------------------------------------------------------
void Set_Multiplex_Ratio_25664(unsigned char a)
{
command(0xCA); // Set MUX Ratio
data(a); // Default => 0x7F
}
//--------------------------------------------------------------------------
void Display_Enhancement_25664(unsigned char a)
{
command(0xD1); // Display Enhancement
data(a); //
data(0x20); //
}
//--------------------------------------------------------------------------
void Set_Command_Lock_25664(unsigned char a)
{
command(0xFD); // Set Lock/Unlock Commands
data(a); // Default => 0x12
}
//--------------------------------------------------------------------------
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Show Blank (Clear Screen)
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void ClearPixel_25664()
{
unsigned int i, j;
Set_Column_Address_25664(0x1C,0x5B);
Set_Row_Address_25664(0x00,0x3F);
Set_Write_RAM_25664();
for(i=0;i<64;i++) //Columns
{
for(j=0;j<128;j++) //Rows
{
data(0x00);
delayMicroseconds(100);
}
}
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Show Checkboard (Full Screen)
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void FillPixel_25664()
{
unsigned int i, j;
Set_Column_Address_25664(0x1C,0x5B); //1C & 5B = DISPLAY Start & End address.
Set_Row_Address_25664(0x00,0x3F);
Set_Write_RAM_25664();
for(i=0;i<64;i++) //Columns
{
for(j=0;j<64;j++) //Rows
{
data(0xFF);
delayMicroseconds(100);
data(0x00);
delayMicroseconds(100);
}
for(j=0;j<64;j++) //Rows
{
data(0x00);
delayMicroseconds(100);
data(0xFF);
delayMicroseconds(100);
}
}
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Show Image (Full Screen)
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// 4 bits (1 Nibble) = 1 Pixel
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void ImageDisplay_25664(unsigned char *image)
{
unsigned int i, j, buff;
Set_Remap_25664(0x14,0x11);
//Set_Remap_25664(0x06,0x11); // To Flip Orientation 180 Degrees
Set_Column_Address_25664(0x1C,0x5B);
Set_Row_Address_25664(0x00,0x3F);
Set_Write_RAM_25664();
for(i=0;i<64;i++) //Columns
{
for(j=0;j<32;j++) //Rows
{
buff = *image;
buff = ((buff >> 6) & 0x03);
if(buff == 0x03){data(0xFF);}
else if(buff == 0x02){data(0xF0);}
else if(buff == 0x01){data(0x0F);}
else data(0x00);
buff = *image;
buff = ((buff >> 4) & 0x03);
if(buff == 0x03){data(0xFF);}
else if(buff == 0x02){data(0xF0);}
else if(buff == 0x01){data(0x0F);}
else data(0x00);
buff = *image;
buff = ((buff >> 2) & 0x03);
if(buff == 0x03){data(0xFF);}
else if(buff == 0x02){data(0xF0);}
else if(buff == 0x01){data(0x0F);}
else data(0x00);
buff = *image;
buff = (buff & 0x03);
if(buff == 0x03){data(0xFF);}
else if(buff == 0x02){data(0xF0);}
else if(buff == 0x01){data(0x0F);}
else data(0x00);
image++;
}
}
}
/****************************************************
* Initialization For controller *
*****************************************************/
void OLED_Init_25664()
{
Set_Command_Lock_25664(0x12); // Unlock commands for OLED
Set_Display_Clock__Oscillator_Frequency_25664(0xD1); // Set Display Clock / Oscillator Frequency
Set_Multiplex_Ratio_25664(0x3F); // Set Multiplex Ratio
Set_Display_Offset_25664(0x00); // Set Display Offset
Set_Display_Start_Line_25664(0x00); // Set Display Start Line
Set_Remap_25664(0x14,0x11); // Set Remap. (A[1]) & (A[4]) can be adjusted to flip display orientation
Set_GPIO_25664(0x00); // Set GPIO
Function_Selection_25664(0x01); // Function Selection Enable internal VDD Regulator
Enable_External_VSL(0xA0,0xB5); // Enable External VSL
Set_Contrast_Control_25664(0x9F); // Set Contrast Control
Master_Contrast_Control_25664(0x0F); // Master Contrast Control
Default_Grayscale_Command_25664(); // Default Linear Grayscale Table
Set_Phase_Length_25664(0x74); // Set Phase Length
Display_Enhancement_25664(0xA2); // Display Enhancement
Set_Precharge_Voltage_25664(0x17); // Set Precharge Voltage
Set_Second_Precharge_Period_25664(0x08); // Set Second Precharge Period
Set_VCOMH_Voltage_25664(0x07); // Set VCOMH Voltage
Display_Mode_25664(0xA6); // Set Normal Display
Exit_Partial_Display_25664(); // Exit Partial Display Mode
Set_Sleep_Mode_25664(0xAF); // Sleep Mode OFF
}
/*****************************************************
* Setup Function, to run once *
*****************************************************/
void setup()
{
pinMode(OLED_CLK, OUTPUT);
pinMode(OLED_MOSI, OUTPUT);
pinMode(OLED_DC, OUTPUT);
pinMode(OLED_RESET, OUTPUT);
pinMode(OLED_CS, OUTPUT);
digitalWrite(OLED_RESET, LOW);
delay(300);
digitalWrite(OLED_RESET, HIGH);
delay(300);
OLED_Init_25664(); //Initialization Sequence
delay(100);
}
/*****************************************************
* Loop Function, to run repeatedly *
*****************************************************/
void loop() {
FillPixel_25664();
delay(500);
ClearPixel_25664();
delay(500);
ImageDisplay_25664(NHD_Logo);
delay(500);
ClearPixel_25664();
delay(500);
}