C12832 LCD kanji interface.

Dependents:  

Fork of GraphicOLED by Norimasa Okamoto

Files at this revision

API Documentation at this revision

Comitter:
va009039
Date:
Thu Sep 04 03:43:30 2014 +0000
Parent:
3:a6650dd2dbc8
Commit message:
for C12832 LCD

Changed in this revision

C12832_KANJI.cpp Show annotated file Show diff for this revision Revisions of this file
C12832_KANJI.h Show annotated file Show diff for this revision Revisions of this file
GraphicOLED.cpp Show diff for this revision Revisions of this file
GraphicOLED.h Show diff for this revision Revisions of this file
misaki_8x8_unicode.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832_KANJI.cpp	Thu Sep 04 03:43:30 2014 +0000
@@ -0,0 +1,164 @@
+// C12832_KANJI.cpp
+#include "C12832_KANJI.h"
+
+extern void font_4x8(uint8_t buf[], int c); // misaki_4x8_jis201.cpp
+extern void font_8x8(uint8_t buf[], uint32_t unicode); // misaki_8x8_unicode.cpp
+
+C12832_KANJI::C12832_KANJI(PinName mosi, PinName sck, PinName reset, PinName a0, PinName ncs) : _spi(mosi,NC,sck),_reset(reset),_A0(a0),_CS(ncs) {
+
+    _spi.format(8,3);                 // 8 bit spi mode 3
+    //_spi.frequency(20000000);          // 19,2 Mhz SPI clock
+    _A0 = 0;
+    _CS = 1;
+    _reset = 0;                        // display reset
+    wait_us(50);
+    _reset = 1;                       // end reset
+    wait_ms(5);
+ 
+    /* Start Initial Sequence ----------------------------------------------------*/
+ 
+    writeCommand(0xAE);   //  display off
+    writeCommand(0xA2);   //  bias voltage
+ 
+    writeCommand(0xA0);
+    writeCommand(0xC8);   //  colum normal
+ 
+    writeCommand(0x22);   //  voltage resistor ratio
+    writeCommand(0x2F);   //  power on
+    //writeCommand(0xA4);   //  LCD display ram
+    writeCommand(0x40);   // start line = 0
+    writeCommand(0xAF);     // display ON
+ 
+    writeCommand(0x81);   //  set contrast
+    writeCommand(0x17);   //  set contrast
+ 
+    writeCommand(0xA6);     // display normal
+
+    _uni_len = 0;
+}
+
+void C12832_KANJI::g_write(uint8_t pat, int x, int y) {
+    writeCommand(0x00 + ( x    &0x0f)); // set column low nibble 0
+    writeCommand(0x10 + ((x>>4)&0x0f)); // set column hi  nibble 0
+    writeCommand(0xB0 + y); // set page address
+
+    writeData(pat);
+}
+
+void C12832_KANJI::g_write(uint8_t *buf, int len, int x, int y) {
+    for(int i = 0; i < len; i++) {
+        g_write(*buf++, x++, y);
+    }
+}
+
+void C12832_KANJI::writeCommand(uint8_t command) {
+    _A0 = 0;
+    writeByte(command);
+}
+
+void C12832_KANJI::writeData(uint8_t data) {
+    _A0 = 1;
+    writeByte(data);
+}
+
+void C12832_KANJI::writeByte(uint8_t value) {
+    _CS = 0;
+    _spi.write(value);
+    _CS = 1;
+}
+
+void C12832_KANJI::cls() {
+    for(int y = 0; y < rows(); y++) {
+        for(int x = 0; x < 128; x++) {
+            g_write(0x00, x, y);
+        }
+    }
+    locate(0,0);
+    _uni_len = 0;
+}
+
+void C12832_KANJI::locate(int column, int row) {
+    _column = column;
+    _row = row;
+}
+
+int C12832_KANJI::columns() {
+     return 128/4;
+}
+
+int C12832_KANJI::rows() {
+    return 4;
+}
+
+int C12832_KANJI::_putc(int value)
+{
+    int step = 0;
+    if (value == '\n') {
+        _column = 0;
+        _row++;
+        if (_row >= rows()) {
+            _row = 0;
+        }
+        _uni_len = 0;
+    } else if (value <= 0x7f) {
+        step = character(_column, _row, value);
+    } else if (value >= 0xc2 && value <= 0xdf) {
+        _unicode = value & 0x1f;
+        _uni_len = 1;
+    } else if (value >= 0xe0 && value <= 0xef) {
+        _unicode = value & 0x0f;
+        _uni_len = 2;
+    } else if (value >= 0xf0 && value <= 0xf7) {
+        _unicode = value & 0x07;
+        _uni_len = 3;
+    } else if (value >= 0xf8 && value <= 0xfb) {
+        _unicode = value & 0x03;
+        _uni_len = 4;
+    } else if (value >= 0xfc && value <= 0xfd) {
+        _unicode = value & 0x01;
+        _uni_len = 5;
+    } else if (_uni_len >= 1 && value >= 0x80 && value <= 0xbf) {
+        _unicode = (_unicode<<6) | (value&0x3f);
+        if (--_uni_len == 0) {
+            step = character(_column, _row, _unicode);
+        }
+    } else {
+        _uni_len = 0;
+    }
+    if (step > 0) {
+        _column += step;
+        if (_column >= columns()) {
+            _column = 0;
+            if (++_row >= rows()) {
+                _row = 0;
+            }
+        }
+        _uni_len = 0;
+    }
+    return value;
+}
+
+int C12832_KANJI::_getc() {
+    return -1;
+}
+
+int C12832_KANJI::character(int column, int row, int c) {
+    if (c <= 0x7f) { // 半角
+        uint8_t buf[4];
+        font_4x8(buf, c);
+        g_write(buf, sizeof(buf), column*4, row);
+        return 1;
+    } else if (c >= 0xff61 && c <= 0xff9f) { // 半角カタカナ
+        int i = c - 0xff61 + 0xa1;
+        uint8_t buf[4];
+        font_4x8(buf, i);
+        g_write(buf, sizeof(buf), column*4, row);
+        return 1;
+    } else { // 全角
+        uint8_t buf[8];
+        font_8x8(buf, c);
+        g_write(buf, sizeof(buf), column*4, row);
+        return 2;
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832_KANJI.h	Thu Sep 04 03:43:30 2014 +0000
@@ -0,0 +1,76 @@
+// C12832_KANJI.h
+#pragma once
+#include "mbed.h"
+
+/** C12832 interface
+ *
+ * Currently support UTF-8 KANJI(misaki font) 
+ *
+ * @code
+ * #include "mbed.h"
+ * #include "C12832_KANJI.h"
+ * 
+ * C12832_KANJI lcd(p5, p7, p6, p8, p11);
+ * 
+ * int main() {
+ *     led.printf("Hello World!\n");
+ * }
+ * @endcode
+ */
+class C12832_KANJI : public Stream {
+public:
+    /** Create a C12832_KANJI interface
+     */
+    C12832_KANJI(PinName mosi, PinName sck, PinName reset, PinName a0, PinName ncs);
+
+#if DOXYGEN_ONLY
+    /** Write a character to the LCD
+     *
+     * @param c The character to write to the display
+     */
+    int putc(int c);
+
+    /** Write a formated string to the LCD
+     *
+     * @param format A printf-style format string, followed by the
+     *               variables to use in formating the string.
+     */
+    int printf(const char* format, ...);
+#endif
+
+    /** Locate to a screen column and row
+     *
+     * @param column  The horizontal position from the left, indexed from 0
+     * @param row     The vertical position from the top, indexed from 0
+     */
+    void locate(int column, int row);
+
+    /** Clear the screen and locate to 0,0 */
+    void cls();
+
+    int rows();
+    int columns();
+
+    void g_write(uint8_t pat, int x, int y);
+    void g_write(uint8_t *buf, int len, int x, int y);
+       
+private:
+    int _uni_len;
+    uint32_t _unicode;
+
+    // Stream implementation functions
+    virtual int _putc(int value);
+    virtual int _getc();
+
+    int character(int column, int row, int c);
+    void writeByte(uint8_t value);
+    void writeCommand(uint8_t command);
+    void writeData(uint8_t data);
+
+    SPI _spi;
+    DigitalOut _reset,_A0,_CS;
+
+    int _column;
+    int _row;
+};
+
--- a/GraphicOLED.cpp	Tue Aug 12 01:47:43 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,153 +0,0 @@
-// GraphicOLED.cpp
-#include "GraphicOLED.h"
-
-extern void font_4x8(uint8_t buf[], int c); // misaki_4x8_jis201.cpp
-extern void font_8x8(uint8_t buf[], uint32_t unicode); // misaki_8x8_unicode.cpp
-
-GraphicOLED::GraphicOLED(PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7) :  _rs(rs), _e(e), _d(d4, d5, d6, d7) {
-    _e  = 1;
-    _rs = 0;            // command mode
-
-    wait_ms(500);       // Wait For Stabilization 500ms
-
-    writeCommand(0x00); // 0x0 x 5, sync 4bit-mode
-    writeCommand(0x00);
-    writeCommand(0x02); // function set
-    writeCommand(0x28); // N=1 2-line display
-    writeCommand(0x0c); // D=1 display on
-    writeCommand(0x14); // S/C=0 R/L=1
-    writeCommand(0x1f); // G/C=1 graphic mode
-
-    _uni_len = 0;
-}
-
-void GraphicOLED::g_write(uint8_t pat, int x, int y) {
-    writeCommand(0x80 + (x&0x7f)); // x position
-    writeCommand(0x40 + (y&0x01)); //y position
-    writeData(pat);
-}
-
-void GraphicOLED::g_write(uint8_t *buf, int len, int x, int y) {
-    for(int i = 0; i < len; i++) {
-        g_write(*buf++, x++, y);
-    }
-}
-
-void GraphicOLED::writeCommand(uint8_t command) {
-    _rs = 0;
-    writeByte(command);
-}
-
-void GraphicOLED::writeData(uint8_t data) {
-    _rs = 1;
-    writeByte(data);
-}
-
-void GraphicOLED::writeByte(uint8_t value) {
-    _d = value >> 4;
-    wait_us(40);  // most instructions take 40us
-    _e = 0;
-    wait_us(40);
-    _e = 1;
-    _d = value >> 0;
-    wait_us(40);
-    _e = 0;
-    wait_us(40);  // most instructions take 40us
-    _e = 1;
-}
-
-void GraphicOLED::cls() {
-    for(int y = 0; y < rows(); y++) {
-        for(int x = 0; x < 100; x++) {
-            g_write(0x00, x, y);
-        }
-    }
-    locate(0,0);
-    _uni_len = 0;
-}
-
-void GraphicOLED::locate(int column, int row) {
-    _column = column;
-    _row = row;
-}
-
-int GraphicOLED::columns() {
-     return 25;
-}
-
-int GraphicOLED::rows() {
-    return 2;
-}
-
-int GraphicOLED::_putc(int value)
-{
-    int step = 0;
-    if (value == '\n') {
-        _column = 0;
-        _row++;
-        if (_row >= rows()) {
-            _row = 0;
-        }
-        _uni_len = 0;
-    } else if (value <= 0x7f) {
-        step = character(_column, _row, value);
-    } else if (value >= 0xc2 && value <= 0xdf) {
-        _unicode = value & 0x1f;
-        _uni_len = 1;
-    } else if (value >= 0xe0 && value <= 0xef) {
-        _unicode = value & 0x0f;
-        _uni_len = 2;
-    } else if (value >= 0xf0 && value <= 0xf7) {
-        _unicode = value & 0x07;
-        _uni_len = 3;
-    } else if (value >= 0xf8 && value <= 0xfb) {
-        _unicode = value & 0x03;
-        _uni_len = 4;
-    } else if (value >= 0xfc && value <= 0xfd) {
-        _unicode = value & 0x01;
-        _uni_len = 5;
-    } else if (_uni_len >= 1 && value >= 0x80 && value <= 0xbf) {
-        _unicode = (_unicode<<6) | (value&0x3f);
-        if (--_uni_len == 0) {
-            step = character(_column, _row, _unicode);
-        }
-    } else {
-        _uni_len = 0;
-    }
-    if (step > 0) {
-        _column += step;
-        if (_column >= columns()) {
-            _column = 0;
-            if (++_row >= rows()) {
-                _row = 0;
-            }
-        }
-        _uni_len = 0;
-    }
-    return value;
-}
-
-int GraphicOLED::_getc() {
-    return -1;
-}
-
-int GraphicOLED::character(int column, int row, int c) {
-    if (c <= 0x7f) { // 半角
-        uint8_t buf[4];
-        font_4x8(buf, c);
-        g_write(buf, sizeof(buf), column*4, row);
-        return 1;
-    } else if (c >= 0xff61 && c <= 0xff9f) { // 半角カタカナ
-        int i = c - 0xff61 + 0xa1;
-        uint8_t buf[4];
-        font_4x8(buf, i);
-        g_write(buf, sizeof(buf), column*4, row);
-        return 1;
-    } else { // 全角
-        uint8_t buf[8];
-        font_8x8(buf, c);
-        g_write(buf, sizeof(buf), column*4, row);
-        return 2;
-    }
-}
-
--- a/GraphicOLED.h	Tue Aug 12 01:47:43 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,80 +0,0 @@
-// GraphicOLED.h
-#pragma once
-#include "mbed.h"
-
-/** GraphicOLED interface for WS0010
- *
- * Currently support UTF-8 KANJI(misaki font) 
- *
- * @code
- * #include "mbed.h"
- * #include "GraphicOLED.h"
- * 
- * GraphicOLED oled(p24, p26, p27, p28, p29, p30); // rs, e, d4-d7
- * 
- * int main() {
- *     oled.printf("Hello World!\n");
- * }
- * @endcode
- */
-class GraphicOLED : public Stream {
-public:
-    /** Create a GraphicOLED interface
-     *
-     * @param rs    Instruction/data control line
-     * @param e     Enable line (clock)
-     * @param d4-d7 Data lines for using as a 4-bit interface
-     */
-    GraphicOLED(PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7);
-
-#if DOXYGEN_ONLY
-    /** Write a character to the OLED
-     *
-     * @param c The character to write to the display
-     */
-    int putc(int c);
-
-    /** Write a formated string to the OLED
-     *
-     * @param format A printf-style format string, followed by the
-     *               variables to use in formating the string.
-     */
-    int printf(const char* format, ...);
-#endif
-
-    /** Locate to a screen column and row
-     *
-     * @param column  The horizontal position from the left, indexed from 0
-     * @param row     The vertical position from the top, indexed from 0
-     */
-    void locate(int column, int row);
-
-    /** Clear the screen and locate to 0,0 */
-    void cls();
-
-    int rows();
-    int columns();
-
-    void g_write(uint8_t pat, int x, int y);
-    void g_write(uint8_t *buf, int len, int x, int y);
-       
-private:
-    int _uni_len;
-    uint32_t _unicode;
-
-    // Stream implementation functions
-    virtual int _putc(int value);
-    virtual int _getc();
-
-    int character(int column, int row, int c);
-    void writeByte(uint8_t value);
-    void writeCommand(uint8_t command);
-    void writeData(uint8_t data);
-
-    DigitalOut _rs, _e;
-    BusOut _d;
-
-    int _column;
-    int _row;
-};
-
--- a/misaki_8x8_unicode.cpp	Tue Aug 12 01:47:43 2014 +0000
+++ b/misaki_8x8_unicode.cpp	Thu Sep 04 03:43:30 2014 +0000
@@ -24,7 +24,7 @@
 // COPYRIGHT "Copyright(C) 2002-2012 Num Kadoma"
 // ENDPROPERTIES
 
-#include "GraphicOLED.h"
+#include "C12832_KANJI.h"
 
 struct stfont {
     uint16_t unicode;