128x64 grafical display with KS0107B and KS0108B controller

Revision:
0:45771b38d50d
Child:
1:1d06bc155ef3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Display.cpp	Tue Nov 17 22:42:50 2009 +0000
@@ -0,0 +1,74 @@
+#include "mbed.h"
+#include "Display.h"
+
+Display::Display (PinName _RS, PinName _RW, PinName _E, PinName _CS1, PinName _CS2, PinName DB0, PinName DB1, PinName DB2, PinName DB3, PinName DB4, PinName DB5, PinName DB6, PinName DB7)
+    : DB(DB0,DB1,DB2,DB3,DB4,DB5,DB6,DB7), RS(_RS), RW(_RW), E(_E), CS1(_CS1), CS2(_CS2) {
+    DB.mode(PullNone);
+    E = 0;
+    SendCommand(0x3F, 4|8);
+    for (int c=0;c<128;c++) {
+        for (int r=0;r<8;r++)
+        {
+            write(r,c,0);
+        }
+    }
+}
+DisplayTTY::DisplayTTY (Display *d, int row, int startY, int numOfChars=10, int numOfRows=1, int charOffset=6, int flags=0)
+{
+    display = d;
+}
+int Display::SendCommand(unsigned int Command, int f) {
+    int value = 1;
+    E = 0;
+    RS = 0;
+    RW = 0;
+    CS1 = 0;
+    CS2 = 0;
+    if (f&1)
+        RS = 1;
+    if (f&2)
+        RW = 1;
+    if (f&4)
+        CS1 = 1;
+    if (f&8)
+        CS2 = 1;
+    wait(0.0000005); // 500ns
+    E = 1;
+    if (f&2)
+    {
+        DB.input();
+        wait(0.0000004);
+        value = DB;
+    }
+    else
+    {
+        DB.output();
+        wait(0.0000001);
+        DB = Command;
+    }
+    E = 0;
+    return value;
+}
+
+void Display::write (int page, int y, unsigned int data) {
+    int f = 0;
+    if (y<64)
+        f = 4;
+    else
+        f = 8;
+    CurCol = y;
+    SendCommand(0xB8+(page&0x07), f);
+    SendCommand(0x40+(y&0x3F),f);
+    SendCommand(data, f+1);
+}
+
+void Display::writec (int row, int Y, char c) {
+    if (c>31 && c<127)
+    {
+        write(row,Y,font5x8[(c-32)*5+0]);
+        write(row,Y,font5x8[(c-32)*5+1]);
+        write(row,Y,font5x8[(c-32)*5+2]);
+        write(row,Y,font5x8[(c-32)*5+3]);
+        write(row,Y,font5x8[(c-32)*5+4]);
+    }
+}