This library is designed to work with LCD screens on the I2C bus. This library is an import of arduino library LiquidCrystal_I2C. This library was tested on the Nucleo F103 debug card using the LCD module 1602A.

Dependencies:   mbed

Dependents:   mbed-os-example-mbed6-wifi_MY_SOCKET_rigtech_copy_

Committer:
Yar
Date:
Fri May 19 18:21:24 2017 +0000
Revision:
0:824096cc05af
Import arduino library for working with LCD screen. Checked work with the LCD display 1602A, with the control controller ks0066U.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Yar 0:824096cc05af 1 #ifndef FDB_LIQUID_CRYSTAL_I2C_H
Yar 0:824096cc05af 2 #define FDB_LIQUID_CRYSTAL_I2C_H
Yar 0:824096cc05af 3
Yar 0:824096cc05af 4 //#include <inttypes.h>
Yar 0:824096cc05af 5 //#include <Print.h>
Yar 0:824096cc05af 6
Yar 0:824096cc05af 7 // commands
Yar 0:824096cc05af 8 #define LCD_CLEARDISPLAY 0x01
Yar 0:824096cc05af 9 #define LCD_RETURNHOME 0x02
Yar 0:824096cc05af 10 #define LCD_ENTRYMODESET 0x04
Yar 0:824096cc05af 11 #define LCD_DISPLAYCONTROL 0x08
Yar 0:824096cc05af 12 #define LCD_CURSORSHIFT 0x10
Yar 0:824096cc05af 13 #define LCD_FUNCTIONSET 0x20
Yar 0:824096cc05af 14 #define LCD_SETCGRAMADDR 0x40
Yar 0:824096cc05af 15 #define LCD_SETDDRAMADDR 0x80
Yar 0:824096cc05af 16
Yar 0:824096cc05af 17 // flags for display entry mode
Yar 0:824096cc05af 18 #define LCD_ENTRYRIGHT 0x00
Yar 0:824096cc05af 19 #define LCD_ENTRYLEFT 0x02
Yar 0:824096cc05af 20 #define LCD_ENTRYSHIFTINCREMENT 0x01
Yar 0:824096cc05af 21 #define LCD_ENTRYSHIFTDECREMENT 0x00
Yar 0:824096cc05af 22
Yar 0:824096cc05af 23 // flags for display on/off control
Yar 0:824096cc05af 24 #define LCD_DISPLAYON 0x04
Yar 0:824096cc05af 25 #define LCD_DISPLAYOFF 0x00
Yar 0:824096cc05af 26 #define LCD_CURSORON 0x02
Yar 0:824096cc05af 27 #define LCD_CURSOROFF 0x00
Yar 0:824096cc05af 28 #define LCD_BLINKON 0x01
Yar 0:824096cc05af 29 #define LCD_BLINKOFF 0x00
Yar 0:824096cc05af 30
Yar 0:824096cc05af 31 // flags for display/cursor shift
Yar 0:824096cc05af 32 #define LCD_DISPLAYMOVE 0x08
Yar 0:824096cc05af 33 #define LCD_CURSORMOVE 0x00
Yar 0:824096cc05af 34 #define LCD_MOVERIGHT 0x04
Yar 0:824096cc05af 35 #define LCD_MOVELEFT 0x00
Yar 0:824096cc05af 36
Yar 0:824096cc05af 37 // flags for function set
Yar 0:824096cc05af 38 #define LCD_8BITMODE 0x10
Yar 0:824096cc05af 39 #define LCD_4BITMODE 0x00
Yar 0:824096cc05af 40 #define LCD_2LINE 0x08
Yar 0:824096cc05af 41 #define LCD_1LINE 0x00
Yar 0:824096cc05af 42 #define LCD_5x10DOTS 0x04
Yar 0:824096cc05af 43 #define LCD_5x8DOTS 0x00
Yar 0:824096cc05af 44
Yar 0:824096cc05af 45 // flags for backlight control
Yar 0:824096cc05af 46 #define LCD_BACKLIGHT 0x08
Yar 0:824096cc05af 47 #define LCD_NOBACKLIGHT 0x00
Yar 0:824096cc05af 48
Yar 0:824096cc05af 49 #define En 0x04//B00000100 // Enable bit
Yar 0:824096cc05af 50 #define Rw 0x02 // B00000010 // Read/Write bit
Yar 0:824096cc05af 51 #define Rs 0x01 //B00000001 // Register select bit
Yar 0:824096cc05af 52
Yar 0:824096cc05af 53 /**
Yar 0:824096cc05af 54 * This is the driver for the Liquid Crystal LCD displays that use the I2C bus.
Yar 0:824096cc05af 55 *
Yar 0:824096cc05af 56 * After creating an instance of this class, first call begin() before anything else.
Yar 0:824096cc05af 57 * The backlight is on by default, since that is the most likely operating mode in
Yar 0:824096cc05af 58 * most cases.
Yar 0:824096cc05af 59 */
Yar 0:824096cc05af 60 class LiquidCrystal_I2C {
Yar 0:824096cc05af 61 public:
Yar 0:824096cc05af 62 /**
Yar 0:824096cc05af 63 * Constructor
Yar 0:824096cc05af 64 *
Yar 0:824096cc05af 65 * @param lcd_addr I2C slave address of the LCD display. Most likely printed on the
Yar 0:824096cc05af 66 * LCD circuit board, or look in the supplied LCD documentation.
Yar 0:824096cc05af 67 * @param lcd_cols Number of columns your LCD display has.
Yar 0:824096cc05af 68 * @param lcd_rows Number of rows your LCD display has.
Yar 0:824096cc05af 69 * @param charsize The size in dots that the display has, use LCD_5x10DOTS or LCD_5x8DOTS.
Yar 0:824096cc05af 70 */
Yar 0:824096cc05af 71 LiquidCrystal_I2C(unsigned char lcd_addr, unsigned char lcd_cols, unsigned char lcd_rows, unsigned char charsize = LCD_5x8DOTS);
Yar 0:824096cc05af 72
Yar 0:824096cc05af 73 /**
Yar 0:824096cc05af 74 * Set the LCD display in the correct begin state, must be called before anything else is done.
Yar 0:824096cc05af 75 */
Yar 0:824096cc05af 76 void begin();
Yar 0:824096cc05af 77
Yar 0:824096cc05af 78 /**
Yar 0:824096cc05af 79 * Remove all the characters currently shown. Next print/write operation will start
Yar 0:824096cc05af 80 * from the first position on LCD display.
Yar 0:824096cc05af 81 */
Yar 0:824096cc05af 82 void clear();
Yar 0:824096cc05af 83
Yar 0:824096cc05af 84 /**
Yar 0:824096cc05af 85 * Next print/write operation will will start from the first position on the LCD display.
Yar 0:824096cc05af 86 */
Yar 0:824096cc05af 87 void home();
Yar 0:824096cc05af 88
Yar 0:824096cc05af 89 /**
Yar 0:824096cc05af 90 * Do not show any characters on the LCD display. Backlight state will remain unchanged.
Yar 0:824096cc05af 91 * Also all characters written on the display will return, when the display in enabled again.
Yar 0:824096cc05af 92 */
Yar 0:824096cc05af 93 void noDisplay();
Yar 0:824096cc05af 94
Yar 0:824096cc05af 95 /**
Yar 0:824096cc05af 96 * Show the characters on the LCD display, this is the normal behaviour. This method should
Yar 0:824096cc05af 97 * only be used after noDisplay() has been used.
Yar 0:824096cc05af 98 */
Yar 0:824096cc05af 99 void display();
Yar 0:824096cc05af 100
Yar 0:824096cc05af 101 /**
Yar 0:824096cc05af 102 * Do not blink the cursor indicator.
Yar 0:824096cc05af 103 */
Yar 0:824096cc05af 104 void noBlink();
Yar 0:824096cc05af 105
Yar 0:824096cc05af 106 /**
Yar 0:824096cc05af 107 * Start blinking the cursor indicator.
Yar 0:824096cc05af 108 */
Yar 0:824096cc05af 109 void blink();
Yar 0:824096cc05af 110
Yar 0:824096cc05af 111 /**
Yar 0:824096cc05af 112 * Do not show a cursor indicator.
Yar 0:824096cc05af 113 */
Yar 0:824096cc05af 114 void noCursor();
Yar 0:824096cc05af 115
Yar 0:824096cc05af 116 /**
Yar 0:824096cc05af 117 * Show a cursor indicator, cursor can blink on not blink. Use the
Yar 0:824096cc05af 118 * methods blink() and noBlink() for changing cursor blink.
Yar 0:824096cc05af 119 */
Yar 0:824096cc05af 120 void cursor();
Yar 0:824096cc05af 121
Yar 0:824096cc05af 122 void scrollDisplayLeft();
Yar 0:824096cc05af 123 void scrollDisplayRight();
Yar 0:824096cc05af 124 void printLeft();
Yar 0:824096cc05af 125 void printRight();
Yar 0:824096cc05af 126 void leftToRight();
Yar 0:824096cc05af 127 void rightToLeft();
Yar 0:824096cc05af 128 void shiftIncrement();
Yar 0:824096cc05af 129 void shiftDecrement();
Yar 0:824096cc05af 130 void noBacklight();
Yar 0:824096cc05af 131 void backlight();
Yar 0:824096cc05af 132 bool getBacklight();
Yar 0:824096cc05af 133 void autoscroll();
Yar 0:824096cc05af 134 void noAutoscroll();
Yar 0:824096cc05af 135 void createChar(unsigned char, unsigned char[]);
Yar 0:824096cc05af 136 void setCursor(unsigned char, unsigned char);
Yar 0:824096cc05af 137 virtual int write(unsigned char);
Yar 0:824096cc05af 138 void command(unsigned char);
Yar 0:824096cc05af 139
Yar 0:824096cc05af 140 inline void blink_on() { blink(); }
Yar 0:824096cc05af 141 inline void blink_off() { noBlink(); }
Yar 0:824096cc05af 142 inline void cursor_on() { cursor(); }
Yar 0:824096cc05af 143 inline void cursor_off() { noCursor(); }
Yar 0:824096cc05af 144
Yar 0:824096cc05af 145 // Compatibility API function aliases
Yar 0:824096cc05af 146 void setBacklight(unsigned char new_val); // alias for backlight() and nobacklight()
Yar 0:824096cc05af 147 void load_custom_character(unsigned char char_num, unsigned char *rows); // alias for createChar()
Yar 0:824096cc05af 148 void printstr(const char[]);
Yar 0:824096cc05af 149 int print(const char* text);
Yar 0:824096cc05af 150 private:
Yar 0:824096cc05af 151 void send(unsigned char, unsigned char);
Yar 0:824096cc05af 152 void write4bits(unsigned char);
Yar 0:824096cc05af 153 void expanderWrite(unsigned char);
Yar 0:824096cc05af 154 void pulseEnable(unsigned char);
Yar 0:824096cc05af 155 unsigned char _addr;
Yar 0:824096cc05af 156 unsigned char _displayfunction;
Yar 0:824096cc05af 157 unsigned char _displaycontrol;
Yar 0:824096cc05af 158 unsigned char _displaymode;
Yar 0:824096cc05af 159 unsigned char _cols;
Yar 0:824096cc05af 160 unsigned char _rows;
Yar 0:824096cc05af 161 unsigned char _charsize;
Yar 0:824096cc05af 162 unsigned char _backlightval;
Yar 0:824096cc05af 163 };
Yar 0:824096cc05af 164
Yar 0:824096cc05af 165 #endif // FDB_LIQUID_CRYSTAL_I2C_H