SG12864A

Dependents:   SG12864A_TestProgram

Files at this revision

API Documentation at this revision

Comitter:
shintamainjp
Date:
Mon Jul 19 12:43:25 2010 +0000
Child:
1:aacd73a4e7ee
Commit message:

Changed in this revision

SG12864A.cpp Show annotated file Show diff for this revision Revisions of this file
SG12864A.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SG12864A.cpp	Mon Jul 19 12:43:25 2010 +0000
@@ -0,0 +1,240 @@
+/**
+ * SG12864A Graphics LCD module driver class (Version 0.0.1)
+ *
+ * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems)
+ * http://shinta.main.jp/
+ */
+
+#include "SG12864A.h"
+
+SG12864A::SG12864A(PinName di,
+                   PinName rw,
+                   PinName en,
+                   PinName db0,
+                   PinName db1,
+                   PinName db2,
+                   PinName db3,
+                   PinName db4,
+                   PinName db5,
+                   PinName db6,
+                   PinName db7,
+                   PinName cs1,
+                   PinName cs2,
+                   PinName res)
+        :
+        ioDI(di),
+        ioRW(rw),
+        ioEN(en),
+        ioDB(db0, db1, db2, db3, db4, db5, db6, db7),
+        ioCS1(cs1),
+        ioCS2(cs2),
+        ioRES(res) {
+    setDirectionToWrite();
+}
+
+SG12864A::~SG12864A() {
+}
+
+/**
+ * High Level Interface.
+ *
+ * Reset display module.
+ */
+void SG12864A::reset(void) {
+    setDisplayOnOff(SG12864A::CS1, false);
+    setDisplayOnOff(SG12864A::CS2, false);
+    clear();
+
+    reset(true);
+    wait_ms(200);
+    reset(false);
+    wait_ms(200);
+
+    setDisplayOnOff(SG12864A::CS1, true);
+    setDisplayOnOff(SG12864A::CS2, true);
+    setDisplayStartLine(SG12864A::CS1, 0);
+    setDisplayStartLine(SG12864A::CS2, 0);
+    setPageAddress(SG12864A::CS1, 0);
+    setPageAddress(SG12864A::CS2, 0);
+    setColumnAddress(SG12864A::CS1, 0);
+    setColumnAddress(SG12864A::CS2, 0);
+}
+
+/**
+ * High Level Interface.
+ *
+ * Clear display module.
+ */
+void SG12864A::clear(void) {
+    for (uint8_t page = 0; page < PAGES; page++) {
+        for (uint8_t column = 0; column < COLUMNS; column++) {
+            // CS1
+            setPageAddress(SG12864A::CS1, page);
+            setColumnAddress(SG12864A::CS1, column);
+            writeData(CS1, 0x00);
+            // CS2
+            setPageAddress(SG12864A::CS2, page);
+            setColumnAddress(SG12864A::CS2, column);
+            writeData(CS2, 0x00);
+        }
+    }
+    // CS1
+    setPageAddress(SG12864A::CS1, 0);
+    setColumnAddress(SG12864A::CS1, 0);
+    writeData(CS1, 0x00);
+    // CS2
+    setPageAddress(SG12864A::CS2, 0);
+    setColumnAddress(SG12864A::CS2, 0);
+    writeData(CS2, 0x00);
+}
+
+/**
+ * Middle Level Interface.
+ *
+ * Set display on/off.
+ *
+ * @param t Target (CS1, CS2).
+ * @param on ON/OFF (true, false).
+ */
+void SG12864A::setDisplayOnOff(Target t, bool on) {
+    setDirectionToWrite();
+    uint8_t c = 0x3e | (on ? 0x01 : 0x00);
+    write(t, SG12864A::Instruction, c);
+    wait_us(1);
+}
+
+/**
+ * Middle Level Interface.
+ *
+ * Set display start line.
+ *
+ * @param t Target (CS1, CS2).
+ * @param addr Display start line (0-63).
+ */
+void SG12864A::setDisplayStartLine(Target t, uint8_t addr) {
+    setDirectionToWrite();
+    uint8_t c = 0xc0 | (addr & 0x3f);
+    write(t, SG12864A::Instruction, c);
+    wait_us(1);
+}
+
+/**
+ * Middle Level Interface.
+ *
+ * Set page address.
+ *
+ * @param t Target (CS1, CS2).
+ * @param addr Page address(0-7).
+ */
+void SG12864A::setPageAddress(Target t, uint8_t addr) {
+    setDirectionToWrite();
+    uint8_t c = 0xb8 | (addr & 0x07);
+    write(t, SG12864A::Instruction, c);
+    wait_us(1);
+}
+
+/**
+ * Middle Level Interface.
+ *
+ * Set column address.
+ *
+ * @param t Target. (CS1, CS2)
+ * @param addr Column address (0-63).
+ */
+void SG12864A::setColumnAddress(Target t, uint8_t addr) {
+    setDirectionToWrite();
+    uint8_t c = 0x40 | (addr & 0x3f);
+    write(t, SG12864A::Instruction, c);
+    wait_us(1);
+}
+
+/**
+ * Middle Level Interface.
+ */
+void SG12864A::readStatus(Target t, uint8_t *c) {
+    setDirectionToRead();
+    read(t, SG12864A::Instruction, c);
+    wait_us(1);
+}
+
+/**
+ * Middle Level Interface.
+ */
+void SG12864A::writeData(Target t, uint8_t c) {
+    setDirectionToWrite();
+    write(t, SG12864A::Data, c);
+    wait_us(1);
+}
+
+/**
+ * Middle Level Interface.
+ */
+void SG12864A::readData(Target t, uint8_t *c) {
+    setDirectionToRead();
+    read(t, SG12864A::Data, c);
+    wait_us(1);
+}
+
+/**
+ * Low Level Interface.
+ */
+void SG12864A::setDirectionToRead() {
+    ioDB.input();
+    ioRW = 1;
+}
+
+/**
+ * Low Level Interface.
+ */
+void SG12864A::setDirectionToWrite() {
+    ioDB.output();
+    ioRW = 0;
+}
+
+/**
+ * Low Level Interface.
+ */
+void SG12864A::write(Target t, Mode m, uint8_t c) {
+    switch (t) {
+        case CS1:
+            ioCS1 = 1;
+            ioCS2 = 0;
+            break;
+        case CS2:
+            ioCS1 = 0;
+            ioCS2 = 1;
+            break;
+    }
+    switch (m) {
+        case Data:
+            ioDI = 1;
+            break;
+        case Instruction:
+            ioDI = 0;
+            break;
+    }
+    ioDB = c;
+    wait_us(1);
+    ioEN = 1;
+    wait_us(1);
+    ioEN = 0;
+    wait_us(5);
+}
+
+/**
+ * Low Level Interface.
+ */
+void SG12864A::read(Target t, Mode m, uint8_t *c) {
+    // TODO
+}
+
+/**
+ * Low Level Interface.
+ */
+void SG12864A::reset(bool b) {
+    if (b) {
+        ioRES = 0;
+    } else {
+        ioRES = 1;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SG12864A.h	Mon Jul 19 12:43:25 2010 +0000
@@ -0,0 +1,65 @@
+/**
+ * SG12864A Graphics LCD module driver class (Version 0.0.1)
+ *
+ * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems)
+ * http://shinta.main.jp/
+ */
+
+#ifndef _SG12864A_H_
+#define _SG12864A_H_
+
+#include "mbed.h"
+
+class SG12864A {
+public:
+    SG12864A(
+        PinName di,
+        PinName rw,
+        PinName en,
+        PinName db0,
+        PinName db1,
+        PinName db2,
+        PinName db3,
+        PinName db4,
+        PinName db5,
+        PinName db6,
+        PinName db7,
+        PinName cs1,
+        PinName cs2,
+        PinName res);
+    ~SG12864A();
+    enum Target {
+        CS1,
+        CS2
+    };
+    void reset(void);
+    void clear(void);
+    void setDisplayOnOff(Target t, bool on);
+    void setDisplayStartLine(Target t, uint8_t displayStartLine);
+    void setPageAddress(Target t, uint8_t addr);
+    void setColumnAddress(Target t, uint8_t addr);
+    void readStatus(Target t, uint8_t *c);
+    void writeData(Target t, uint8_t c);
+    void readData(Target t, uint8_t *c);
+private:
+    static const int PAGES = 8;
+    static const int COLUMNS = 64;
+    DigitalOut ioDI;
+    DigitalOut ioRW;
+    DigitalOut ioEN;
+    BusInOut ioDB;
+    DigitalOut ioCS1;
+    DigitalOut ioCS2;
+    DigitalOut ioRES;
+    enum Mode {
+        Data,
+        Instruction
+    };
+    void setDirectionToRead();
+    void setDirectionToWrite();
+    void write(Target t, Mode m, uint8_t c);
+    void read(Target t, Mode m, uint8_t *c);
+    void reset(bool b);
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jul 19 12:43:25 2010 +0000
@@ -0,0 +1,40 @@
+/**
+ * SG12864A Graphics LCD module driver class (Version 0.0.1)
+ *
+ * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems)
+ * http://shinta.main.jp/
+ */
+
+#include "mbed.h"
+#include "SG12864A.h"
+
+int main() {
+
+    SG12864A lcd(p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18);
+
+    lcd.reset();
+
+    {
+        static const int pages = 8;
+        static const int columns = 64;
+        for (int i = 0; i < pages; i++) {
+            lcd.setPageAddress(SG12864A::CS1, i);
+            lcd.setPageAddress(SG12864A::CS2, i);
+            for (int j = 0; j < columns; j++) {
+                uint8_t n = 1 << (j % 8);
+                lcd.setColumnAddress(SG12864A::CS1, j);
+                lcd.setColumnAddress(SG12864A::CS2, j);
+                lcd.writeData(SG12864A::CS1, n);
+                lcd.writeData(SG12864A::CS2, n);
+            }
+        }
+    }
+
+    uint8_t n = 0;
+    while (1) {
+        lcd.setDisplayStartLine(SG12864A::CS1, n);
+        lcd.setDisplayStartLine(SG12864A::CS2, n);
+        n++;
+        wait_ms(100);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Jul 19 12:43:25 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9114680c05da