Skip to content

OLED Display on SPI

December 15, 2017

IMG_0345
This is definitely a work in progress but I always love to see the Cosmac Elf starship.

The display is SPI and addressed similarly to the Nokia cellphone displays which I have played with before. The dimensions are different (128X64 vs 84*96) bu the bytes are laid out the same way so i was able to use the guts of the code for the LCD to drive the oled.

I was inspired to do it by Al Williams and Oscar Vermeulen’s UNO1802 which emulates an 1802 on an arduino uno and mimics the pixie display on the OLED. Their code is actually quite a bit more spohisticated than mine because it translates on the fly from the pixie display which wants 64 consecutive bits for each scan line to the oled which wants 128 BYTES each of which covers 8 scan lines. I may try to duplicate this because it would let me use more pixie code but it would probably be slow and i had already done the transposition once for the Nokia LCD.

The gallery below shows the OLED hooked up to an arduino running an adafruit demo and progressively rewired onto the olduino with, eventually, a correct display.

The code block below contains the display program and the header file with the starship graphic. All of the SPI code and most of the LCD-specific stuff is reused except for the initialization which has different command bytes.

/*
	Display the COSMAC starship on an OLED display using hardware SPI shift register
	Dec 14 2017 - adapting for OLED display/SSD1306 controller
*/
#include <olduino.h>
#include <nstdlib.h>
#include <cpu1802spd4port7.h>
#include <hspi2.h>
#include <hspi2Lcd.h>
#include "oledship.h"
//#include "santaw2.h"
#define LcdSS 4
void oledInitialise(void)
{
  	unsigned char initbytes[32]={ //cribbed from adafruit library
		0xAE,0xD5,0x80,0xA8,0x3F,0xD3,0x00,0x40,
		0x8D,0x14,0x20,0x00,0xA1,0xC8,0xDA,0x12,
		0x81,0xCF,0xD9,0xF1,0xDB,0x40,0xA4,0xA6,
		0x2E,0xAF,0x21,0x00,0x7F,0x22,0x00,0x07};
	unsigned int i;

  	digitalWrite(lcdreset,LOW); //reset the LCD
  	digitalWrite(lcdreset,HIGH); //release the reset
  	digitalWrite(LcdSS,LOW);	//select the LCD
  	for (i=0;i<32;i++){
		LcdWrite(LCD_C, initbytes[i]); //send initialization
	}

}
void oledSet(unsigned char what) //set the whole LCD to a bit pattern
{
  unsigned int index;
  for (index = 0; index <1024; index++)
  {
    LcdWrite(LCD_D, what);
  }
}
void main()
{
 	printf("oledmain.c here\n");
 	PIN4=0;
 	digitalWrite(LcdSS,HIGH);
 	setqon();
 	digitalWrite(LcdSS,LOW);
	oledInitialise();
	setqoff();
	//oledSet(0xf0);
	digitalWrite(lcdcmd,LCD_D); //set data
	spiSendN(spibytes,128*8);
}
#include <hspi2.c>
#include <hspi2Lcd.c>
#include <olduino.c>
#include <nstdlib.c>

//oledship.h header file follows
//each byte fills 1 horizontal position in 8 display lines
static unsigned char spibytes[]={
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,

0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,

0,0,0,0,0,0,0,0,0,0,
0x00,0x1F,0x11,0x11,0x1B,0x00,0x1F,0x11,0x11,0x1F,0x00,0x17,0x15,0x15,0x1D,0x00,
0x1F,0x03,0x04,0x03,0x1F,0x00,0x1F,0x05,0x05,0x1F,0x00,0x1F,0x11,0x11,0x1B,0x00,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x80,0x80,0x80,0x80,0x80,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,

0,0,0,0,0,0,0,0,0,0,
0x00,0x1C,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x16,0x22,0x22,0x6A,0x6B,0x6B,0x6A,
0x22,0x22,0x16,0x34,0x54,0x94,0x94,0x94,0x94,0x34,0x54,0x88,0x00,0x00,0x00,0x03,
0x04,0x04,0x04,0x04,0x04,0xFC,0x00,0x00,0xFC,0x04,0x04,0x04,0x04,0x04,0x04,0x04,
0x04,0xC4,0x44,0x44,0x44,0x04,0xC4,0x04,0x04,0x04,0x04,0xC4,0x44,0x44,0x46,0x01,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,

0,0,0,0,0,0,0,0,0,0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x04,0x0e,0x1F,0x11,0x20,0x24,0x24,0x24,0x25,0x25,0x25,0x15,0x11,0x11,0x11,
0x11,0x11,0x09,0x09,0x09,0x09,0x08,0x08,0x09,0x09,0x09,0x0f,0x00,0x00,0x00,0x00,
0x00,0x07,0x05,0x05,0x04,0x00,0x07,0x04,0x04,0x04,0x00,0x07,0x01,0x01,0x00,0x00,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,

0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,


0x0E,0x11,0x11,0x0E,0x00,0x1F,0x10,0x10,0x10,0x00,0x1f,0x11,0x11,0x0E,0x00, //O L D
0x0F,0x10,0x10,0x0F,0x00,0x00,0X1F,0x00,0X00,0x1F,0x04,0x08,0x1F,0x00, //U I N
0x1F,0x11,0x11,0x1F,0x00,0X00,0X00,0X00,0X00,0X00,0x1F,0x15,0x15,0x11,0x00,	//O sp E
0x1f,0x11,0x11,0x0E,0x00, 0x00,0x1F,0x00,0X00, 0x01,0x1F,0x01,0x00,	//D I T
0x00,0x1F,0x00,0X00,0x0E,0x11,0x11,0x0E,0x00,0x1F,0x04,0x08,0x1F,0x00, //I O N
0,0X17,0,0, //!
0,0,0,0,0,0,0,0,0,0, //10 empty bits
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,
};

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: