From 89ca5987aaff0fd6ee4f559fee5efd5c7f91042c Mon Sep 17 00:00:00 2001 From: JP Date: Sun, 12 Jan 2014 21:00:51 +1100 Subject: [PATCH] first commit --- MicroView.cpp | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++ MicroView.h | 81 +++++++++++++++++++++++++++++ keywords.txt | 23 +++++++++ 3 files changed, 241 insertions(+) create mode 100644 MicroView.cpp create mode 100644 MicroView.h create mode 100644 keywords.txt diff --git a/MicroView.cpp b/MicroView.cpp new file mode 100644 index 0000000..a54eb89 --- /dev/null +++ b/MicroView.cpp @@ -0,0 +1,137 @@ +#include +#include +#include + +void MICROVIEW::begin() { + // SPI + SPI.setClockDivider(SPI_CLOCK_DIV2); + SPI.begin(); + pinMode(MOSI, OUTPUT); + pinMode(SCK, OUTPUT); + pinMode(DC, OUTPUT); + pinMode(RESET, OUTPUT); + pinMode(cs, OUTPUT); + digitalWrite(cs, HIGH); + + sckport = portOutputRegister(digitalPinToPort(SCK)); + sckpinmask = digitalPinToBitMask(SCK); + mosiport = portOutputRegister(digitalPinToPort(MOSI)); + mosipinmask = digitalPinToBitMask(MOSI); + csport = portOutputRegister(digitalPinToPort(cs)); + cspinmask = digitalPinToBitMask(cs); + dcport = portOutputRegister(digitalPinToPort(DC)); + dcpinmask = digitalPinToBitMask(DC); + + digitalWrite(RESET, HIGH); + // VDD (3.3V) goes high at start, lets just chill for a ms + delay(1); + // bring reset low + digitalWrite(RESET, LOW); + // wait 10ms + delay(10); + // bring out of reset + digitalWrite(RESET, HIGH); + // turn on VCC + // Init sequence for 64x48 OLED module + command(DISPLAYOFF); // 0xAE + + command(SETDISPLAYCLOCKDIV); // 0xD5 + command(0x80); // the suggested ratio 0x80 + + command(SETMULTIPLEX); // 0xA8 + command(0x2F); + + command(SETDISPLAYOFFSET); // 0xD3 + command(0x0); // no offset + + command(SETSTARTLINE | 0x0); // line #0 + + command(CHARGEPUMP); // enable charge pump + command(0x14); + + command(NORMALDISPLAY); // 0xA6 + command(DISPLAYALLONRESUME); // 0xA4 + + +// command(MEMORYMODE); // 0x20 +// command(0x00); // Horizontal Memory Addressing mode + + command(SEGREMAP | 0x1); + + command(COMSCANDEC); + + command(SETCOMPINS); // 0xDA + command(0x12); + + command(SETCONTRAST); // 0x81 + command(0x8F); + + command(SETPRECHARGE); // 0xd9 + command(0xF1); + + command(SETVCOMDESELECT); // 0xDB + command(0x40); + + command(DISPLAYON); //--turn on oled panel +} + +void MICROVIEW::command(uint8_t c) { + // Hardware SPI + *csport |= cspinmask; // CS HIGH + *dcport &= ~dcpinmask; // DC LOW + *csport &= ~cspinmask; // CS LOW + SPI.transfer(c); + *csport |= cspinmask; // CS HIGH +} + +void MICROVIEW::data(uint8_t c) { + // Hardware SPI + *csport |= cspinmask; // CS HIGH + *dcport |= dcpinmask; // DC HIGH + *csport &= ~cspinmask; // CS LOW + SPI.transfer(c); + *csport |= cspinmask; // CS HIGH +} + +void MICROVIEW::setPageAddress(uint8_t add) { + add=0xb0|add; + command(add); + return; +} + +void MICROVIEW::setColumnAddress(uint8_t add) { + command((0x10|(add>>4))+0x02); + command((0x0f&add)); + return; +} + +void MICROVIEW::clear(void) { + for (int i=0;i<8; i++) { + setPageAddress(i); + setColumnAddress(0); + for (int j=0; j<0x80; j++) { + data(0); + } + } +} + +void MICROVIEW::stopScroll(void){ + command(DEACTIVATESCROLL); +} + +void MICROVIEW::scrollRight(uint8_t start, uint8_t stop){ + if (stop= 100 + #include "Arduino.h" +#else + #include "WProgram.h" +#endif + +// CS is defined when constructing MICROVIEW class, thus the library can control multiple slave MicroViews. +#define DC 8 +#define SCK 13 +#define MOSI 11 +#define RESET 12 + +#define BLACK 0 +#define WHITE 1 + +#define LCDWIDTH 64 +#define LCDHEIGHT 48 + +#define SETCONTRAST 0x81 +#define DISPLAYALLONRESUME 0xA4 +#define DISPLAYALLON 0xA5 +#define NORMALDISPLAY 0xA6 +#define INVERTDISPLAY 0xA7 +#define DISPLAYOFF 0xAE +#define DISPLAYON 0xAF +#define SETDISPLAYOFFSET 0xD3 +#define SETCOMPINS 0xDA +#define SETVCOMDESELECT 0xDB +#define SETDISPLAYCLOCKDIV 0xD5 +#define SETPRECHARGE 0xD9 +#define SETMULTIPLEX 0xA8 +#define SETLOWCOLUMN 0x00 +#define SETHIGHCOLUMN 0x10 +#define SETSTARTLINE 0x40 +#define MEMORYMODE 0x20 +#define COMSCANINC 0xC0 +#define COMSCANDEC 0xC8 +#define SEGREMAP 0xA0 +#define CHARGEPUMP 0x8D +#define EXTERNALVCC 0x01 +#define SWITCHCAPVCC 0x02 + +// Scroll +#define ACTIVATESCROLL 0x2F +#define DEACTIVATESCROLL 0x2E +#define SETVERTICALSCROLLAREA 0xA3 +#define RIGHTHORIZONTALSCROLL 0x26 +#define LEFT_HORIZONTALSCROLL 0x27 +#define VERTICALRIGHTHORIZONTALSCROLL 0x29 +#define VERTICALLEFTHORIZONTALSCROLL 0x2A + +class MICROVIEW { + public: + MICROVIEW(uint8_t CS) :cs(CS) {} + void begin(void); + void command(uint8_t c); + void data(uint8_t c); + void clear(void); + void invert(uint8_t i); + void display(void); + void drawPixel(uint8_t x, uint8_t y, uint8_t color); + void drawBitmap(void); + void setColumnAddress(uint8_t add); + void setPageAddress(uint8_t add); + + void scrollRight(uint8_t start, uint8_t stop); + void scrollLeft(uint8_t start, uint8_t stop); + void scrollVertRight(uint8_t start, uint8_t stop); + void scrollVertLeft(uint8_t start, uint8_t stop); + void stopScroll(void); + + + private: + uint8_t cs; + volatile uint8_t *mosiport, *sckport, *csport, *dcport; // use volatile because these are fixed location port address + uint8_t mosipinmask, sckpinmask, cspinmask, dcpinmask; +}; +#endif \ No newline at end of file diff --git a/keywords.txt b/keywords.txt new file mode 100644 index 0000000..162acdd --- /dev/null +++ b/keywords.txt @@ -0,0 +1,23 @@ +####################################### +# Syntax Coloring Map For MicroView +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +MicroView KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +begin KEYWORD2 +clear KEYWORD2 +home KEYWORD2 + + +####################################### +# Constants (LITERAL1) +####################################### +