Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Adafruit_GFX_nano SPI_Demo_Nano
Diff: main.cpp
- Revision:
- 8:971ea27171dd
- Parent:
- 4:9decf12340fa
- Child:
- 9:bbe01bf9a3ef
diff -r 9decf12340fa -r 971ea27171dd main.cpp
--- a/main.cpp Wed Feb 25 22:01:10 2015 +0000
+++ b/main.cpp Wed Feb 25 23:27:42 2015 +0000
@@ -21,6 +21,27 @@
#include "spi_master.h"
#include "Adafruit_SSD1306.h"
+#define SSD1306_SETCONTRAST 0x81
+#define SSD1306_DISPLAYALLON_RESUME 0xA4
+#define SSD1306_DISPLAYALLON 0xA5
+#define SSD1306_NORMALDISPLAY 0xA6
+#define SSD1306_INVERTDISPLAY 0xA7
+#define SSD1306_DISPLAYOFF 0xAE
+#define SSD1306_DISPLAYON 0xAF
+#define SSD1306_SETDISPLAYOFFSET 0xD3
+#define SSD1306_SETCOMPINS 0xDA
+#define SSD1306_SETVCOMDETECT 0xDB
+#define SSD1306_SETDISPLAYCLOCKDIV 0xD5
+#define SSD1306_SETPRECHARGE 0xD9
+#define SSD1306_SETMULTIPLEX 0xA8
+#define SSD1306_SETLOWCOLUMN 0x00
+#define SSD1306_SETHIGHCOLUMN 0x10
+#define SSD1306_SETSTARTLINE 0x40
+#define SSD1306_MEMORYMODE 0x20
+#define SSD1306_COMSCANINC 0xC0
+#define SSD1306_COMSCANDEC 0xC8
+#define SSD1306_SEGREMAP 0xA0
+#define SSD1306_CHARGEPUMP 0x8D
//DigitalOut spi_cs(P0_10);
DigitalOut rst(A3);
DigitalOut dc(A4);
@@ -29,37 +50,74 @@
SPIClass SPI1(NRF_SPI1);
-Serial pc(USBTX, USBRX);
+
//Adafruit_SSD1306_nrf gOled1(&SPI1,A4,A3,D2);// SPI, DC, RST, CS
int main(void)
{
- pc.printf("SPI Demo Start \r\n");
+
led = 1; // off
- //SPI1.begin();
SPI1.begin(P0_8, P0_9, P0_11);//SCK, MOSI, MISO
- pc.printf("Step 1 \r\n");
+
+//Display initialisation
rst = 1;
// VDD (3.3V) goes high at start, lets just chill for a ms
wait_ms(1);
// bring reset low
- pc.printf("Step 2 \r\n");
- rst = 0;
+ rst = 0;
// wait 10ms
wait_ms(10);
// bring out of reset
rst = 1;
// turn on VCC (9V?)
- pc.printf("Step 3 \r\n");
- SPI1.transfer(0xAE);// SSD1306_DISPLAYOFF
- SPI1.transfer(0xD5);// SSD1306_SETDISPLAYCLOCKDIV
- SPI1.transfer(0x80);// // the suggested ratio 0x80
- pc.printf("Step 4 \r\n");
- led = 0; // on
- wait(1);
- led = 1;
- wait(1);
- led = 0;
+ SPI1.transfer(SSD1306_DISPLAYOFF);
+ SPI1.transfer(SSD1306_SETDISPLAYCLOCKDIV);
+ SPI1.transfer(0x80); // the suggested ratio 0x80
+
+ SPI1.transfer(SSD1306_SETMULTIPLEX);
+ SPI1.transfer(31);
+
+ SPI1.transfer(SSD1306_SETDISPLAYOFFSET);
+ SPI1.transfer(0x0); // no offset
+
+ SPI1.transfer(SSD1306_SETSTARTLINE | 0x0); // line #0
+
+ SPI1.transfer(SSD1306_CHARGEPUMP);
+ SPI1.transfer(0x14);
+
+ SPI1.transfer(SSD1306_MEMORYMODE);
+ SPI1.transfer(0x00); // 0x0 act like ks0108
+
+ SPI1.transfer(SSD1306_SEGREMAP | 0x1);
+
+ SPI1.transfer(SSD1306_COMSCANDEC);
+
+ SPI1.transfer(SSD1306_SETCOMPINS);
+ SPI1.transfer(0x02); // TODO - calculate based on _rawHieght ?
+
+ SPI1.transfer(SSD1306_SETCONTRAST);
+ SPI1.transfer(0x8F );
+
+ SPI1.transfer(SSD1306_SETPRECHARGE);
+ SPI1.transfer( 0x22);
+
+ SPI1.transfer(SSD1306_SETVCOMDETECT);
+ SPI1.transfer(0x40);
+
+ SPI1.transfer(SSD1306_DISPLAYALLON_RESUME);
+
+ SPI1.transfer(SSD1306_NORMALDISPLAY);
+
+ SPI1.transfer(SSD1306_DISPLAYON);
+
+
+
+ while(1){
+ led = 0; // on
+ wait(1);
+ led = 1;
+ wait(1);
+ }
}