128x64 grafical display with KS0107B and KS0108B controller

Committer:
hornfeldt
Date:
Wed Feb 10 14:47:58 2010 +0000
Revision:
1:1d06bc155ef3
Parent:
0:45771b38d50d
Child:
3:6c18ab81111c

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hornfeldt 0:45771b38d50d 1 #include "Display.h"
hornfeldt 1:1d06bc155ef3 2 #include "font.h"
hornfeldt 0:45771b38d50d 3
hornfeldt 0:45771b38d50d 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)
hornfeldt 0:45771b38d50d 5 : DB(DB0,DB1,DB2,DB3,DB4,DB5,DB6,DB7), RS(_RS), RW(_RW), E(_E), CS1(_CS1), CS2(_CS2) {
hornfeldt 0:45771b38d50d 6 DB.mode(PullNone);
hornfeldt 0:45771b38d50d 7 E = 0;
hornfeldt 0:45771b38d50d 8 SendCommand(0x3F, 4|8);
hornfeldt 0:45771b38d50d 9 for (int c=0;c<128;c++) {
hornfeldt 0:45771b38d50d 10 for (int r=0;r<8;r++)
hornfeldt 0:45771b38d50d 11 {
hornfeldt 0:45771b38d50d 12 write(r,c,0);
hornfeldt 0:45771b38d50d 13 }
hornfeldt 0:45771b38d50d 14 }
hornfeldt 0:45771b38d50d 15 }
hornfeldt 1:1d06bc155ef3 16 DisplayTTY::DisplayTTY (Display *d, int _row, int _startY, int _numOfChars, int _numOfRows, int _charOffset, int _flags)
hornfeldt 0:45771b38d50d 17 {
hornfeldt 1:1d06bc155ef3 18 kalle = d;
hornfeldt 1:1d06bc155ef3 19 row = _row;
hornfeldt 1:1d06bc155ef3 20 startY = _startY;
hornfeldt 1:1d06bc155ef3 21 numOfChars = _numOfChars;
hornfeldt 1:1d06bc155ef3 22 numOfRows = _numOfRows;
hornfeldt 1:1d06bc155ef3 23 charOffset = _charOffset;
hornfeldt 1:1d06bc155ef3 24 flags = _flags;
hornfeldt 1:1d06bc155ef3 25 CursPosY = 0;
hornfeldt 1:1d06bc155ef3 26 CursPosW = row;
hornfeldt 1:1d06bc155ef3 27 cls();
hornfeldt 0:45771b38d50d 28 }
hornfeldt 0:45771b38d50d 29 int Display::SendCommand(unsigned int Command, int f) {
hornfeldt 0:45771b38d50d 30 int value = 1;
hornfeldt 0:45771b38d50d 31 E = 0;
hornfeldt 0:45771b38d50d 32 RS = 0;
hornfeldt 0:45771b38d50d 33 RW = 0;
hornfeldt 0:45771b38d50d 34 CS1 = 0;
hornfeldt 0:45771b38d50d 35 CS2 = 0;
hornfeldt 0:45771b38d50d 36 if (f&1)
hornfeldt 0:45771b38d50d 37 RS = 1;
hornfeldt 0:45771b38d50d 38 if (f&2)
hornfeldt 0:45771b38d50d 39 RW = 1;
hornfeldt 0:45771b38d50d 40 if (f&4)
hornfeldt 0:45771b38d50d 41 CS1 = 1;
hornfeldt 0:45771b38d50d 42 if (f&8)
hornfeldt 0:45771b38d50d 43 CS2 = 1;
hornfeldt 1:1d06bc155ef3 44 wait(0.0000003); // 300ns
hornfeldt 0:45771b38d50d 45 E = 1;
hornfeldt 0:45771b38d50d 46 if (f&2)
hornfeldt 0:45771b38d50d 47 {
hornfeldt 0:45771b38d50d 48 DB.input();
hornfeldt 1:1d06bc155ef3 49 wait(0.0000003);
hornfeldt 0:45771b38d50d 50 value = DB;
hornfeldt 0:45771b38d50d 51 }
hornfeldt 0:45771b38d50d 52 else
hornfeldt 0:45771b38d50d 53 {
hornfeldt 0:45771b38d50d 54 DB.output();
hornfeldt 0:45771b38d50d 55 DB = Command;
hornfeldt 0:45771b38d50d 56 }
hornfeldt 1:1d06bc155ef3 57 wait(0.0000001);
hornfeldt 0:45771b38d50d 58 E = 0;
hornfeldt 0:45771b38d50d 59 return value;
hornfeldt 0:45771b38d50d 60 }
hornfeldt 0:45771b38d50d 61
hornfeldt 0:45771b38d50d 62 void Display::write (int page, int y, unsigned int data) {
hornfeldt 0:45771b38d50d 63 int f = 0;
hornfeldt 0:45771b38d50d 64 if (y<64)
hornfeldt 0:45771b38d50d 65 f = 4;
hornfeldt 0:45771b38d50d 66 else
hornfeldt 0:45771b38d50d 67 f = 8;
hornfeldt 0:45771b38d50d 68 CurCol = y;
hornfeldt 0:45771b38d50d 69 SendCommand(0xB8+(page&0x07), f);
hornfeldt 0:45771b38d50d 70 SendCommand(0x40+(y&0x3F),f);
hornfeldt 0:45771b38d50d 71 SendCommand(data, f+1);
hornfeldt 0:45771b38d50d 72 }
hornfeldt 0:45771b38d50d 73
hornfeldt 1:1d06bc155ef3 74 void Display::writec (int row, int Y, int c) {
hornfeldt 0:45771b38d50d 75 if (c>31 && c<127)
hornfeldt 0:45771b38d50d 76 {
hornfeldt 1:1d06bc155ef3 77 write(row,Y+0,font5x8[(c-32)*5+0]);
hornfeldt 1:1d06bc155ef3 78 write(row,Y+1,font5x8[(c-32)*5+1]);
hornfeldt 1:1d06bc155ef3 79 write(row,Y+2,font5x8[(c-32)*5+2]);
hornfeldt 1:1d06bc155ef3 80 write(row,Y+3,font5x8[(c-32)*5+3]);
hornfeldt 1:1d06bc155ef3 81 write(row,Y+4,font5x8[(c-32)*5+4]);
hornfeldt 0:45771b38d50d 82 }
hornfeldt 0:45771b38d50d 83 }
hornfeldt 1:1d06bc155ef3 84 int DisplayTTY::_putc (int c)
hornfeldt 1:1d06bc155ef3 85 {
hornfeldt 1:1d06bc155ef3 86 if (c == '\n')
hornfeldt 1:1d06bc155ef3 87 newline();
hornfeldt 1:1d06bc155ef3 88 else
hornfeldt 1:1d06bc155ef3 89 {
hornfeldt 1:1d06bc155ef3 90 kalle->writec(CursPosW, startY+CursPosY*charOffset, c);
hornfeldt 1:1d06bc155ef3 91
hornfeldt 1:1d06bc155ef3 92 if (++CursPosY>=numOfChars)
hornfeldt 1:1d06bc155ef3 93 newline();
hornfeldt 1:1d06bc155ef3 94 }
hornfeldt 1:1d06bc155ef3 95
hornfeldt 1:1d06bc155ef3 96 return 0;
hornfeldt 1:1d06bc155ef3 97 }
hornfeldt 1:1d06bc155ef3 98 int DisplayTTY::_getc() {
hornfeldt 1:1d06bc155ef3 99 return 0;
hornfeldt 1:1d06bc155ef3 100 }
hornfeldt 1:1d06bc155ef3 101 void DisplayTTY::newline() {
hornfeldt 1:1d06bc155ef3 102 CursPosY=0;
hornfeldt 1:1d06bc155ef3 103 if ((++CursPosW-row)>=numOfRows)
hornfeldt 1:1d06bc155ef3 104 {
hornfeldt 1:1d06bc155ef3 105 CursPosW = row;
hornfeldt 1:1d06bc155ef3 106 }
hornfeldt 1:1d06bc155ef3 107 }
hornfeldt 1:1d06bc155ef3 108 void DisplayTTY::cls() {
hornfeldt 1:1d06bc155ef3 109 CursPosY=0;
hornfeldt 1:1d06bc155ef3 110 CursPosW = row;
hornfeldt 1:1d06bc155ef3 111 for (int c=0;c<numOfChars*numOfRows;c++)
hornfeldt 1:1d06bc155ef3 112 {
hornfeldt 1:1d06bc155ef3 113 _putc(' ');
hornfeldt 1:1d06bc155ef3 114 }
hornfeldt 1:1d06bc155ef3 115 }