Software to control a 128x64 graphic LCD with KS0107B and KS0108B controller. Slight modification to Anders Hörnfeldts Code which increases framerate by up to 300%.
Display.cpp@0:0cc7719c6d87, 2010-12-25 (annotated)
- Committer:
- hapoo
- Date:
- Sat Dec 25 10:14:10 2010 +0000
- Revision:
- 0:0cc7719c6d87
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hapoo | 0:0cc7719c6d87 | 1 | #include "Display.h" |
hapoo | 0:0cc7719c6d87 | 2 | #include "font.h" |
hapoo | 0:0cc7719c6d87 | 3 | |
hapoo | 0:0cc7719c6d87 | 4 | 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) |
hapoo | 0:0cc7719c6d87 | 5 | : DB(DB0,DB1,DB2,DB3,DB4,DB5,DB6,DB7), RS(_RS), RW(_RW), E(_E), CS1(_CS1), CS2(_CS2) { |
hapoo | 0:0cc7719c6d87 | 6 | DB.mode(PullNone); |
hapoo | 0:0cc7719c6d87 | 7 | E = 0; |
hapoo | 0:0cc7719c6d87 | 8 | SendCommand(0x3F, 4|8); |
hapoo | 0:0cc7719c6d87 | 9 | for (int c=0;c<128;c++) { |
hapoo | 0:0cc7719c6d87 | 10 | for (int r=0;r<8;r++) |
hapoo | 0:0cc7719c6d87 | 11 | { |
hapoo | 0:0cc7719c6d87 | 12 | write(r,c,0); |
hapoo | 0:0cc7719c6d87 | 13 | } |
hapoo | 0:0cc7719c6d87 | 14 | } |
hapoo | 0:0cc7719c6d87 | 15 | prevPage = -2; |
hapoo | 0:0cc7719c6d87 | 16 | prevY = -2; |
hapoo | 0:0cc7719c6d87 | 17 | } |
hapoo | 0:0cc7719c6d87 | 18 | DisplayTTY::DisplayTTY (Display *d, int _row, int _startY, int _numOfChars, int _numOfRows, int _charOffset, int _flags) |
hapoo | 0:0cc7719c6d87 | 19 | { |
hapoo | 0:0cc7719c6d87 | 20 | kalle = d; |
hapoo | 0:0cc7719c6d87 | 21 | row = _row; |
hapoo | 0:0cc7719c6d87 | 22 | startY = _startY; |
hapoo | 0:0cc7719c6d87 | 23 | numOfChars = _numOfChars; |
hapoo | 0:0cc7719c6d87 | 24 | numOfRows = _numOfRows; |
hapoo | 0:0cc7719c6d87 | 25 | charOffset = _charOffset; |
hapoo | 0:0cc7719c6d87 | 26 | flags = _flags; |
hapoo | 0:0cc7719c6d87 | 27 | CursPosY = 0; |
hapoo | 0:0cc7719c6d87 | 28 | CursPosW = row; |
hapoo | 0:0cc7719c6d87 | 29 | cls(); |
hapoo | 0:0cc7719c6d87 | 30 | } |
hapoo | 0:0cc7719c6d87 | 31 | int Display::SendCommand(unsigned int Command, int f) { |
hapoo | 0:0cc7719c6d87 | 32 | int value = 1; |
hapoo | 0:0cc7719c6d87 | 33 | E = 0; |
hapoo | 0:0cc7719c6d87 | 34 | RS = 0; |
hapoo | 0:0cc7719c6d87 | 35 | RW = 0; |
hapoo | 0:0cc7719c6d87 | 36 | CS1 = 0; |
hapoo | 0:0cc7719c6d87 | 37 | CS2 = 0; |
hapoo | 0:0cc7719c6d87 | 38 | if (f&1) |
hapoo | 0:0cc7719c6d87 | 39 | RS = 1; |
hapoo | 0:0cc7719c6d87 | 40 | if (f&2) |
hapoo | 0:0cc7719c6d87 | 41 | RW = 1; |
hapoo | 0:0cc7719c6d87 | 42 | if (f&4) |
hapoo | 0:0cc7719c6d87 | 43 | CS1 = 1; |
hapoo | 0:0cc7719c6d87 | 44 | |
hapoo | 0:0cc7719c6d87 | 45 | if (f&8) |
hapoo | 0:0cc7719c6d87 | 46 | CS2 = 1; |
hapoo | 0:0cc7719c6d87 | 47 | //wait(0.0000003); // 300ns |
hapoo | 0:0cc7719c6d87 | 48 | E = 1; |
hapoo | 0:0cc7719c6d87 | 49 | if (f&2) |
hapoo | 0:0cc7719c6d87 | 50 | { |
hapoo | 0:0cc7719c6d87 | 51 | DB.input(); |
hapoo | 0:0cc7719c6d87 | 52 | //wait(0.0000003); |
hapoo | 0:0cc7719c6d87 | 53 | value = DB; |
hapoo | 0:0cc7719c6d87 | 54 | } |
hapoo | 0:0cc7719c6d87 | 55 | else |
hapoo | 0:0cc7719c6d87 | 56 | { |
hapoo | 0:0cc7719c6d87 | 57 | DB.output(); |
hapoo | 0:0cc7719c6d87 | 58 | DB = Command; |
hapoo | 0:0cc7719c6d87 | 59 | } |
hapoo | 0:0cc7719c6d87 | 60 | //wait(0.0000001); |
hapoo | 0:0cc7719c6d87 | 61 | E = 0; |
hapoo | 0:0cc7719c6d87 | 62 | return value; |
hapoo | 0:0cc7719c6d87 | 63 | } |
hapoo | 0:0cc7719c6d87 | 64 | |
hapoo | 0:0cc7719c6d87 | 65 | void Display::write (int page, int y, unsigned int data) { |
hapoo | 0:0cc7719c6d87 | 66 | int f = 0; |
hapoo | 0:0cc7719c6d87 | 67 | if (y<64) |
hapoo | 0:0cc7719c6d87 | 68 | f = 4; |
hapoo | 0:0cc7719c6d87 | 69 | else |
hapoo | 0:0cc7719c6d87 | 70 | f = 8; |
hapoo | 0:0cc7719c6d87 | 71 | CurCol = y; |
hapoo | 0:0cc7719c6d87 | 72 | if( ( page != prevPage ) || ( y != (prevY+1) ) || (y == 64) ) |
hapoo | 0:0cc7719c6d87 | 73 | { |
hapoo | 0:0cc7719c6d87 | 74 | SendCommand(0xB8+(page&0x07), f); |
hapoo | 0:0cc7719c6d87 | 75 | SendCommand(0x40+(y&0x3F),f); |
hapoo | 0:0cc7719c6d87 | 76 | prevPage = page; |
hapoo | 0:0cc7719c6d87 | 77 | } |
hapoo | 0:0cc7719c6d87 | 78 | SendCommand(data, f+1); |
hapoo | 0:0cc7719c6d87 | 79 | |
hapoo | 0:0cc7719c6d87 | 80 | prevY = y; |
hapoo | 0:0cc7719c6d87 | 81 | } |
hapoo | 0:0cc7719c6d87 | 82 | |
hapoo | 0:0cc7719c6d87 | 83 | void Display::writec (int row, int Y, int c) { |
hapoo | 0:0cc7719c6d87 | 84 | if (c>31 && c<127) |
hapoo | 0:0cc7719c6d87 | 85 | { |
hapoo | 0:0cc7719c6d87 | 86 | write(row,Y+0,font5x8[(c-32)*5+0]); |
hapoo | 0:0cc7719c6d87 | 87 | write(row,Y+1,font5x8[(c-32)*5+1]); |
hapoo | 0:0cc7719c6d87 | 88 | write(row,Y+2,font5x8[(c-32)*5+2]); |
hapoo | 0:0cc7719c6d87 | 89 | write(row,Y+3,font5x8[(c-32)*5+3]); |
hapoo | 0:0cc7719c6d87 | 90 | write(row,Y+4,font5x8[(c-32)*5+4]); |
hapoo | 0:0cc7719c6d87 | 91 | } |
hapoo | 0:0cc7719c6d87 | 92 | } |
hapoo | 0:0cc7719c6d87 | 93 | int DisplayTTY::_putc (int c) |
hapoo | 0:0cc7719c6d87 | 94 | { |
hapoo | 0:0cc7719c6d87 | 95 | if (c == '\n') |
hapoo | 0:0cc7719c6d87 | 96 | newline(); |
hapoo | 0:0cc7719c6d87 | 97 | else |
hapoo | 0:0cc7719c6d87 | 98 | { |
hapoo | 0:0cc7719c6d87 | 99 | kalle->writec(CursPosW, startY+CursPosY*charOffset, c); |
hapoo | 0:0cc7719c6d87 | 100 | |
hapoo | 0:0cc7719c6d87 | 101 | if (++CursPosY>=numOfChars) |
hapoo | 0:0cc7719c6d87 | 102 | newline(); |
hapoo | 0:0cc7719c6d87 | 103 | } |
hapoo | 0:0cc7719c6d87 | 104 | |
hapoo | 0:0cc7719c6d87 | 105 | return 0; |
hapoo | 0:0cc7719c6d87 | 106 | } |
hapoo | 0:0cc7719c6d87 | 107 | int DisplayTTY::_getc() { |
hapoo | 0:0cc7719c6d87 | 108 | return 0; |
hapoo | 0:0cc7719c6d87 | 109 | } |
hapoo | 0:0cc7719c6d87 | 110 | void DisplayTTY::newline() { |
hapoo | 0:0cc7719c6d87 | 111 | CursPosY=0; |
hapoo | 0:0cc7719c6d87 | 112 | if ((++CursPosW-row)>=numOfRows) |
hapoo | 0:0cc7719c6d87 | 113 | { |
hapoo | 0:0cc7719c6d87 | 114 | CursPosW = row; |
hapoo | 0:0cc7719c6d87 | 115 | } |
hapoo | 0:0cc7719c6d87 | 116 | } |
hapoo | 0:0cc7719c6d87 | 117 | void DisplayTTY::cls() { |
hapoo | 0:0cc7719c6d87 | 118 | CursPosY=0; |
hapoo | 0:0cc7719c6d87 | 119 | CursPosW = row; |
hapoo | 0:0cc7719c6d87 | 120 | for (int c=0;c<numOfChars*numOfRows;c++) |
hapoo | 0:0cc7719c6d87 | 121 | { |
hapoo | 0:0cc7719c6d87 | 122 | _putc(' '); |
hapoo | 0:0cc7719c6d87 | 123 | } |
hapoo | 0:0cc7719c6d87 | 124 | } |