DAS
Embed:
(wiki syntax)
Show/hide line numbers
SeeedGrayOLED.cpp
00001 /* 00002 * SeeedGrayOLED.cpp 00003 * SSD1327 Gray OLED Driver Library 00004 * 00005 * Copyright (c) 2011 seeed technology inc. 00006 * Author : Visweswara R 00007 * Create Time : Dec 2011 00008 * Change Log : 00009 * 00010 * This library is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU Lesser General Public 00012 * License as published by the Free Software Foundation; either 00013 * version 2.1 of the License, or (at your option) any later version. 00014 * 00015 * This library is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 * Lesser General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Lesser General Public 00021 * License along with this library; if not, write to the Free Software 00022 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00023 */ 00024 00025 // #include "Arduino.h" 00026 //#include "Wire.h" 00027 #include "SeeedGrayOLED.h" 00028 //#include <pgmspace.h> 00029 00030 #if defined(__arm__) && !defined(PROGMEM) 00031 #define PROGMEM 00032 #define pgm_read_byte(STR) STR 00033 #endif 00034 00035 I2C i2c_oled(PB_9, PB_8); 00036 //(sda,scl) 00037 00038 // 8x8 Font ASCII 32 - 127 Implemented 00039 // Users can modify this to support more characters(glyphs) 00040 // BasicFont is placed in code memory. 00041 00042 // This font can be freely used without any restriction(It is placed in public domain) 00043 const unsigned char zifu[][16]PROGMEM= 00044 { 00045 00046 {0x01,0x00,0x00,0xFF,0x00,0x00,0x00,0xF9,0x49,0x49,0x49,0x49,0x49,0xF9,0x00,0x00}, 00047 {0x00,0x80,0x60,0xF8,0x07,0x00,0x04,0x24,0x24,0x25,0x26,0x24,0x24,0x24,0x04,0x00},/*"信",0*/ 00048 00049 }; 00050 00051 const unsigned char BasicFont[][8]PROGMEM= 00052 { 00053 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 00054 {0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00}, 00055 {0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00}, 00056 {0x00,0x14,0x7F,0x14,0x7F,0x14,0x00,0x00}, 00057 {0x00,0x24,0x2A,0x7F,0x2A,0x12,0x00,0x00}, 00058 {0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00}, 00059 {0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00}, 00060 {0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00}, 00061 {0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00}, 00062 {0x00,0x41,0x22,0x1C,0x00,0x00,0x00,0x00}, 00063 {0x00,0x08,0x2A,0x1C,0x2A,0x08,0x00,0x00}, 00064 {0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00}, 00065 {0x00,0xA0,0x60,0x00,0x00,0x00,0x00,0x00}, 00066 {0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00}, 00067 {0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00}, 00068 {0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00}, 00069 {0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00}, 00070 {0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00}, 00071 {0x00,0x62,0x51,0x49,0x49,0x46,0x00,0x00}, 00072 {0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00}, 00073 {0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00}, 00074 {0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00}, 00075 {0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00}, 00076 {0x00,0x01,0x71,0x09,0x05,0x03,0x00,0x00}, 00077 {0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00}, 00078 {0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00}, 00079 {0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00}, 00080 {0x00,0x00,0xAC,0x6C,0x00,0x00,0x00,0x00}, 00081 {0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00}, 00082 {0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00}, 00083 {0x00,0x41,0x22,0x14,0x08,0x00,0x00,0x00}, 00084 {0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00}, 00085 {0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00}, 00086 {0x00,0x7E,0x09,0x09,0x09,0x7E,0x00,0x00}, 00087 {0x00,0x7F,0x49,0x49,0x49,0x36,0x00,0x00}, 00088 {0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00}, 00089 {0x00,0x7F,0x41,0x41,0x22,0x1C,0x00,0x00}, 00090 {0x00,0x7F,0x49,0x49,0x49,0x41,0x00,0x00}, 00091 {0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00}, 00092 {0x00,0x3E,0x41,0x41,0x51,0x72,0x00,0x00}, 00093 {0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00}, 00094 {0x00,0x41,0x7F,0x41,0x00,0x00,0x00,0x00}, 00095 {0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00}, 00096 {0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00}, 00097 {0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00}, 00098 {0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00}, 00099 {0x00,0x7F,0x04,0x08,0x10,0x7F,0x00,0x00}, 00100 {0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00}, 00101 {0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00}, 00102 {0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00}, 00103 {0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00}, 00104 {0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00}, 00105 {0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00}, 00106 {0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00}, 00107 {0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00}, 00108 {0x00,0x3F,0x40,0x38,0x40,0x3F,0x00,0x00}, 00109 {0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00}, 00110 {0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x00}, 00111 {0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00}, 00112 {0x00,0x7F,0x41,0x41,0x00,0x00,0x00,0x00}, 00113 {0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00}, 00114 {0x00,0x41,0x41,0x7F,0x00,0x00,0x00,0x00}, 00115 {0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00}, 00116 {0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00}, 00117 {0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00}, 00118 {0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00}, 00119 {0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00}, 00120 {0x00,0x38,0x44,0x44,0x28,0x00,0x00,0x00}, 00121 {0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00}, 00122 {0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00}, 00123 {0x00,0x08,0x7E,0x09,0x02,0x00,0x00,0x00}, 00124 {0x00,0x18,0xA4,0xA4,0xA4,0x7C,0x00,0x00}, 00125 {0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00}, 00126 {0x00,0x00,0x7D,0x00,0x00,0x00,0x00,0x00}, 00127 {0x00,0x80,0x84,0x7D,0x00,0x00,0x00,0x00}, 00128 {0x00,0x7F,0x10,0x28,0x44,0x00,0x00,0x00}, 00129 {0x00,0x41,0x7F,0x40,0x00,0x00,0x00,0x00}, 00130 {0x00,0x7C,0x04,0x18,0x04,0x78,0x00,0x00}, 00131 {0x00,0x7C,0x08,0x04,0x7C,0x00,0x00,0x00}, 00132 {0x00,0x38,0x44,0x44,0x38,0x00,0x00,0x00}, 00133 {0x00,0xFC,0x24,0x24,0x18,0x00,0x00,0x00}, 00134 {0x00,0x18,0x24,0x24,0xFC,0x00,0x00,0x00}, 00135 {0x00,0x00,0x7C,0x08,0x04,0x00,0x00,0x00}, 00136 {0x00,0x48,0x54,0x54,0x24,0x00,0x00,0x00}, 00137 {0x00,0x04,0x7F,0x44,0x00,0x00,0x00,0x00}, 00138 {0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00}, 00139 {0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00}, 00140 {0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00}, 00141 {0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00}, 00142 {0x00,0x1C,0xA0,0xA0,0x7C,0x00,0x00,0x00}, 00143 {0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00}, 00144 {0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x00}, 00145 {0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00}, 00146 {0x00,0x41,0x36,0x08,0x00,0x00,0x00,0x00}, 00147 {0x00,0x02,0x01,0x01,0x02,0x01,0x00,0x00}, 00148 {0x00,0x02,0x05,0x05,0x02,0x00,0x00,0x00} 00149 }; 00150 00151 00152 void SeeedGrayOLED::drawzifu(unsigned char Row1, unsigned char Column,const unsigned char *bitmaparray,int bytes) 00153 { 00154 if(Drive_IC == SSD1327) 00155 { 00156 char localAddressMode = addressingMode; 00157 if(addressingMode != HORIZONTAL_MODE) 00158 { 00159 //Bitmap is drawn in horizontal mode 00160 setHorizontalMode(); 00161 } 00162 00163 for(int i=0;i<bytes;i++) 00164 { 00165 00166 for(int j=0;j<8;j=j+2) 00167 { 00168 char c=0x00; 00169 char bit1 = bitmaparray[i] << j & 0x80; 00170 char bit2 = bitmaparray[i] << (j+1) & 0x80; 00171 00172 // Each bit is changed to a nibble 00173 c|=(bit1)?grayH:0x00; 00174 // Each bit is changed to a nibble 00175 c|=(bit2)?grayL:0x00; 00176 sendData(c); 00177 } 00178 } 00179 if(localAddressMode == VERTICAL_MODE) 00180 { 00181 //If Vertical Mode was used earlier, restore it. 00182 setVerticalMode(); 00183 } 00184 } 00185 else if(Drive_IC == SH1107G) 00186 { 00187 int Row = 0,column_l = 0x00, column_h = 0x11; 00188 setHorizontalMode(); 00189 for(int i=0;i<bytes;i++) 00190 { 00191 sendCommand(0xb0 + Row1*2 +Row); 00192 sendCommand(column_l); 00193 sendCommand(column_h + Column); 00194 //sendCommand(0xA7); 00195 00196 // byte bits = (byte)pgm_read_byte(&bitmaparray[i]); 00197 // byte tmp = 0x00; 00198 00199 char bits = bitmaparray[i]; 00200 char tmp = 0x00; 00201 00202 for(int b = 0; b < 8; b++) 00203 { 00204 // tmp |= ((bits>>(7-b))&0x01)<<b; 00205 tmp |= ((bits>>(7-b))&0x01)<<b; 00206 } 00207 // sendData(tmp); 00208 sendData(tmp); 00209 00210 Row++; 00211 if(Row >= 2){ 00212 Row = 0; 00213 column_l++; 00214 if(column_l >= 16){ 00215 column_l = 0x00; 00216 column_h += 0x01; 00217 } 00218 } 00219 } 00220 } 00221 00222 } 00223 00224 void SeeedGrayOLED::putzifu(unsigned char C) 00225 { 00226 if(C < 32 || C > 127) //Ignore non-printable ASCII characters. This can be modified for multilingual font. 00227 { 00228 C=' '; //Space 00229 } 00230 00231 if(Drive_IC == SSD1327) 00232 { 00233 for(char i=0;i<8;i=i+2) 00234 { 00235 for(char j=0;j<8;j++) 00236 { 00237 // Character is constructed two pixel at a time using vertical mode from the default 8x8 font 00238 char c=0x00; 00239 char bit1= (BasicFont[C-32][i] >> j) & 0x01; 00240 char bit2= (BasicFont[C-32][i+1] >> j) & 0x01; 00241 // Each bit is changed to a nibble 00242 c|=(bit1)?grayH:0x00; 00243 c|=(bit2)?grayL:0x00; 00244 00245 sendData(c); 00246 } 00247 } 00248 } 00249 else if(Drive_IC == SH1107G) 00250 { 00251 for(int i=0;i<16;i++) 00252 { 00253 00254 sendData(zifu[C-48][i]); //font array starts at 0, ASCII starts at 32. Hence the translation 00255 00256 //read bytes from code memory 00257 } 00258 } 00259 } 00260 00261 void SeeedGrayOLED::setzifuXY(unsigned char Row, unsigned char Column) 00262 { 00263 if(Drive_IC == SSD1327) 00264 { 00265 //Column Address 00266 sendCommand(0x15); /* Set Column Address */ 00267 sendCommand(0x08+(Column*4)); /* Start Column: Start from 8 */ 00268 sendCommand(0x37); /* End Column */ 00269 // Row Address 00270 sendCommand(0x75); /* Set Row Address */ 00271 sendCommand(0x00+(Row*8)); /* Start Row*/ 00272 sendCommand(0x07+(Row*8)); /* End Row*/ 00273 } 00274 else if(Drive_IC == SH1107G) 00275 { 00276 uint8_t col_l; 00277 00278 Column%2 ? col_l = 0x10 : col_l = 0x00; 00279 sendCommand(0xb0+Row); 00280 sendCommand(col_l); 00281 sendCommand(0x11+(Column/2)); 00282 } 00283 } 00284 00285 void SeeedGrayOLED::init(int IC) 00286 { 00287 Drive_IC = IC; 00288 if(Drive_IC == SSD1327) 00289 { 00290 sendCommand(0xFD); // Unlock OLED driver IC MCU interface from entering command. i.e: Accept commands 00291 sendCommand(0x12); 00292 sendCommand(0xAE); // Set display off 00293 sendCommand(0xA8); // set multiplex ratio 00294 sendCommand(0x5F); // 96 00295 sendCommand(0xA1); // set display start line 00296 sendCommand(0x00); 00297 sendCommand(0xA2); // set display offset 00298 sendCommand(0x60); 00299 sendCommand(0xA0); // set remap 00300 sendCommand(0x46); 00301 sendCommand(0xAB); // set vdd internal 00302 sendCommand(0x01); // 00303 sendCommand(0x81); // set contrasr 00304 sendCommand(0x53); // 100 nit 00305 sendCommand(0xB1); // Set Phase Length 00306 sendCommand(0X51); // 00307 sendCommand(0xB3); // Set Display Clock Divide Ratio/Oscillator Frequency 00308 sendCommand(0x01); 00309 sendCommand(0xB9); // 00310 sendCommand(0xBC); // set pre_charge voltage/VCOMH 00311 sendCommand(0x08); // (0x08); 00312 sendCommand(0xBE); // set VCOMH 00313 sendCommand(0X07); // (0x07); 00314 sendCommand(0xB6); // Set second pre-charge period 00315 sendCommand(0x01); // 00316 sendCommand(0xD5); // enable second precharge and enternal vsl 00317 sendCommand(0X62); // (0x62); 00318 sendCommand(0xA4); // Set Normal Display Mode 00319 sendCommand(0x2E); // Deactivate Scroll 00320 sendCommand(0xAF); // Switch on display 00321 wait(0.1); 00322 00323 // Row Address 00324 sendCommand(0x75); // Set Row Address 00325 sendCommand(0x00); // Start 0 00326 sendCommand(0x5f); // End 95 00327 00328 00329 // Column Address 00330 sendCommand(0x15); // Set Column Address 00331 sendCommand(0x08); // Start from 8th Column of driver IC. This is 0th Column for OLED 00332 sendCommand(0x37); // End at (8 + 47)th column. Each Column has 2 pixels(segments) 00333 00334 // Init gray level for text. Default:Brightest White 00335 grayH= 0xF0; 00336 grayL= 0x0F; 00337 } 00338 else if (Drive_IC ==SH1107G) 00339 { 00340 sendCommand(0xae); //Display OFF 00341 sendCommand(0xd5); // Set Dclk 00342 sendCommand(0x50); // 100Hz 00343 sendCommand(0x20); // Set row address 00344 sendCommand(0x81); // Set contrast control 00345 sendCommand(0x80); 00346 sendCommand(0xa0); // Segment remap 00347 sendCommand(0xa4); // Set Entire Display ON 00348 sendCommand(0xa6); // Normal display 00349 sendCommand(0xad); // Set external VCC 00350 sendCommand(0x80); 00351 sendCommand(0xc0); // Set Common scan direction 00352 sendCommand(0xd9); // Set phase leghth 00353 sendCommand(0x1f); 00354 sendCommand(0xdb); // Set Vcomh voltage 00355 sendCommand(0x27); 00356 sendCommand(0xaf); //Display ON 00357 sendCommand(0xb0); 00358 sendCommand(0x00); 00359 sendCommand(0x11); 00360 } 00361 } 00362 00363 00364 void SeeedGrayOLED::sendCommand(unsigned char command) 00365 { 00366 // Wire.beginTransmission(SeeedGrayOLED_Address); // begin I2C communication 00367 // Wire.write(SeeedGrayOLED_Command_Mode); // Set OLED Command mode 00368 // Wire.write(command); 00369 // Wire.endTransmission(); // End I2C communication 00370 char cmd[2]; 00371 cmd[0] = SeeedGrayOLED_Command_Mode; 00372 cmd[1] = command; 00373 00374 i2c_oled.write(SeeedGrayOLED_Address, cmd, 2); 00375 00376 } 00377 00378 void SeeedGrayOLED::setContrastLevel(unsigned char ContrastLevel) 00379 { 00380 sendCommand(SeeedGrayOLED_Set_ContrastLevel_Cmd); 00381 sendCommand(ContrastLevel); 00382 } 00383 00384 void SeeedGrayOLED::setHorizontalMode() 00385 { 00386 if(Drive_IC == SSD1327) 00387 { 00388 sendCommand(0xA0); // remap to 00389 sendCommand(0x42); // horizontal mode 00390 00391 // Row Address 00392 sendCommand(0x75); // Set Row Address 00393 sendCommand(0x00); // Start 0 00394 sendCommand(0x5f); // End 95 00395 00396 // Column Address 00397 sendCommand(0x15); // Set Column Address 00398 sendCommand(0x08); // Start from 8th Column of driver IC. This is 0th Column for OLED 00399 sendCommand(0x37); // End at (8 + 47)th column. Each Column has 2 pixels(or segments) 00400 } 00401 else if(Drive_IC == SH1107G) 00402 { 00403 sendCommand(0xA0); 00404 sendCommand(0xC8); 00405 } 00406 } 00407 00408 void SeeedGrayOLED::setVerticalMode() 00409 { 00410 if(Drive_IC == SSD1327) 00411 { 00412 sendCommand(0xA0); // remap to 00413 sendCommand(0x46); // Vertical mode 00414 } 00415 else if(Drive_IC == SH1107G) 00416 { 00417 sendCommand(0xA0); 00418 sendCommand(0xC0); 00419 } 00420 } 00421 00422 void SeeedGrayOLED::setTextXY(unsigned char Row, unsigned char Column) 00423 { 00424 if(Drive_IC == SSD1327) 00425 { 00426 //Column Address 00427 sendCommand(0x15); /* Set Column Address */ 00428 sendCommand(0x08+(Column*4)); /* Start Column: Start from 8 */ 00429 sendCommand(0x37); /* End Column */ 00430 // Row Address 00431 sendCommand(0x75); /* Set Row Address */ 00432 sendCommand(0x00+(Row*8)); /* Start Row*/ 00433 sendCommand(0x07+(Row*8)); /* End Row*/ 00434 } 00435 else if(Drive_IC == SH1107G) 00436 { 00437 uint8_t col_l; 00438 00439 Column%2 ? col_l = 0x08 : col_l = 0x00; 00440 sendCommand(0xb0+Row); 00441 sendCommand(col_l); 00442 sendCommand(0x11+(Column/2)); 00443 } 00444 } 00445 00446 void SeeedGrayOLED::clearDisplay() 00447 { 00448 unsigned char i,j; 00449 00450 if(Drive_IC == SSD1327) 00451 { 00452 for(j=0;j<48;j++) 00453 { 00454 for(i=0;i<96;i++) //clear all columns 00455 { 00456 sendData(0x00); 00457 } 00458 } 00459 } 00460 else if(Drive_IC == SH1107G) 00461 { 00462 for(i=0; i<16;i++){ 00463 sendCommand(0xb0+i); 00464 sendCommand(0x0); 00465 sendCommand(0x10); 00466 for(j=0; j<128;j++){ 00467 sendData(0x00); 00468 } 00469 } 00470 } 00471 00472 } 00473 00474 void SeeedGrayOLED::sendData(unsigned char Data) 00475 { 00476 // Wire.beginTransmission(SeeedGrayOLED_Address); // begin I2C transmission 00477 // Wire.write(SeeedGrayOLED_Data_Mode); // data mode 00478 // Wire.write(Data); 00479 // Wire.endTransmission(); // stop I2C transmission 00480 char cmd[2]; 00481 cmd[0] = SeeedGrayOLED_Data_Mode; 00482 cmd[1] = Data; 00483 00484 i2c_oled.write(SeeedGrayOLED_Address, cmd, 2); 00485 } 00486 00487 void SeeedGrayOLED::setGrayLevel(unsigned char grayLevel) 00488 { 00489 grayH = (grayLevel << 4) & 0xF0; 00490 grayL = grayLevel & 0x0F; 00491 } 00492 00493 void SeeedGrayOLED::putChar(unsigned char C) 00494 { 00495 if(C < 32 || C > 127) //Ignore non-printable ASCII characters. This can be modified for multilingual font. 00496 { 00497 C=' '; //Space 00498 } 00499 00500 if(Drive_IC == SSD1327) 00501 { 00502 for(char i=0;i<8;i=i+2) 00503 { 00504 for(char j=0;j<8;j++) 00505 { 00506 // Character is constructed two pixel at a time using vertical mode from the default 8x8 font 00507 char c=0x00; 00508 char bit1= (BasicFont[C-32][i] >> j) & 0x01; 00509 char bit2= (BasicFont[C-32][i+1] >> j) & 0x01; 00510 // Each bit is changed to a nibble 00511 c|=(bit1)?grayH:0x00; 00512 c|=(bit2)?grayL:0x00; 00513 00514 sendData(c); 00515 } 00516 } 00517 } 00518 else if(Drive_IC == SH1107G) 00519 { 00520 for(int i=0;i<8;i++) 00521 { 00522 //read bytes from code memory 00523 sendData(BasicFont[C-32][i]); //font array starts at 0, ASCII starts at 32. Hence the translation 00524 } 00525 } 00526 } 00527 00528 00529 00530 void SeeedGrayOLED::putString(const char *String) 00531 { 00532 unsigned char i=0; 00533 while(String[i]) 00534 { 00535 putChar(String[i]); 00536 i++; 00537 } 00538 } 00539 00540 unsigned char SeeedGrayOLED::putNumber(long long_num) 00541 { 00542 unsigned char char_buffer[10]=""; 00543 unsigned char i = 0; 00544 unsigned char f = 0; 00545 00546 if (long_num < 0) 00547 { 00548 f=1; 00549 putChar('-'); 00550 long_num = -long_num; 00551 } 00552 else if (long_num == 0) 00553 { 00554 f=1; 00555 putChar('0'); 00556 return f; 00557 } 00558 00559 while (long_num > 0) 00560 { 00561 char_buffer[i++] = long_num % 10; 00562 long_num /= 10; 00563 } 00564 00565 f=f+i; 00566 for(; i > 0; i--) 00567 { 00568 putChar('0'+ char_buffer[i - 1]); 00569 } 00570 return f; 00571 00572 } 00573 00574 00575 00576 void SeeedGrayOLED::drawBitmap(const unsigned char *bitmaparray,int bytes) 00577 { 00578 if(Drive_IC == SSD1327) 00579 { 00580 char localAddressMode = addressingMode; 00581 if(addressingMode != HORIZONTAL_MODE) 00582 { 00583 //Bitmap is drawn in horizontal mode 00584 setHorizontalMode(); 00585 } 00586 00587 for(int i=0;i<bytes;i++) 00588 { 00589 00590 for(int j=0;j<8;j=j+2) 00591 { 00592 char c=0x00; 00593 char bit1 = bitmaparray[i] << j & 0x80; 00594 char bit2 = bitmaparray[i] << (j+1) & 0x80; 00595 00596 // Each bit is changed to a nibble 00597 c|=(bit1)?grayH:0x00; 00598 // Each bit is changed to a nibble 00599 c|=(bit2)?grayL:0x00; 00600 sendData(c); 00601 } 00602 } 00603 if(localAddressMode == VERTICAL_MODE) 00604 { 00605 //If Vertical Mode was used earlier, restore it. 00606 setVerticalMode(); 00607 } 00608 } 00609 else if(Drive_IC == SH1107G) 00610 { 00611 int Row = 0, column_l = 0x00, column_h = 0x11; 00612 setHorizontalMode(); 00613 for(int i=0;i<bytes;i++) 00614 { 00615 sendCommand(0xb0 + Row); 00616 sendCommand(column_l); 00617 sendCommand(column_h); 00618 // byte bits = (byte)pgm_read_byte(&bitmaparray[i]); 00619 // byte tmp = 0x00; 00620 char bits = bitmaparray[i]; 00621 char tmp = 0x00; 00622 for(int b = 0; b < 8; b++) 00623 { 00624 // tmp |= ((bits>>(7-b))&0x01)<<b; 00625 tmp |= ((bits>>(7-b))&0x01)<<b; 00626 } 00627 // sendData(tmp); 00628 sendData(tmp); 00629 Row++; 00630 if(Row >= 12) 00631 { 00632 Row = 0; 00633 column_l++; 00634 if(column_l >= 16) 00635 { 00636 column_l = 0x00; 00637 column_h += 0x01; 00638 } 00639 } 00640 } 00641 } 00642 00643 } 00644 00645 void SeeedGrayOLED::setHorizontalScrollProperties(bool direction,unsigned char startRow, unsigned char endRow,unsigned char startColumn, unsigned char endColumn, unsigned char scrollSpeed) 00646 { 00647 /* 00648 Use the following defines for 'direction' : 00649 00650 Scroll_Left 00651 Scroll_Right 00652 00653 Use the following defines for 'scrollSpeed' : 00654 00655 Scroll_2Frames 00656 Scroll_3Frames 00657 Scroll_4Frames 00658 Scroll_5Frames 00659 Scroll_25Frames 00660 Scroll_64Frames 00661 Scroll_128Frames 00662 Scroll_256Frames 00663 00664 */ 00665 00666 if(Scroll_Right == direction) 00667 { 00668 //Scroll Right 00669 sendCommand(0x27); 00670 } 00671 else 00672 { 00673 //Scroll Left 00674 sendCommand(0x26); 00675 } 00676 sendCommand(0x00); //Dummmy byte 00677 sendCommand(startRow); 00678 sendCommand(scrollSpeed); 00679 sendCommand(endRow); 00680 sendCommand(startColumn+8); 00681 sendCommand(endColumn+8); 00682 sendCommand(0x00); //Dummmy byte 00683 00684 } 00685 00686 void SeeedGrayOLED::activateScroll() 00687 { 00688 sendCommand(SeeedGrayOLED_Activate_Scroll_Cmd); 00689 } 00690 00691 void SeeedGrayOLED::deactivateScroll() 00692 { 00693 sendCommand(SeeedGrayOLED_Dectivate_Scroll_Cmd); 00694 } 00695 00696 void SeeedGrayOLED::setNormalDisplay() 00697 { 00698 sendCommand(SeeedGrayOLED_Normal_Display_Cmd); 00699 } 00700 00701 void SeeedGrayOLED::setInverseDisplay() 00702 { 00703 sendCommand(SeeedGrayOLED_Inverse_Display_Cmd); 00704 } 00705 SeeedGrayOLED SeeedGrayOled; // Preinstantiate Objects
Generated on Mon Jul 18 2022 00:03:35 by
1.7.2