128x64 grafical display with KS0107B and KS0108B controller

Committer:
hornfeldt
Date:
Tue Sep 07 07:17:53 2010 +0000
Revision:
3:6c18ab81111c
Parent:
1:1d06bc155ef3
Licensed as MIT

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hornfeldt 3:6c18ab81111c 1 /*
hornfeldt 3:6c18ab81111c 2 Copyright (c) 2010 Anders Hörnfeldt
hornfeldt 3:6c18ab81111c 3
hornfeldt 3:6c18ab81111c 4 Permission is hereby granted, free of charge, to any person obtaining a copy
hornfeldt 3:6c18ab81111c 5 of this software and associated documentation files (the "Software"), to deal
hornfeldt 3:6c18ab81111c 6 in the Software without restriction, including without limitation the rights
hornfeldt 3:6c18ab81111c 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
hornfeldt 3:6c18ab81111c 8 copies of the Software, and to permit persons to whom the Software is
hornfeldt 3:6c18ab81111c 9 furnished to do so, subject to the following conditions:
hornfeldt 3:6c18ab81111c 10
hornfeldt 3:6c18ab81111c 11 The above copyright notice and this permission notice shall be included in
hornfeldt 3:6c18ab81111c 12 all copies or substantial portions of the Software.
hornfeldt 3:6c18ab81111c 13
hornfeldt 3:6c18ab81111c 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
hornfeldt 3:6c18ab81111c 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
hornfeldt 3:6c18ab81111c 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
hornfeldt 3:6c18ab81111c 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
hornfeldt 3:6c18ab81111c 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
hornfeldt 3:6c18ab81111c 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
hornfeldt 3:6c18ab81111c 20 THE SOFTWARE.
hornfeldt 3:6c18ab81111c 21 */
hornfeldt 3:6c18ab81111c 22
hornfeldt 0:45771b38d50d 23 #include "Display.h"
hornfeldt 1:1d06bc155ef3 24 #include "font.h"
hornfeldt 0:45771b38d50d 25
hornfeldt 0:45771b38d50d 26 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)
hornfeldt 0:45771b38d50d 27 : DB(DB0,DB1,DB2,DB3,DB4,DB5,DB6,DB7), RS(_RS), RW(_RW), E(_E), CS1(_CS1), CS2(_CS2) {
hornfeldt 0:45771b38d50d 28 DB.mode(PullNone);
hornfeldt 0:45771b38d50d 29 E = 0;
hornfeldt 0:45771b38d50d 30 SendCommand(0x3F, 4|8);
hornfeldt 0:45771b38d50d 31 for (int c=0;c<128;c++) {
hornfeldt 0:45771b38d50d 32 for (int r=0;r<8;r++)
hornfeldt 0:45771b38d50d 33 {
hornfeldt 0:45771b38d50d 34 write(r,c,0);
hornfeldt 0:45771b38d50d 35 }
hornfeldt 0:45771b38d50d 36 }
hornfeldt 0:45771b38d50d 37 }
hornfeldt 1:1d06bc155ef3 38 DisplayTTY::DisplayTTY (Display *d, int _row, int _startY, int _numOfChars, int _numOfRows, int _charOffset, int _flags)
hornfeldt 0:45771b38d50d 39 {
hornfeldt 1:1d06bc155ef3 40 kalle = d;
hornfeldt 1:1d06bc155ef3 41 row = _row;
hornfeldt 1:1d06bc155ef3 42 startY = _startY;
hornfeldt 1:1d06bc155ef3 43 numOfChars = _numOfChars;
hornfeldt 1:1d06bc155ef3 44 numOfRows = _numOfRows;
hornfeldt 1:1d06bc155ef3 45 charOffset = _charOffset;
hornfeldt 1:1d06bc155ef3 46 flags = _flags;
hornfeldt 1:1d06bc155ef3 47 CursPosY = 0;
hornfeldt 1:1d06bc155ef3 48 CursPosW = row;
hornfeldt 1:1d06bc155ef3 49 cls();
hornfeldt 0:45771b38d50d 50 }
hornfeldt 0:45771b38d50d 51 int Display::SendCommand(unsigned int Command, int f) {
hornfeldt 0:45771b38d50d 52 int value = 1;
hornfeldt 0:45771b38d50d 53 E = 0;
hornfeldt 0:45771b38d50d 54 RS = 0;
hornfeldt 0:45771b38d50d 55 RW = 0;
hornfeldt 0:45771b38d50d 56 CS1 = 0;
hornfeldt 0:45771b38d50d 57 CS2 = 0;
hornfeldt 0:45771b38d50d 58 if (f&1)
hornfeldt 0:45771b38d50d 59 RS = 1;
hornfeldt 0:45771b38d50d 60 if (f&2)
hornfeldt 0:45771b38d50d 61 RW = 1;
hornfeldt 0:45771b38d50d 62 if (f&4)
hornfeldt 0:45771b38d50d 63 CS1 = 1;
hornfeldt 0:45771b38d50d 64 if (f&8)
hornfeldt 0:45771b38d50d 65 CS2 = 1;
hornfeldt 1:1d06bc155ef3 66 wait(0.0000003); // 300ns
hornfeldt 0:45771b38d50d 67 E = 1;
hornfeldt 0:45771b38d50d 68 if (f&2)
hornfeldt 0:45771b38d50d 69 {
hornfeldt 0:45771b38d50d 70 DB.input();
hornfeldt 1:1d06bc155ef3 71 wait(0.0000003);
hornfeldt 0:45771b38d50d 72 value = DB;
hornfeldt 0:45771b38d50d 73 }
hornfeldt 0:45771b38d50d 74 else
hornfeldt 0:45771b38d50d 75 {
hornfeldt 0:45771b38d50d 76 DB.output();
hornfeldt 0:45771b38d50d 77 DB = Command;
hornfeldt 0:45771b38d50d 78 }
hornfeldt 1:1d06bc155ef3 79 wait(0.0000001);
hornfeldt 0:45771b38d50d 80 E = 0;
hornfeldt 0:45771b38d50d 81 return value;
hornfeldt 0:45771b38d50d 82 }
hornfeldt 0:45771b38d50d 83
hornfeldt 0:45771b38d50d 84 void Display::write (int page, int y, unsigned int data) {
hornfeldt 0:45771b38d50d 85 int f = 0;
hornfeldt 0:45771b38d50d 86 if (y<64)
hornfeldt 0:45771b38d50d 87 f = 4;
hornfeldt 0:45771b38d50d 88 else
hornfeldt 0:45771b38d50d 89 f = 8;
hornfeldt 0:45771b38d50d 90 CurCol = y;
hornfeldt 0:45771b38d50d 91 SendCommand(0xB8+(page&0x07), f);
hornfeldt 0:45771b38d50d 92 SendCommand(0x40+(y&0x3F),f);
hornfeldt 0:45771b38d50d 93 SendCommand(data, f+1);
hornfeldt 0:45771b38d50d 94 }
hornfeldt 0:45771b38d50d 95
hornfeldt 1:1d06bc155ef3 96 void Display::writec (int row, int Y, int c) {
hornfeldt 0:45771b38d50d 97 if (c>31 && c<127)
hornfeldt 0:45771b38d50d 98 {
hornfeldt 1:1d06bc155ef3 99 write(row,Y+0,font5x8[(c-32)*5+0]);
hornfeldt 1:1d06bc155ef3 100 write(row,Y+1,font5x8[(c-32)*5+1]);
hornfeldt 1:1d06bc155ef3 101 write(row,Y+2,font5x8[(c-32)*5+2]);
hornfeldt 1:1d06bc155ef3 102 write(row,Y+3,font5x8[(c-32)*5+3]);
hornfeldt 1:1d06bc155ef3 103 write(row,Y+4,font5x8[(c-32)*5+4]);
hornfeldt 0:45771b38d50d 104 }
hornfeldt 0:45771b38d50d 105 }
hornfeldt 1:1d06bc155ef3 106 int DisplayTTY::_putc (int c)
hornfeldt 1:1d06bc155ef3 107 {
hornfeldt 1:1d06bc155ef3 108 if (c == '\n')
hornfeldt 1:1d06bc155ef3 109 newline();
hornfeldt 1:1d06bc155ef3 110 else
hornfeldt 1:1d06bc155ef3 111 {
hornfeldt 1:1d06bc155ef3 112 kalle->writec(CursPosW, startY+CursPosY*charOffset, c);
hornfeldt 1:1d06bc155ef3 113
hornfeldt 1:1d06bc155ef3 114 if (++CursPosY>=numOfChars)
hornfeldt 1:1d06bc155ef3 115 newline();
hornfeldt 1:1d06bc155ef3 116 }
hornfeldt 1:1d06bc155ef3 117
hornfeldt 1:1d06bc155ef3 118 return 0;
hornfeldt 1:1d06bc155ef3 119 }
hornfeldt 1:1d06bc155ef3 120 int DisplayTTY::_getc() {
hornfeldt 1:1d06bc155ef3 121 return 0;
hornfeldt 1:1d06bc155ef3 122 }
hornfeldt 1:1d06bc155ef3 123 void DisplayTTY::newline() {
hornfeldt 1:1d06bc155ef3 124 CursPosY=0;
hornfeldt 1:1d06bc155ef3 125 if ((++CursPosW-row)>=numOfRows)
hornfeldt 1:1d06bc155ef3 126 {
hornfeldt 1:1d06bc155ef3 127 CursPosW = row;
hornfeldt 1:1d06bc155ef3 128 }
hornfeldt 1:1d06bc155ef3 129 }
hornfeldt 1:1d06bc155ef3 130 void DisplayTTY::cls() {
hornfeldt 1:1d06bc155ef3 131 CursPosY=0;
hornfeldt 1:1d06bc155ef3 132 CursPosW = row;
hornfeldt 1:1d06bc155ef3 133 for (int c=0;c<numOfChars*numOfRows;c++)
hornfeldt 1:1d06bc155ef3 134 {
hornfeldt 1:1d06bc155ef3 135 _putc(' ');
hornfeldt 1:1d06bc155ef3 136 }
hornfeldt 1:1d06bc155ef3 137 }