Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
MCC0G42005A6W.h
00001 #ifndef _MCC0G42005A6W_H 00002 #define _MCC0G42005A6W_H 00003 00004 #include <stdarg.h> 00005 #include "mbed.h" 00006 #include "MCC0G42005A6W.h" 00007 00008 /** 00009 * LCD example 00010 * 00011 * @code 00012 * #include <stdarg.h> 00013 * #include "mbed.h" 00014 * #include "MCC0G42005A6W.h" 00015 * 00016 * // MCCOG42005A6W-BNMLWI 00017 * // Alphanumeric LCD, 20 x 4, White on Blue, 3V to 5V, I2C, English, Japanese, Transmissive 00018 * // Farnell nr. 2218946 00019 * // example PCB LCD I2C 4x20 https://circuitmaker.com/User/Details/Rob-Keij-4 00020 * 00021 * LCD_COG lcd(SDA, SCL, "==LCD=Driver=V1.00=="); // SDA, SCL 00022 * 00023 * int main() 00024 * { 00025 * lcd.printf( 0, 0, "Hello world!" ); 00026 * lcd.printf( 4, 1, "pi = %.6f", 3.14159265 ); 00027 * lcd.printf( 2, 2, "This is Row %d",2 ); 00028 * lcd.printf( 3, 3, "This is Row %d",3 ); 00029 * 00030 * while(1) { 00031 * 00032 * } 00033 * } 00034 * @endcode 00035 */ 00036 00037 00038 class LCD_COG 00039 { 00040 public: 00041 00042 /** Create a LCD instance which is connected to specified I2C pins with specified address 00043 * 00044 * @param I2C_sda I2C-bus SDA pin 00045 * @param I2C_scl I2C-bus SCL pin 00046 * @param init_message string to initialize the LCD 00047 */ 00048 LCD_COG( PinName I2C_sda, PinName I2C_scl, const char *init_message = NULL ); 00049 00050 /** Create a LCD instance connected to specified I2C pins with specified address 00051 * 00052 * @param I2C object (instance) 00053 * @param init_message string to initialize the LCD 00054 */ 00055 LCD_COG( I2C &i2c_, const char* init_message = NULL ); 00056 00057 /** Destructor 00058 */ 00059 ~LCD_COG(); 00060 00061 /** Printf 00062 * 00063 * printf function with line number. 00064 * it can be used like 00065 * 00066 * lcd.printf( 0, "Hello world!" ); 00067 * lcd.printf( 1, "pi = %.6f", 3.14159265 ); 00068 * lcd.printf( 2, "This is Row %d",2 ); 00069 * lcd.printf( 3, "This is Row %d",3 ); 00070 * 00071 * @param line line# (0 for upper, 1 for lower) 00072 * @param format following parameters are compatible to stdout's printf 00073 */ 00074 void printf( char line, const char *format, ... ); 00075 00076 /** Printf 00077 * 00078 * printf function with X and Y character position on the LCD. 00079 * it can be used like 00080 * 00081 * lcd.printf( 0, 0, "Hello world!" ); 00082 * lcd.printf( 4, 1, "pi = %.6f", 3.14159265 ); 00083 * lcd.printf( 2, 2, "This is Row %d",2 ); 00084 * lcd.printf( 3, 3, "This is Row %d",3 ); 00085 * 00086 * @param x X horizontal character position on the LCD 00087 * @param y Y vertical character position on the LCD 00088 * @param format following parameters are compatible to stdout's printf 00089 */ 00090 void printf( char x, unsigned char y, const char *format, ... ); 00091 00092 /** Put character : "putc()" 00093 * 00094 * @param line line# (0 for upper, 1 for lower) 00095 * @param c character code 00096 */ 00097 void putc( unsigned char line, char c ); 00098 00099 /** Put string : "puts()" 00100 * 00101 * @param line line# (0 for upper, 1 for lower) 00102 * @param s pointer to a string data 00103 */ 00104 void puts( char line, const char *s ); 00105 00106 /** Put character into specified screen position 00107 * 00108 * @param c character code 00109 * @param x horizontal character position on the LCD 00110 * @param y vertical character position on the LCD 00111 */ 00112 void putcxy( char c, unsigned char x, unsigned char y ); 00113 00114 /** Clear the LCD 00115 */ 00116 void clear( void ); 00117 00118 /** Contrast adjustment 00119 * 00120 * @param contrast value (from 0x00 to 0x3E) 00121 */ 00122 void contrast( char contrast ); 00123 00124 /** Put a custom character given as bitmap data 00125 * 00126 * @param c_code character code 00127 * @param cg pointer to bitmap data (array of 8 bytes) 00128 * @param x horizontal character position on the LCD 00129 * @param y vertical character position on the LCD 00130 */ 00131 void put_custom_char( char c_code, const char *cg, char x, char y ); 00132 00133 /** Set CGRAM (set custom bitmap as a character) 00134 * 00135 * @param c_code character code 00136 * @param cg pointer to bitmap data (array of 8 bytes) 00137 */ 00138 void set_CGRAM( char char_code, const char* cg ); 00139 00140 /** Set CGRAM (set custom bitmap as a character) 00141 * 00142 * @param c_code character code 00143 * @param v bitmap data (5 bit pattern in this variable are copied to all row of a character bitmap) 00144 */ 00145 void set_CGRAM( char char_code, char v ); 00146 00147 00148 /** Set number of characters in a line 00149 * 00150 * @param ch number of charactors in a line 00151 */ 00152 void setCharsInLine( char ch ) 00153 { 00154 charsInLine = ch; 00155 }; 00156 00157 private: 00158 00159 typedef enum { 00160 00161 SLAVEADRESS = 0x78, 00162 LINES = 4, 00163 LCD_HOME_L1 = 0x80, 00164 LINE1 = 0x00, 00165 LINE2 = LINE1+0x20, 00166 LINE3 = LINE1+0x40, 00167 LINE4 = LINE1+0x60, 00168 00169 DISPLAY_ON = 0x04, 00170 DISPLAY_OFF = 0x03, 00171 CURSOR_ON = 0x02, 00172 CURSOR_OFF = 0x05, 00173 BLINK_ON = 0x01, 00174 BLINK_OFF = 0x06, 00175 00176 TOPVIEW = 0x05, 00177 BOTTOMVIEW = 0x06, 00178 00179 ROMA = 0x00, 00180 ROMB = 0x04, 00181 ROMC = 0x0C, 00182 00183 Comm_FunctionSet_Normal = 0x38, 00184 Comm_FunctionSet_Extended = 0x39, 00185 Comm_InternalOscFrequency = 0x14, 00186 Comm_DisplayOnOff = 0x0C, 00187 Comm_ClearDisplay = 0x01, 00188 Comm_ReturnHome = 0x02, 00189 Comm_ContrastSet = 0x70, 00190 Comm_PwrIconContrast = 0x5C, 00191 Comm_FollowerCtrl = 0x60, 00192 Comm_EntryModeSet = 0x04, 00193 Comm_SetCGRAM = 0x40 00194 00195 00196 //Instruction IS RE RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 Description 00197 //Clear display XX00 0 0 0 0 0 0 0 1 Write "20H" to DDRAM. and set DDRAM address to "00H" from AC. 00198 //Comm_ClearDisplay = 0x01, 00199 // 00200 //Return home X000 0 0 0 0 0 0 1 X Set DDRAM address to "00H" from AC and return cursor to its original position if shifted. The contents of DDRAM are not changed. 00201 //Comm_ReturnHome = 0x02, 00202 // 00203 //Power down mode X100 0 0 0 0 0 0 1 PD Set power down mode bit. PD = "1": power down mode set, PD = "0": power down mode disable (POR) 00204 // 00205 //Entry mode set X000 0 0 0 0 0 1 I/D S Assign cursor/ blink moving direction with DDRAM address I/D = "1": cursor/ blink moves to right 00206 // and DDRAM address is increased by 1 (POR) 00207 // I/D = "0": cursor/ blink moves to left and DDRAM address is decreased by 1 00208 // Assign display shift with DDRAM address S = "1": make display shift of the enabled lines by the DS4 to DS1 bits in the shift enable instruction. 00209 // Left/right direction depends on I/D bit selection. S = "0": display shift disable (POR) 00210 // 00211 // X100 0 0 0 0 0 1 BDC BDS Segment bi-direction function. 00212 // BDS = "0": Seg100 -> Seg1, 00213 // BDS = "1": Seg1 -> Seg100. 00214 // Segment bi-direction function. 00215 // BDC = "0": Com32 -> Com1 00216 // BDC = "1": Com1 -> Com32 00217 // 00218 //Display On/Off control X000 0 0 0 0 1 D C B Set display/cursor/blink on/off 00219 //Comm_DisplayOnOff = 0x0C, // 0000 1100 00220 // D = "1": display on, 00221 // D = "0": display off (POR), 00222 // C = "1": cursor on, 00223 // C = "0": cursor off (POR), 00224 // B = "1": blink on, 00225 // B = "0": blink off (POR). 00226 // 00227 //Extended function set X100 0 0 0 0 1 FW B/W NW Assign font width, black/white inverting of cursor, and 4-line display mode control bit. 00228 // FW = "1": 6-dot font width, 00229 // FW = "0": 5-dot font width (POR), 00230 // B/W = "1": black/white inverting of cursor enable, 00231 // B/W = "0": black/white inverting of cursor disable (POR) 00232 // NW = "1": 3-line or 4-line display mode, 00233 // NW = "0": 1-line or 2-line display mode 00234 // 00235 //Cursor or display shift 0000 0 0 0 1 S/C R/L x x Set cursor moving and display shift control bit, and the direction, without changing DDRAM data. 00236 // S/C = "1": display shift, 00237 // S/C = "0": cursor shift, 00238 // R/L = "1": shift to right, 00239 // R/L = "0": shift to left. 00240 // 00241 //Double height(4-line)/ 0100 0 0 0 1 UD2 UD1 BS1 DH’ UD2~1: Assign different doubt height format (POR=11) 00242 //Bias/Display-dotshift BS1:BS0 = “00”: 1/5 bias (POR) 00243 // BS1:BS0 = “01”: 1/4 bias 00244 // BS1:BS0 = “10”: 1/7 bias 00245 // BS1:BS0 = “11”: 1/6 bias 00246 // DH’ = "1": display shift enable 00247 // DH’ = "0": dot scroll enable (POR) 00248 00249 00250 //Internal OSC frequency 1000 0 0 0 1 BS0 F2 F1 F0 F2~0: adjust internal OSC frequency for FE frequency (POR: 011) 00251 //Comm_InternalOscFrequency = 0x14, 00252 // 00253 //Shiftenable 1100 0 0 0 1 DS4 DS3 DS2 DS1 (when DH’ = "1") POR DS4~1=1111 Determine the line for display shift. 00254 // DS1 = "1/0": 1st line display shift enable/disable 00255 // DS2 = "1/0": 2nd line display shift enable/disable 00256 // DS3 = "1/0": 3rd line display shift enable/disable 00257 // DS4 = "1/0": 4th line display shift enable/disable. 00258 //Scroll enable 1100 0 0 0 1 HS4 HS3 HS2 HS1 (when DH’ = "0") POR HS4~1=1111 Determine the line for horizontal smooth scroll. 00259 // HS1 = "1/0": 1st line dot scroll enable/disable 00260 // HS2 = "1/0": 2nd line dot scroll enable/disable 00261 // HS3 = "1/0": 3rd line dot scroll enable/disable 00262 // HS4 = "1/0": 4th line dot scroll enable/disable. 00263 // 00264 //Function set X000 0 0 1 DL N DH RE(0) IS Set interface data length DL = "1": 8-bit (POR), 00265 // DL = "0": 4-bit 00266 // Numbers of display line N = "1": 2-line (NW=0)/ 4-line(NW=1), 00267 // N = "0": 1-line (NW=0)/ 3-line(NW=1) 00268 // Extension register, RE("0") at this instruction, RE must be "0". 00269 // Shift/scroll enable DH = “ 1/0”: Double height font control for 2-line mode enable/ disable (POR=0) 00270 // IS Special registers enable bit at this moment, must be "0". 00271 00272 00273 //Comm_FunctionSet_Normal = 0x3a, // 0011 1010 00274 //Comm_FunctionSet_Normal = 0x38, // 0011 1000 00275 00276 00277 // 00278 // 00279 // X100 0 0 1 DL N BE RE(1) REV Set DL, N, RE("1") CGRAM/SEGRAM blink enable BE = " 1/0": CGRAM/SEGRAM blink enable/disable (POR=0) 00280 // Reverse bit REV = "1": reverse display, REV = "0": normal display (POR). 00281 // 00282 //set CGRAM address 0000 0 1 AC5 AC4 AC3 AC2 AC1 AC0 Set CGRAM address in address counter. (POR=00 0000) 00283 00284 //set SEGRAM address 1000 0 1 0 0 AC3 AC2 AC1 AC0 Set SEGRAM address in address counter. (POR=0000) 00285 // 00286 //Power/ 00287 //Icon control/ 00288 //Contrast set 1000 0 1 0 1 Ion Bon C5 C4 Ion = “1/0”: ICON (SEGRAM) display on/off (POR=0) 00289 // Bon = “1/0”: set booster and regulator circuit on/off (POR=0) 00290 // C5, C4: Contrast set for internal follower mode (POR=10) 00291 // 00292 //Follower Control 1000 0 1 1 0 Don Rab2 Rab1 Rab0 Don: Set divider circuit on/ off (POR=0) 00293 // Rab2~0: Select Amplifier internal resistor ratio (POR=010) 00294 // 00295 //Contrast Set 1000 0 1 1 1 C3 C2 C1 C0 C3~0: Contrast set for internal follower mode (POR=0000) 00296 // 00297 //set DDRAM address X000 1 AC6 AC5 AC4 AC3 AC2 AC1 AC0 Set DDRAM address in address counter. (POR=000 0000) 00298 // 00299 //set scroll quantity X100 1 X SQ5 SQ4 SQ3 SQ2 SQ1 SQ0 Set the quantity of horizontal dot scroll. (POR=00 0000) 00300 // 00301 //Read busy flag and Can be known whether during internal operation or not by reading BF. 00302 //address/part ID XX01 BF AC6 AC5 AC4 AC3 AC2 AC1 AC0 The contents of address counter or the part ID can also be read. 00303 // / / / / / / / When it is read the first time, the address counter can be read. 00304 // ID6 ID5 ID4 ID3 ID2 ID1 ID0 When it is read the second time, the part ID can be read. 00305 // 00306 // BF = "1": busy state 00307 // BF = "0": ready state 00308 // 00309 //write data XX10 D7 D6 D5 D4 D3 D2 D1 D0 Write data into internal RAM (DDRAM / CGRAM / SEGRAM). 00310 //read data XX11 D7 D6 D5 D4 D3 D2 D1 D0 Read data from internal RAM (DDRAM / CGRAM / SEGRAM). 00311 // 00312 // 00313 00314 00315 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00316 // Extended Instruction Set 00317 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00318 // 00319 //Temperature X100 0 1 1 1 0 1 1 0 Set Temperature Coefficient TC2~0: 00320 //Coefficient 000: Reserved 00321 //Control 001: Reserved 00322 // 010: -0.05%/゚C (POR) 00323 //Temperature XX10 0 0 0 0 0 TC2 TC1 TC0 011: Reserved 00324 //Coefficient 100: -0.10%/゚C 00325 //Control 101: Reserved 00326 //Settings 110: -0.15%/゚C 00327 // 111: -0.20%/゚C 00328 // 00329 //ROM Selection X100 0 1 1 1 0 0 1 0 Writing data into ROM selection 00330 //ROM Selection Settings XX10 0 0 0 0 ROM2 ROM1 0 0 register enables the selection of 00331 // ROM A, B or C. 00332 // ROM2~1: 00333 // 00: ROMA 00334 // 01: ROMB 00335 // 10: ROMC 00336 // 11: Invalid 00337 00338 } _commands; 00339 00340 typedef enum { 00341 MaxCharsInALine = 0x14, // buffer depth for one line (no scroll function used) 00342 COMMAND = 0x00, 00343 DATA = 0x40 00344 } _constants; 00345 00346 00347 char curs[LINES]; // Character position on line 00348 void init( const char* init_message ); 00349 void clear_rest_of_line( unsigned char line ); 00350 int lcd_write( char first, char second ); 00351 int lcd_command( char command ); 00352 int lcd_data( char data ); 00353 I2C *i2c_p; 00354 I2C &i2c; 00355 char i2c_addr; 00356 char charsInLine; 00357 00358 }; 00359 00360 00361 #endif 00362 00363 00364 00365 00366 00367 00368 00369 00370 00371
Generated on Tue Jul 12 2022 16:15:28 by
1.7.2