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.
Dependents: mbed-os-example-mbed6-wifi_MY_SOCKET_rigtech_copy_
LiquidCrystal_I2C.h
00001 #ifndef FDB_LIQUID_CRYSTAL_I2C_H 00002 #define FDB_LIQUID_CRYSTAL_I2C_H 00003 00004 //#include <inttypes.h> 00005 //#include <Print.h> 00006 00007 // commands 00008 #define LCD_CLEARDISPLAY 0x01 00009 #define LCD_RETURNHOME 0x02 00010 #define LCD_ENTRYMODESET 0x04 00011 #define LCD_DISPLAYCONTROL 0x08 00012 #define LCD_CURSORSHIFT 0x10 00013 #define LCD_FUNCTIONSET 0x20 00014 #define LCD_SETCGRAMADDR 0x40 00015 #define LCD_SETDDRAMADDR 0x80 00016 00017 // flags for display entry mode 00018 #define LCD_ENTRYRIGHT 0x00 00019 #define LCD_ENTRYLEFT 0x02 00020 #define LCD_ENTRYSHIFTINCREMENT 0x01 00021 #define LCD_ENTRYSHIFTDECREMENT 0x00 00022 00023 // flags for display on/off control 00024 #define LCD_DISPLAYON 0x04 00025 #define LCD_DISPLAYOFF 0x00 00026 #define LCD_CURSORON 0x02 00027 #define LCD_CURSOROFF 0x00 00028 #define LCD_BLINKON 0x01 00029 #define LCD_BLINKOFF 0x00 00030 00031 // flags for display/cursor shift 00032 #define LCD_DISPLAYMOVE 0x08 00033 #define LCD_CURSORMOVE 0x00 00034 #define LCD_MOVERIGHT 0x04 00035 #define LCD_MOVELEFT 0x00 00036 00037 // flags for function set 00038 #define LCD_8BITMODE 0x10 00039 #define LCD_4BITMODE 0x00 00040 #define LCD_2LINE 0x08 00041 #define LCD_1LINE 0x00 00042 #define LCD_5x10DOTS 0x04 00043 #define LCD_5x8DOTS 0x00 00044 00045 // flags for backlight control 00046 #define LCD_BACKLIGHT 0x08 00047 #define LCD_NOBACKLIGHT 0x00 00048 00049 #define En 0x04//B00000100 // Enable bit 00050 #define Rw 0x02 // B00000010 // Read/Write bit 00051 #define Rs 0x01 //B00000001 // Register select bit 00052 00053 /** 00054 * This is the driver for the Liquid Crystal LCD displays that use the I2C bus. 00055 * 00056 * After creating an instance of this class, first call begin() before anything else. 00057 * The backlight is on by default, since that is the most likely operating mode in 00058 * most cases. 00059 */ 00060 class LiquidCrystal_I2C { 00061 public: 00062 /** 00063 * Constructor 00064 * 00065 * @param lcd_addr I2C slave address of the LCD display. Most likely printed on the 00066 * LCD circuit board, or look in the supplied LCD documentation. 00067 * @param lcd_cols Number of columns your LCD display has. 00068 * @param lcd_rows Number of rows your LCD display has. 00069 * @param charsize The size in dots that the display has, use LCD_5x10DOTS or LCD_5x8DOTS. 00070 */ 00071 LiquidCrystal_I2C(unsigned char lcd_addr, unsigned char lcd_cols, unsigned char lcd_rows, unsigned char charsize = LCD_5x8DOTS); 00072 00073 /** 00074 * Set the LCD display in the correct begin state, must be called before anything else is done. 00075 */ 00076 void begin(); 00077 00078 /** 00079 * Remove all the characters currently shown. Next print/write operation will start 00080 * from the first position on LCD display. 00081 */ 00082 void clear(); 00083 00084 /** 00085 * Next print/write operation will will start from the first position on the LCD display. 00086 */ 00087 void home(); 00088 00089 /** 00090 * Do not show any characters on the LCD display. Backlight state will remain unchanged. 00091 * Also all characters written on the display will return, when the display in enabled again. 00092 */ 00093 void noDisplay(); 00094 00095 /** 00096 * Show the characters on the LCD display, this is the normal behaviour. This method should 00097 * only be used after noDisplay() has been used. 00098 */ 00099 void display(); 00100 00101 /** 00102 * Do not blink the cursor indicator. 00103 */ 00104 void noBlink(); 00105 00106 /** 00107 * Start blinking the cursor indicator. 00108 */ 00109 void blink(); 00110 00111 /** 00112 * Do not show a cursor indicator. 00113 */ 00114 void noCursor(); 00115 00116 /** 00117 * Show a cursor indicator, cursor can blink on not blink. Use the 00118 * methods blink() and noBlink() for changing cursor blink. 00119 */ 00120 void cursor(); 00121 00122 void scrollDisplayLeft(); 00123 void scrollDisplayRight(); 00124 void printLeft(); 00125 void printRight(); 00126 void leftToRight(); 00127 void rightToLeft(); 00128 void shiftIncrement(); 00129 void shiftDecrement(); 00130 void noBacklight(); 00131 void backlight(); 00132 bool getBacklight(); 00133 void autoscroll(); 00134 void noAutoscroll(); 00135 void createChar(unsigned char, unsigned char[]); 00136 void setCursor(unsigned char, unsigned char); 00137 virtual int write(unsigned char); 00138 void command(unsigned char); 00139 00140 inline void blink_on() { blink(); } 00141 inline void blink_off() { noBlink(); } 00142 inline void cursor_on() { cursor(); } 00143 inline void cursor_off() { noCursor(); } 00144 00145 // Compatibility API function aliases 00146 void setBacklight(unsigned char new_val); // alias for backlight() and nobacklight() 00147 void load_custom_character(unsigned char char_num, unsigned char *rows); // alias for createChar() 00148 void printstr(const char[]); 00149 int print(const char* text); 00150 private: 00151 void send(unsigned char, unsigned char); 00152 void write4bits(unsigned char); 00153 void expanderWrite(unsigned char); 00154 void pulseEnable(unsigned char); 00155 unsigned char _addr; 00156 unsigned char _displayfunction; 00157 unsigned char _displaycontrol; 00158 unsigned char _displaymode; 00159 unsigned char _cols; 00160 unsigned char _rows; 00161 unsigned char _charsize; 00162 unsigned char _backlightval; 00163 }; 00164 00165 #endif // FDB_LIQUID_CRYSTAL_I2C_H
Generated on Tue Jul 12 2022 12:28:12 by
