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
main.cpp
- Committer:
- tsh
- Date:
- 2015-02-25
- Revision:
- 9:bbe01bf9a3ef
- Parent:
- 8:971ea27171dd
- Child:
- 10:d9a6a2fede8c
File content as of revision 9:bbe01bf9a3ef:
/*
Copyright (c) 2012-2014 RedBearLab
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "mbed.h"
#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);
DigitalOut cs(D2);
DigitalOut led(D13);
SPIClass SPI1(NRF_SPI1);
//Adafruit_SSD1306_nrf gOled1(A4,A3,D2);// SPI, DC, RST, CS
int main(void)
{
led = 1; // off
wait (0.3);
led = 0; // ON
wait (0.3);
led = 1; // off
// SPI1.begin(P0_8, P0_9, P0_11);//SCK, MOSI, MISO
//Display initialisation
rst = 1;
// VDD (3.3V) goes high at start, lets just chill for a ms
wait_ms(1);
// bring reset low
rst = 0;
// wait 10ms
wait_ms(10);
// bring out of reset
rst = 1;
// turn on VCC (9V?)
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);
}
}