Library to drive DogM16x text displays

Committer:
FrankWeissenborn
Date:
Fri Jan 28 07:31:58 2011 +0000
Revision:
3:fb071acba88f
Parent:
2:5c2b562c9875
fix DOGM char* -> const char*

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