Revision 0:1cfbf6b8d116, committed 2010-11-19
- Comitter:
- tonydbeck
- Date:
- Fri Nov 19 23:48:18 2010 +0000
- Commit message:
Changed in this revision
diff -r 000000000000 -r 1cfbf6b8d116 KS0713.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/KS0713.cpp Fri Nov 19 23:48:18 2010 +0000
@@ -0,0 +1,237 @@
+#include "gLCD.h"
+#include "mbed.h"
+
+gLCD::gLCD(PinName rst, PinName rs, PinName e, PinName d0, PinName d1,
+ PinName d2, PinName d3, PinName d4, PinName d5, PinName d6, PinName d7, PinName led)
+ : _rst(rst), _rs(rs), _e(e), _d(d0, d1, d2, d3, d4, d5, d6, d7), _led(led){
+
+ _rst = 0; // Put display driver into Reset mode
+ _e = 1;
+ _rs = 0; // Put display controller in command mode
+
+ wait(0.015); // Wait 15ms to ensure powered up
+
+ _rst = 1; // Switch reset off
+
+
+ /* ADC Select
+ Horizontal direction
+ 0xA0 = SEG1->SEG132 (left to right)
+ 0xA1 = SEG132->SEG1 (right to left) */
+ writeCommand(0xA0); // 0xA0 = SEG1->SEG132 (left to right)
+
+ /* SHL Select
+ Vertical direction
+ 0xC0 = COM1->COM64 (top to bottom)
+ 0xC8 = COM64->COM1 (bottom to top) */
+ writeCommand(0xC0); // 0xC0 = COM1->COM64
+
+ /* LCD bias select
+ Screen in use: Displaytech 64128E
+ Display duty ratio: 1/65
+ Display bias: 1/9
+ 0xA2 = 1/5 or 1/6 or 1/7 bias
+ 0xA3 = 1/6 or 1/8 or 1/9 bias
+ Note: at 1/6 bias use 0xA2 for 1/49 duty ratio
+ or 0xA3 for 1/33 duty ratio */
+ writeCommand(0xA3); // 0xA3 = 1/9 bias
+
+ /*Power control
+ Displaytech screen uses built-in power circuits
+ Switch on in order as specified in data sheet
+ wait 1ms between each command
+ 1st - Voltage converter ON = 0x2C
+ 2nd - Voltage regulator ON = 0x2E
+ 3rd - Voltage follower ON = 0x2F */
+ writeCommand(0x2C); //0x2C = Voltage converter ON
+ wait(0.001);
+ writeCommand(0x2E); //0x2E = Voltage regulator ON
+ wait(0.001);
+ writeCommand(0x2F); //0x2F = Voltage follower ON
+
+ /*Regulator resistor select
+ Sets the internal resistance ratio used in the internal voltage regulator
+ Refer to datasheet p.42
+ This works as a corse contrast control
+ 0x20 = 1.9
+ 0x21 = 2.19
+ 0x22 = 2.55
+ 0x23 = 3.02
+ 0x24 = 3.61
+ 0x25 = 4.35
+ 0x26 = 5.29
+ 0x27 = 6.48 */
+ writeCommand(0x26);
+
+ /*Set reference voltage register
+ Used as a fine contrast control
+ 0x81 = Enter voltage register set mode
+ 0x00 to 0x3F = 0 to 63 */
+ writeCommand(0x81); //0x81 = Enter voltage register set mode
+ writeCommand(0x46); //0x30 = Set ref voltage to 30
+
+ /*Initial display line
+ Specify DDRAM line for COM1
+ 0x40 + display line */
+ writeCommand(0x40); //Set initial line to 0
+
+ /*Set page address
+ Sets the initial page address to write to
+ 0xB0 + page address 0 to 8 */
+ writeCommand(0xB0); //Initial page set to 0
+
+ /*Set column address
+ Sets the initial column to write to
+ for LSB (b3-b0) 0x00 + first nibble
+ for MSB (b7-b4) 0x10 + second nibble
+ 0x00 to 0x83 = column 0 to 131 */
+ writeCommand(0x00); //Sets LSB to 0
+ writeCommand(0x10); //Sets MSB to 0 - column is now set to 0
+
+ /*Reverse display
+ Selects either a normal display or a reverse display
+ 0xA6 = normal
+ 0xA7 = reverse */
+ writeCommand(0xA6); //Sets display to normal
+
+ /*Set static indicator
+ Sets up a static indicator on the display
+ See datasheet p.42
+ This is a 2 instruction cycle
+ 0xAC = static indicator ON
+ 0xAD = static indicator OFF
+ Next instruction to set indicator type:
+ 0x00 = OFF
+ 0x01 = ON - 1 second blinking
+ 0x02 = ON - 0.5 second blinking
+ 0x03 = ON - always ON */
+ writeCommand(0xAD); //Static indicator OFF
+ writeCommand(0x00); //OFF - 0.5 second blinking
+
+ /*Display ON/OFF
+ Switched the display to on or off
+ 0xAE = Display OFF
+ 0xAF = Display ON */
+ writeCommand(0xAF);
+
+
+
+
+
+
+}
+
+
+
+void gLCD::writeCommand(int command)
+ {
+ _rs = 0;
+ wait(0.000040f);
+ writeByte(command);
+ }
+
+void gLCD::writeData(int data)
+ {
+ _rs = 1;
+ writeByte(data);
+ }
+
+void gLCD::writeByte(int value)
+ {
+ _led = 1;
+ _e = 1;
+ wait(0.000040f); //Allow time for display
+ _d = value;
+ wait(0.000040f); //Allow time for display
+ _e = 0; //Load value to display - display driver registers on falling edge of e
+ _led = 0;
+
+ }
+
+void gLCD::locate(int page, int column)
+ {
+ _column = column;
+ _page = page;
+ writeCommand(0xB0 + page);
+ writeCommand(0x00 + (column & 0x0f));
+ writeCommand(0x10 + ((column >> 4) & 0x0f));
+ }
+
+void gLCD::locateChar(int page, int column)
+ {
+ column = ((column*6)+1);
+ _column = column;
+ _page = page;
+ writeCommand(0xB0 + page);
+ writeCommand(0x00 + (column & 0x0f));
+ writeCommand(0x10 + ((column >> 4) & 0x0f));
+ }
+
+void gLCD::clearScreen()
+ {
+ for(int a = 0; a < 8; a++)
+ {
+ locate(a,0);
+ for(int b = 0; b <128; b++)
+ {
+ writeData(0x00);
+ }
+ }
+ locate(0,0);
+ }
+
+void gLCD::writeChar5x8(int p, int col, int c)
+ {
+ const int *ptrFont5x8 = font5x8;
+ locate(p,col);
+ ptrFont5x8+= ((c-32)*6);
+
+ for(int a=0; a < 6; a++)
+ {
+
+ writeData(*ptrFont5x8);
+
+ ptrFont5x8++;
+ }
+
+ }
+
+
+
+int gLCD::_putc(int value)
+ {
+
+
+
+ writeChar5x8(_page, _column, value);
+ _column+=6;
+
+
+ return value;
+}
+
+int gLCD::_getc() {
+ return -1;
+}
+
+
+void gLCD::writeBitmap(const int *ptrBitmap)
+ {
+
+
+
+ for(int a=0; a < 8; a++)
+ {
+ locate(a,0);
+
+ for(int b=0; b < 128; b++)
+ {
+ writeData(*ptrBitmap);
+ ptrBitmap+=8;
+
+
+ }
+ ptrBitmap-=1023;
+ }
+
+ }
\ No newline at end of file
diff -r 000000000000 -r 1cfbf6b8d116 KS0713.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/KS0713.h Fri Nov 19 23:48:18 2010 +0000
@@ -0,0 +1,77 @@
+#ifndef GLCD_H
+#define GLCD_H
+
+#include "mbed.h"
+#include "bitmap.h"
+#include "font.h"
+
+
+
+class gLCD : public Stream {
+public:
+
+
+ /* rst = Reset rs = Register Select e = Enable d0 - d7 = 8bit data bus */
+
+ gLCD(PinName rst, PinName rs, PinName e, PinName d0, PinName d1, PinName d2, PinName d3, PinName d4, PinName d5, PinName d6, PinName d7, PinName led);
+
+
+#if DOXYGEN_ONLY
+ int putc(int c);
+ int printf(const char* format, ...);
+#endif
+
+
+
+ /* locate(page address, column address)
+ Function to locate a position on the display */
+ void locate(int page, int column);
+
+ /* clearScreen()
+ Function to clear entire display */
+ void clearScreen();
+
+ /* writeBitmap(name of bitmap array)
+ Function to write a bitmap to the display */
+ void writeBitmap(const int *ptrBitmap);
+
+
+ void locateChar(int page, int column);
+
+ protected:
+
+ virtual int _putc(int value);
+ virtual int _getc();
+
+ /* writeCommand(Command to send to display)
+ Function to write a command to the display
+ RS is low for commands */
+
+ void writeCommand(int command);
+
+ /* writeData(Data to send to display RAM)
+ Function to send data to the display */
+
+ void writeData(int data);
+
+ /* writeByte(Byte to send to the display via the data bus)
+ Function to write a byte to the display */
+
+ void writeByte(int value);
+ /*Initialize Digital Outputs for RS signal and E signal */
+
+ void writeChar5x8(int p, int col, int c);
+
+ DigitalOut _rs, _e, _rst, _led;
+
+ /*Initialize bus for data*/
+
+ BusOut _d;
+
+ int _page;
+ int _column;
+
+};
+
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 1cfbf6b8d116 bitmap.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bitmap.h Fri Nov 19 23:48:18 2010 +0000
@@ -0,0 +1,11 @@
+const int bitmapToDisplay[] =
+{
+
+// Hex data here in the form of 1024 bytes.
+// must declare pointer in main program.....
+//eg.
+//const int *ptrBitmapToDisplay = bitmapToDisplay
+
+// To convert 128x64 bitmap into hex array use 'the dot factory' - an open source program
+
+};
\ No newline at end of file
diff -r 000000000000 -r 1cfbf6b8d116 font.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/font.h Fri Nov 19 23:48:18 2010 +0000
@@ -0,0 +1,99 @@
+const int font5x8[] =
+{
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // " " 0x20
+ 0x00, 0x00, 0x4f, 0x00, 0x00, 0x00, // ! 0x21
+ 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, // " 0x22
+ 0x14, 0x7f, 0x14, 0x7f, 0x14, 0x00, // # 0x23
+ 0x24, 0x2a, 0x7f, 0x2a, 0x12, 0x00, // $ 0x24
+ 0x23, 0x13, 0x08, 0x64, 0x62, 0x00, // % 0x25
+ 0x36, 0x49, 0x55, 0x22, 0x50, 0x00, // & 0x26
+ 0x00, 0x05, 0x03, 0x00, 0x00, 0x00, // ' 0x27
+ 0x00, 0x1c, 0x22, 0x41, 0x00, 0x00, // ( 0x28
+ 0x00, 0x41, 0x22, 0x1c, 0x00, 0x00, // ) 0x29
+ 0x14, 0x08, 0x3e, 0x08, 0x14, 0x00, // * 0x2A
+ 0x08, 0x08, 0x3e, 0x08, 0x08, 0x00, // + 0x2B
+ 0x00, 0x50, 0x30, 0x00, 0x00, 0x00, // , 0x2C
+ 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, // - 0x2D
+ 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, // . 0x2E
+ 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, // / 0x2F
+ 0x3e, 0x51, 0x49, 0x45, 0x3e, 0x00, // 0 0x30
+ 0x00, 0x42, 0x7f, 0x40, 0x00, 0x00, // 1 0x31
+ 0x42, 0x61, 0x51, 0x49, 0x46, 0x00, // 2 0x32
+ 0x21, 0x41, 0x45, 0x4b, 0x31, 0x00, // 3 0x33
+ 0x18, 0x14, 0x12, 0x7f, 0x10, 0x00, // 4 0x34
+ 0x27, 0x45, 0x45, 0x45, 0x39, 0x00, // 5 0x35
+ 0x3c, 0x4a, 0x49, 0x49, 0x30, 0x00, // 6 0x36
+ 0x01, 0x71, 0x09, 0x05, 0x03, 0x00, // 7 0x37
+ 0x36, 0x49, 0x49, 0x49, 0x36, 0x00, // 8 0x38
+ 0x06, 0x49, 0x49, 0x29, 0x1e, 0x00, // 9 0x39
+ 0x00, 0x36, 0x36, 0x00, 0x00, 0x00, // : 0x3A
+ 0x00, 0x56, 0x36, 0x00, 0x00, 0x00, // ; 0x3B
+ 0x08, 0x14, 0x22, 0x41, 0x00, 0x00, // < 0x3C
+ 0x14, 0x14, 0x14, 0x14, 0x14, 0x00, // = 0x3D
+ 0x00, 0x41, 0x22, 0x14, 0x08, 0x00, // > 0x3E
+ 0x02, 0x01, 0x51, 0x09, 0x06, 0x00, // ? 0x3F
+ 0x32, 0x49, 0x79, 0x41, 0x3e, 0x00, // @ 0x40
+ 0x7e, 0x11, 0x11, 0x11, 0x7e, 0x00, // A 0x41
+ 0x7f, 0x49, 0x49, 0x49, 0x36, 0x00, // B 0x42
+ 0x3e, 0x41, 0x41, 0x41, 0x22, 0x00, // C 0x43
+ 0x7f, 0x41, 0x41, 0x22, 0x1c, 0x00, // D 0x44
+ 0x7f, 0x49, 0x49, 0x49, 0x41, 0x00, // E 0x45
+ 0x7f, 0x09, 0x09, 0x09, 0x01, 0x00, // F 0x46
+ 0x3e, 0x41, 0x49, 0x49, 0x7a, 0x00, // G 0x47
+ 0x7f, 0x08, 0x08, 0x08, 0x7f, 0x00, // H 0x48
+ 0x00, 0x41, 0x7f, 0x41, 0x00, 0x00, // I 0x49
+ 0x20, 0x40, 0x41, 0x3f, 0x01, 0x00, // J 0x4A
+ 0x7f, 0x08, 0x14, 0x22, 0x41, 0x00, // K 0x4B
+ 0x7f, 0x40, 0x40, 0x40, 0x40, 0x00, // L 0x4C
+ 0x7f, 0x02, 0x0c, 0x02, 0x7f, 0x00, // M 0x4D
+ 0x7f, 0x04, 0x08, 0x10, 0x7f, 0x00, // N 0x4E
+ 0x3e, 0x41, 0x41, 0x41, 0x3e, 0x00, // O 0x4F
+ 0x7f, 0x09, 0x09, 0x09, 0x06, 0x00, // P 0X50
+ 0x3e, 0x41, 0x51, 0x21, 0x5e, 0x00, // Q 0X51
+ 0x7f, 0x09, 0x19, 0x29, 0x46, 0x00, // R 0X52
+ 0x46, 0x49, 0x49, 0x49, 0x31, 0x00, // S 0X53
+ 0x01, 0x01, 0x7f, 0x01, 0x01, 0x00, // T 0X54
+ 0x3f, 0x40, 0x40, 0x40, 0x3f, 0x00, // U 0X55
+ 0x1f, 0x20, 0x40, 0x20, 0x1f, 0x00, // V 0X56
+ 0x3f, 0x40, 0x38, 0x40, 0x3f, 0x00, // W 0X57
+ 0x63, 0x14, 0x08, 0x14, 0x63, 0x00, // X 0X58
+ 0x07, 0x08, 0x70, 0x08, 0x07, 0x00, // Y 0X59
+ 0x61, 0x51, 0x49, 0x45, 0x43, 0x00, // Z 0X5A
+ 0x00, 0x7f, 0x41, 0x41, 0x00, 0x00, // [ 0X5B
+ 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, // "\" 0X5C
+ 0x00, 0x41, 0x41, 0x7f, 0x00, 0x00, // ] 0X5D
+ 0x04, 0x02, 0x01, 0x02, 0x04, 0x00, // ^ 0X5E
+ 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, // _ 0X5F
+ 0x00, 0x01, 0x02, 0x04, 0x00, 0x00, // ` 0X60
+ 0x20, 0x54, 0x54, 0x54, 0x78, 0x00, // a 0X61
+ 0x7f, 0x48, 0x44, 0x44, 0x38, 0x00, // b 0X62
+ 0x38, 0x44, 0x44, 0x44, 0x20, 0x00, // c 0X63
+ 0x38, 0x44, 0x44, 0x48, 0x7f, 0x00, // d 0X64
+ 0x38, 0x54, 0x54, 0x54, 0x18, 0x00, // e 0X65
+ 0x08, 0x7e, 0x09, 0x01, 0x02, 0x00, // f 0X66
+ 0x0c, 0x52, 0x52, 0x52, 0x3e, 0x00, // g 0X67
+ 0x7f, 0x08, 0x04, 0x04, 0x78, 0x00, // h 0X68
+ 0x00, 0x44, 0x7d, 0x40, 0x00, 0x00, // i 0X69
+ 0x20, 0x40, 0x44, 0x3d, 0x00, 0x00, // j 0X6A
+ 0x7f, 0x10, 0x28, 0x44, 0x00, 0x00, // k 0X6B
+ 0x00, 0x41, 0x7f, 0x40, 0x00, 0x00, // l 0X6C
+ 0x7c, 0x04, 0x18, 0x04, 0x78, 0x00, // m 0X6D
+ 0x7c, 0x08, 0x04, 0x04, 0x78, 0x00, // n 0X6E
+ 0x38, 0x44, 0x44, 0x44, 0x38, 0x00, // o 0X6F
+ 0x7c, 0x14, 0x14, 0x14, 0x08, 0x00, // p 0X70
+ 0x08, 0x14, 0x14, 0x18, 0x7c, 0x00, // q 0X71
+ 0x7c, 0x08, 0x04, 0x04, 0x08, 0x00, // r 0X72
+ 0x48, 0x54, 0x54, 0x54, 0x20, 0x00, // s 0X73
+ 0x04, 0x3f, 0x44, 0x40, 0x20, 0x00, // t 0X74
+ 0x3c, 0x40, 0x40, 0x20, 0x7c, 0x00, // u 0X75
+ 0x1c, 0x20, 0x40, 0x20, 0x1c, 0x00, // v 0X76
+ 0x3c, 0x40, 0x30, 0x40, 0x3c, 0x00, // w 0X77
+ 0x44, 0x28, 0x10, 0x28, 0x44, 0x00, // x 0X78
+ 0x0c, 0x50, 0x50, 0x50, 0x3c, 0x00, // y 0X79
+ 0x44, 0x64, 0x54, 0x4c, 0x44, 0x00, // z 0X7A
+ 0x00, 0x08, 0x36, 0x41, 0x00, 0x00, // { 0X7B
+ 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, // | 0X7C
+ 0x00, 0x41, 0x36, 0x08, 0x00, 0x00, // } 0X7D
+ 0x02, 0x01, 0x02, 0x04, 0x02, 0x00, // ~ 0X7E
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // -- filler --
+};
\ No newline at end of file