diff --git a/MicroView.cpp b/MicroView.cpp index 43d7780..f9ff4c2 100644 --- a/MicroView.cpp +++ b/MicroView.cpp @@ -1,5 +1,5 @@ #include -#include +//#include #include // This fixed ugly GCC warning "only initialized variables can be placed into program memory area" @@ -95,19 +95,19 @@ void MicroView::begin() { // Setting up SPI pins pinMode(MOSI, OUTPUT); pinMode(SCK, OUTPUT); - pinMode(DC, OUTPUT); + + //pinMode(DC, OUTPUT); pinMode(RESET, OUTPUT); - pinMode(SS, OUTPUT); + pinMode(SS, INPUT); digitalWrite(SS, HIGH); - sckport = portOutputRegister(digitalPinToPort(SCK)); - sckpinmask = digitalPinToBitMask(SCK); - mosiport = portOutputRegister(digitalPinToPort(MOSI)); - mosipinmask = digitalPinToBitMask(MOSI); - ssport = portOutputRegister(digitalPinToPort(SS)); - sspinmask = digitalPinToBitMask(SS); - dcport = portOutputRegister(digitalPinToPort(DC)); - dcpinmask = digitalPinToBitMask(DC); + ssport = portOutputRegister(digitalPinToPort(SS)); + sspinmask = digitalPinToBitMask(SS); + ssreg = portModeRegister(digitalPinToPort(SS)); + + dcport = portOutputRegister(digitalPinToPort(DC)); + dcpinmask = digitalPinToBitMask(DC); + dcreg = portModeRegister(digitalPinToPort(DC)); digitalWrite(RESET, HIGH); // VDD (3.3V) goes high at start, lets just chill for 5 ms @@ -122,7 +122,8 @@ void MicroView::begin() { // wait 10ms delay(10); // bring out of reset - digitalWrite(RESET, HIGH); + pinMode(RESET,INPUT_PULLUP); + //digitalWrite(RESET, HIGH); // Init sequence for 64x48 OLED module command(DISPLAYOFF); // 0xAE @@ -166,20 +167,33 @@ void MicroView::begin() { void MicroView::command(uint8_t c) { // Hardware SPI - *ssport |= sspinmask; // SS HIGH - *dcport &= ~dcpinmask; // DC LOW - *ssport &= ~sspinmask; // SS LOW + *dcreg |= dcpinmask; // Set DC pin to OUTPUT + *dcport &= ~dcpinmask; // DC pin LOW + + *ssreg |= sspinmask; // Set SS pin to OUTPUT + *ssport &= ~sspinmask; // SS LOW + MVSPI.transfer(c); + *ssport |= sspinmask; // SS HIGH + *ssreg &= ~sspinmask; // Set SS pin to INPUT + + *dcreg &= ~dcpinmask; // Set DC to INPUT to avoid high voltage over driving the OLED logic } void MicroView::data(uint8_t c) { // Hardware SPI - *ssport |= sspinmask; // SS HIGH *dcport |= dcpinmask; // DC HIGH + + *ssreg |= sspinmask; // Set SS pin to OUTPUT *ssport &= ~sspinmask; // SS LOW + MVSPI.transfer(c); + *ssport |= sspinmask; // SS HIGH + *ssreg &= ~sspinmask; // Set SS pin to INPUT + + *dcreg &= ~dcpinmask; // Set DC to INPUT to avoid high voltage over driving the OLED logic } void MicroView::setPageAddress(uint8_t add) { diff --git a/MicroView.h b/MicroView.h index 4acb896..c8d927b 100644 --- a/MicroView.h +++ b/MicroView.h @@ -9,7 +9,8 @@ #define DC 8 #define RESET 12 -// SS, SCK, MOSI already defined by original SPI.h + +// SS, SCK, MOSI already defined by original pins_arduino.h //#define CS 10 //#define SCK 13 //#define MOSI 11 @@ -158,7 +159,8 @@ public: private: //uint8_t cs; - volatile uint8_t *mosiport, *sckport, *ssport, *dcport; // use volatile because these are fixed location port address + //volatile uint8_t *mosiport, *sckport; + volatile uint8_t *ssport, *dcport, *ssreg, *dcreg; // use volatile because these are fixed location port address uint8_t mosipinmask, sckpinmask, sspinmask, dcpinmask; uint8_t foreColor,drawMode,fontWidth, fontHeight, fontType, fontStartChar, fontTotalChar, cursorX, cursorY; uint16_t fontMapWidth; diff --git a/README.md b/README.md index 490c03b..96a22c5 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,13 @@ Arduino library for MicroView. ## Installation -1. Extract / Check out to Arduino's libraries folder. -2. Start Arduino IDE. -3. MicroView example is located at, File--->Example--->MicroView--->MicroViewDemo +1. Change directory to Arduino's main directory +2. cd libraries +3. mkdir MicroView +4. cd MicroView +5. git clone git@github.com:geekammo/microview.git . +6. Start Arduino IDE. +7. MicroView example is located at, File--->Example--->MicroView--->MicroViewDemo ### Example 1 - Hello World!

@@ -87,6 +91,9 @@ void loop() {
 
## History +**v1.10b: 22th April 2014 by JP Liew** +* changed SS, RESET, DC pins to use weak internal pull-up resistors + **v1.09b: 17th April 2014 by JP Liew** * changed verticalFlip() to flipVertical() and horizontalFlip() to flipHorizontal() for consistency * added debug messages for doCmd()