Library to drive DogM16x text displays

Committer:
FrankWeissenborn
Date:
Wed Jan 12 21:26:18 2011 +0000
Revision:
0:c8d5f35830ce
Child:
1:7557380ce11e
DgM162 and DogM163 support added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
FrankWeissenborn 0:c8d5f35830ce 1 #include "DogM16x.h"
FrankWeissenborn 0:c8d5f35830ce 2
FrankWeissenborn 0:c8d5f35830ce 3
FrankWeissenborn 0:c8d5f35830ce 4 DogM16x::DogM16x(PinName db0, PinName db1, PinName db2, PinName db3, PinName rw, PinName rs, PinName enable, PinName reset,DogM16x_TYPE type):_d(db0,db1,db2,db3),_rw(rw),_rs(rs),_enable(enable),_reset(reset) {
FrankWeissenborn 0:c8d5f35830ce 5 _reset = 1;
FrankWeissenborn 0:c8d5f35830ce 6 _rw = 0;
FrankWeissenborn 0:c8d5f35830ce 7 _enable = 0;
FrankWeissenborn 0:c8d5f35830ce 8 _type = type;
FrankWeissenborn 0:c8d5f35830ce 9 DEBUGOUT("DogM162: Start init");
FrankWeissenborn 0:c8d5f35830ce 10 Init();
FrankWeissenborn 0:c8d5f35830ce 11 DEBUGOUT("DogM162: End init");
FrankWeissenborn 0:c8d5f35830ce 12 }
FrankWeissenborn 0:c8d5f35830ce 13
FrankWeissenborn 0:c8d5f35830ce 14
FrankWeissenborn 0:c8d5f35830ce 15
FrankWeissenborn 0:c8d5f35830ce 16
FrankWeissenborn 0:c8d5f35830ce 17 void DogM16x::Init() {
FrankWeissenborn 0:c8d5f35830ce 18
FrankWeissenborn 0:c8d5f35830ce 19 if (_type == DogM16x_DogM161) {
FrankWeissenborn 0:c8d5f35830ce 20 DEBUGOUT("Not implemented yet");
FrankWeissenborn 0:c8d5f35830ce 21 return;
FrankWeissenborn 0:c8d5f35830ce 22 } else {
FrankWeissenborn 0:c8d5f35830ce 23 _rw = 0;
FrankWeissenborn 0:c8d5f35830ce 24 _enable = 0;
FrankWeissenborn 0:c8d5f35830ce 25 _rs = 0; // RS auf low
FrankWeissenborn 0:c8d5f35830ce 26
FrankWeissenborn 0:c8d5f35830ce 27 wait_ms(200);
FrankWeissenborn 0:c8d5f35830ce 28 WriteCommandByte(0x33); // function set lines, interface
FrankWeissenborn 0:c8d5f35830ce 29 wait_ms(5);
FrankWeissenborn 0:c8d5f35830ce 30 WriteCommandByte(0x32); // function set lines, interface
FrankWeissenborn 0:c8d5f35830ce 31 wait_ms(5);
FrankWeissenborn 0:c8d5f35830ce 32 WriteCommandByte(0x29); // function set lines, interface
FrankWeissenborn 0:c8d5f35830ce 33 wait_ms(5);
FrankWeissenborn 0:c8d5f35830ce 34 WriteCommandByte(0x14); // function set bias, OSC
FrankWeissenborn 0:c8d5f35830ce 35 wait_ms(5);
FrankWeissenborn 0:c8d5f35830ce 36 WriteCommandByte(0x72);//78// function set contrast
FrankWeissenborn 0:c8d5f35830ce 37 wait_ms(5);
FrankWeissenborn 0:c8d5f35830ce 38 WriteCommandByte(0x55);// function set power, icon, contrast
FrankWeissenborn 0:c8d5f35830ce 39 wait_ms(5);
FrankWeissenborn 0:c8d5f35830ce 40 WriteCommandByte(0x6E); //6D// function set follower
FrankWeissenborn 0:c8d5f35830ce 41 wait_ms(5);
FrankWeissenborn 0:c8d5f35830ce 42 WriteCommandByte(0x0C);// funktion set display on/off
FrankWeissenborn 0:c8d5f35830ce 43 wait_ms(5);
FrankWeissenborn 0:c8d5f35830ce 44 WriteCommandByte(0x01); // clear display
FrankWeissenborn 0:c8d5f35830ce 45 wait_ms(20);
FrankWeissenborn 0:c8d5f35830ce 46 WriteCommandByte(0x06); // entry mode set
FrankWeissenborn 0:c8d5f35830ce 47 wait_ms(20);
FrankWeissenborn 0:c8d5f35830ce 48 }
FrankWeissenborn 0:c8d5f35830ce 49
FrankWeissenborn 0:c8d5f35830ce 50 }
FrankWeissenborn 0:c8d5f35830ce 51
FrankWeissenborn 0:c8d5f35830ce 52 void DogM16x::WriteCommandByte(int cmd) {
FrankWeissenborn 0:c8d5f35830ce 53 _rs = 0;
FrankWeissenborn 0:c8d5f35830ce 54 _rw = 0;
FrankWeissenborn 0:c8d5f35830ce 55 SetData(cmd);
FrankWeissenborn 0:c8d5f35830ce 56 }
FrankWeissenborn 0:c8d5f35830ce 57 void DogM16x::WriteDataByte(int cmd) {
FrankWeissenborn 0:c8d5f35830ce 58 _rs = 1;
FrankWeissenborn 0:c8d5f35830ce 59 _rw = 0;
FrankWeissenborn 0:c8d5f35830ce 60 SetData(cmd);
FrankWeissenborn 0:c8d5f35830ce 61 }
FrankWeissenborn 0:c8d5f35830ce 62
FrankWeissenborn 0:c8d5f35830ce 63 void DogM16x::SetData(int value) {
FrankWeissenborn 0:c8d5f35830ce 64
FrankWeissenborn 0:c8d5f35830ce 65 _d = ((value & 0xF0)>>4); // Oberes Nibble
FrankWeissenborn 0:c8d5f35830ce 66 wait_us(30); // 30�s warten
FrankWeissenborn 0:c8d5f35830ce 67 _enable = 1; // Clock-Bit auf high
FrankWeissenborn 0:c8d5f35830ce 68 wait_us(1); // High muss min. 200ns anliegen
FrankWeissenborn 0:c8d5f35830ce 69 _enable = 0; // und jetzt auf low
FrankWeissenborn 0:c8d5f35830ce 70
FrankWeissenborn 0:c8d5f35830ce 71 wait_us(1); // 30�s warten
FrankWeissenborn 0:c8d5f35830ce 72 _d = (value & 0x0F); // Unteres Nibble
FrankWeissenborn 0:c8d5f35830ce 73 wait_us(30); // 30�s warten
FrankWeissenborn 0:c8d5f35830ce 74 _enable = 1; // Clock-Bit auf high
FrankWeissenborn 0:c8d5f35830ce 75 wait_us(1); // High muss min. 200ns anliegen
FrankWeissenborn 0:c8d5f35830ce 76 _enable = 0; // und jetzt auf low
FrankWeissenborn 0:c8d5f35830ce 77 }
FrankWeissenborn 0:c8d5f35830ce 78
FrankWeissenborn 0:c8d5f35830ce 79 /** Clear Display
FrankWeissenborn 0:c8d5f35830ce 80 *
FrankWeissenborn 0:c8d5f35830ce 81 * Write spaces into DDRAM and set address to (0,0)
FrankWeissenborn 0:c8d5f35830ce 82 *
FrankWeissenborn 0:c8d5f35830ce 83 */
FrankWeissenborn 0:c8d5f35830ce 84 void DogM16x::Clear() {
FrankWeissenborn 0:c8d5f35830ce 85 WriteCommandByte(0x01);
FrankWeissenborn 0:c8d5f35830ce 86 wait_ms(50);
FrankWeissenborn 0:c8d5f35830ce 87 }
FrankWeissenborn 0:c8d5f35830ce 88
FrankWeissenborn 0:c8d5f35830ce 89 /** Set Position to (x,line)
FrankWeissenborn 0:c8d5f35830ce 90 *
FrankWeissenborn 0:c8d5f35830ce 91 * @param x new x position
FrankWeissenborn 0:c8d5f35830ce 92 * @param line new line
FrankWeissenborn 0:c8d5f35830ce 93 */
FrankWeissenborn 0:c8d5f35830ce 94 void DogM16x::SetPosition(unsigned char x, DogM16x_LINE line) {
FrankWeissenborn 0:c8d5f35830ce 95
FrankWeissenborn 0:c8d5f35830ce 96 int distance_per_line = 0;
FrankWeissenborn 0:c8d5f35830ce 97 if (_type == DogM16x_DogM161) {
FrankWeissenborn 0:c8d5f35830ce 98 DEBUGOUT("Not implemented yet");
FrankWeissenborn 0:c8d5f35830ce 99 return;
FrankWeissenborn 0:c8d5f35830ce 100 }
FrankWeissenborn 0:c8d5f35830ce 101 if (_type == DogM16x_DogM162) {
FrankWeissenborn 0:c8d5f35830ce 102 distance_per_line = 20;
FrankWeissenborn 0:c8d5f35830ce 103 }
FrankWeissenborn 0:c8d5f35830ce 104 if (_type == DogM16x_DogM163) {
FrankWeissenborn 0:c8d5f35830ce 105 distance_per_line = 16;
FrankWeissenborn 0:c8d5f35830ce 106 }
FrankWeissenborn 0:c8d5f35830ce 107
FrankWeissenborn 0:c8d5f35830ce 108 WriteCommandByte(0x80 + line*distance_per_line + x);
FrankWeissenborn 0:c8d5f35830ce 109 }
FrankWeissenborn 0:c8d5f35830ce 110
FrankWeissenborn 0:c8d5f35830ce 111 /** Write a character at the current position
FrankWeissenborn 0:c8d5f35830ce 112 *
FrankWeissenborn 0:c8d5f35830ce 113 * @param character character
FrankWeissenborn 0:c8d5f35830ce 114 */
FrankWeissenborn 0:c8d5f35830ce 115 void DogM16x::WriteCharacter(char character) {
FrankWeissenborn 0:c8d5f35830ce 116
FrankWeissenborn 0:c8d5f35830ce 117 WriteDataByte(character);
FrankWeissenborn 0:c8d5f35830ce 118
FrankWeissenborn 0:c8d5f35830ce 119 }
FrankWeissenborn 0:c8d5f35830ce 120
FrankWeissenborn 0:c8d5f35830ce 121 /** Write a character at position (x,line)
FrankWeissenborn 0:c8d5f35830ce 122 *
FrankWeissenborn 0:c8d5f35830ce 123 * @param character character
FrankWeissenborn 0:c8d5f35830ce 124 * @param x x-position (starting with 0)
FrankWeissenborn 0:c8d5f35830ce 125 * @param line
FrankWeissenborn 0:c8d5f35830ce 126 */
FrankWeissenborn 0:c8d5f35830ce 127 void DogM16x::WriteCharacter(char character,unsigned char x, DogM16x_LINE line) {
FrankWeissenborn 0:c8d5f35830ce 128 SetPosition(x,line);
FrankWeissenborn 0:c8d5f35830ce 129 WriteCharacter(character);
FrankWeissenborn 0:c8d5f35830ce 130 }
FrankWeissenborn 0:c8d5f35830ce 131
FrankWeissenborn 0:c8d5f35830ce 132 /** Write a null terminated string at the current position
FrankWeissenborn 0:c8d5f35830ce 133 *
FrankWeissenborn 0:c8d5f35830ce 134 * @param string string
FrankWeissenborn 0:c8d5f35830ce 135 */
FrankWeissenborn 0:c8d5f35830ce 136 void DogM16x::WriteString(char* string) {
FrankWeissenborn 0:c8d5f35830ce 137
FrankWeissenborn 0:c8d5f35830ce 138 _rs = 1;
FrankWeissenborn 0:c8d5f35830ce 139
FrankWeissenborn 0:c8d5f35830ce 140 while (string[0] != 0x00) {
FrankWeissenborn 0:c8d5f35830ce 141 wait_us(30);
FrankWeissenborn 0:c8d5f35830ce 142 SetData(string[0]);
FrankWeissenborn 0:c8d5f35830ce 143 string++;
FrankWeissenborn 0:c8d5f35830ce 144 }
FrankWeissenborn 0:c8d5f35830ce 145 }
FrankWeissenborn 0:c8d5f35830ce 146
FrankWeissenborn 0:c8d5f35830ce 147 /** Write a null terminated string at position (x,line)
FrankWeissenborn 0:c8d5f35830ce 148 *
FrankWeissenborn 0:c8d5f35830ce 149 * @param string string
FrankWeissenborn 0:c8d5f35830ce 150 * @param x x-position (starting with 0)
FrankWeissenborn 0:c8d5f35830ce 151 * @param line (LINE_1, LINE_2 or LINE3)
FrankWeissenborn 0:c8d5f35830ce 152 */
FrankWeissenborn 0:c8d5f35830ce 153 void DogM16x::WriteString(char* string, unsigned char x, DogM16x_LINE line) {
FrankWeissenborn 0:c8d5f35830ce 154 SetPosition(x,line);
FrankWeissenborn 0:c8d5f35830ce 155 WriteString(string);
FrankWeissenborn 0:c8d5f35830ce 156 }
FrankWeissenborn 0:c8d5f35830ce 157