128x64 grafical display with KS0107B and KS0108B controller
Diff: Display.cpp
- Revision:
- 1:1d06bc155ef3
- Parent:
- 0:45771b38d50d
- Child:
- 3:6c18ab81111c
--- a/Display.cpp Tue Nov 17 22:42:50 2009 +0000 +++ b/Display.cpp Wed Feb 10 14:47:58 2010 +0000 @@ -1,5 +1,5 @@ -#include "mbed.h" #include "Display.h" +#include "font.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) { @@ -13,9 +13,18 @@ } } } -DisplayTTY::DisplayTTY (Display *d, int row, int startY, int numOfChars=10, int numOfRows=1, int charOffset=6, int flags=0) +DisplayTTY::DisplayTTY (Display *d, int _row, int _startY, int _numOfChars, int _numOfRows, int _charOffset, int _flags) { - display = d; + kalle = d; + row = _row; + startY = _startY; + numOfChars = _numOfChars; + numOfRows = _numOfRows; + charOffset = _charOffset; + flags = _flags; + CursPosY = 0; + CursPosW = row; + cls(); } int Display::SendCommand(unsigned int Command, int f) { int value = 1; @@ -32,20 +41,20 @@ CS1 = 1; if (f&8) CS2 = 1; - wait(0.0000005); // 500ns + wait(0.0000003); // 300ns E = 1; if (f&2) { DB.input(); - wait(0.0000004); + wait(0.0000003); value = DB; } else { DB.output(); - wait(0.0000001); DB = Command; } + wait(0.0000001); E = 0; return value; } @@ -62,13 +71,45 @@ SendCommand(data, f+1); } -void Display::writec (int row, int Y, char c) { +void Display::writec (int row, int Y, int 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]); + write(row,Y+0,font5x8[(c-32)*5+0]); + write(row,Y+1,font5x8[(c-32)*5+1]); + write(row,Y+2,font5x8[(c-32)*5+2]); + write(row,Y+3,font5x8[(c-32)*5+3]); + write(row,Y+4,font5x8[(c-32)*5+4]); } } +int DisplayTTY::_putc (int c) +{ + if (c == '\n') + newline(); + else + { + kalle->writec(CursPosW, startY+CursPosY*charOffset, c); + + if (++CursPosY>=numOfChars) + newline(); + } + + return 0; +} +int DisplayTTY::_getc() { + return 0; +} +void DisplayTTY::newline() { + CursPosY=0; + if ((++CursPosW-row)>=numOfRows) + { + CursPosW = row; + } +} +void DisplayTTY::cls() { + CursPosY=0; + CursPosW = row; + for (int c=0;c<numOfChars*numOfRows;c++) + { + _putc(' '); + } +} \ No newline at end of file