root / Ports / PortsLCD.h
History | View | Annotate | Download (4.1 KB)
| 1 | 7763 | jcw | //>>> The latest version of this code can be found at https://github.com/jcw/ !!
|
|---|---|---|---|
| 2 | 7763 | jcw | |
| 3 | 4727 | jcw | // LiquidCrystal library, extended for use over I2C with the LCD Plug
|
| 4 | 4727 | jcw | // 2009-09-23 <jcw@equi4.com> http://opensource.org/licenses/mit-license.php
|
| 5 | 4727 | jcw | // $Id$
|
| 6 | 4727 | jcw | |
| 7 | 4727 | jcw | // see http://news.jeelabs.org/2009/09/26/generalized-liquidcrystal-library/
|
| 8 | 4727 | jcw | |
| 9 | 4727 | jcw | #ifndef LiquidCrystal_h
|
| 10 | 4727 | jcw | #define LiquidCrystal_h
|
| 11 | 4727 | jcw | |
| 12 | 4727 | jcw | #include <inttypes.h> |
| 13 | 4727 | jcw | #include <Print.h> |
| 14 | 4727 | jcw | #include <Ports.h> |
| 15 | 4727 | jcw | |
| 16 | 4727 | jcw | // commands
|
| 17 | 4727 | jcw | #define LCD_CLEARDISPLAY 0x01 |
| 18 | 4727 | jcw | #define LCD_RETURNHOME 0x02 |
| 19 | 4727 | jcw | #define LCD_ENTRYMODESET 0x04 |
| 20 | 4727 | jcw | #define LCD_DISPLAYCONTROL 0x08 |
| 21 | 4727 | jcw | #define LCD_CURSORSHIFT 0x10 |
| 22 | 4727 | jcw | #define LCD_FUNCTIONSET 0x20 |
| 23 | 4727 | jcw | #define LCD_SETCGRAMADDR 0x40 |
| 24 | 4727 | jcw | #define LCD_SETDDRAMADDR 0x80 |
| 25 | 4727 | jcw | |
| 26 | 4727 | jcw | // flags for display entry mode
|
| 27 | 4727 | jcw | #define LCD_ENTRYRIGHT 0x00 |
| 28 | 4727 | jcw | #define LCD_ENTRYLEFT 0x02 |
| 29 | 4727 | jcw | #define LCD_ENTRYSHIFTINCREMENT 0x01 |
| 30 | 4727 | jcw | #define LCD_ENTRYSHIFTDECREMENT 0x00 |
| 31 | 4727 | jcw | |
| 32 | 4727 | jcw | // flags for display on/off control
|
| 33 | 4727 | jcw | #define LCD_DISPLAYON 0x04 |
| 34 | 4727 | jcw | #define LCD_DISPLAYOFF 0x00 |
| 35 | 4727 | jcw | #define LCD_CURSORON 0x02 |
| 36 | 4727 | jcw | #define LCD_CURSOROFF 0x00 |
| 37 | 4727 | jcw | #define LCD_BLINKON 0x01 |
| 38 | 4727 | jcw | #define LCD_BLINKOFF 0x00 |
| 39 | 4727 | jcw | |
| 40 | 4727 | jcw | // flags for display/cursor shift
|
| 41 | 4727 | jcw | #define LCD_DISPLAYMOVE 0x08 |
| 42 | 4727 | jcw | #define LCD_CURSORMOVE 0x00 |
| 43 | 4727 | jcw | #define LCD_MOVERIGHT 0x04 |
| 44 | 4727 | jcw | #define LCD_MOVELEFT 0x00 |
| 45 | 4727 | jcw | |
| 46 | 4727 | jcw | // flags for function set
|
| 47 | 4727 | jcw | #define LCD_8BITMODE 0x10 |
| 48 | 4727 | jcw | #define LCD_4BITMODE 0x00 |
| 49 | 4727 | jcw | #define LCD_2LINE 0x08 |
| 50 | 4727 | jcw | #define LCD_1LINE 0x00 |
| 51 | 4727 | jcw | #define LCD_5x10DOTS 0x04 |
| 52 | 4727 | jcw | #define LCD_5x8DOTS 0x00 |
| 53 | 4727 | jcw | |
| 54 | 4727 | jcw | // this class defines all the basic functionality needed to drive an LCD display
|
| 55 | 4727 | jcw | // it is an incomplete (abstract) base class, which needs to be extended for use
|
| 56 | 4727 | jcw | // see the LiquidCrystal and LiquidCrystalI2C classes for two usable versions
|
| 57 | 4727 | jcw | |
| 58 | 4727 | jcw | class LiquidCrystalBase : public Print {
|
| 59 | 4727 | jcw | public:
|
| 60 | 4727 | jcw | LiquidCrystalBase () {}
|
| 61 | 4727 | jcw | |
| 62 | 4727 | jcw | void begin(byte cols, byte rows, byte charsize = LCD_5x8DOTS);
|
| 63 | 4727 | jcw | |
| 64 | 4727 | jcw | void clear();
|
| 65 | 4727 | jcw | void home();
|
| 66 | 4727 | jcw | |
| 67 | 4727 | jcw | void noDisplay();
|
| 68 | 4727 | jcw | void display();
|
| 69 | 4727 | jcw | void noBlink();
|
| 70 | 4727 | jcw | void blink();
|
| 71 | 4727 | jcw | void noCursor();
|
| 72 | 4727 | jcw | void cursor();
|
| 73 | 4727 | jcw | void scrollDisplayLeft();
|
| 74 | 4727 | jcw | void scrollDisplayRight();
|
| 75 | 4727 | jcw | void leftToRight();
|
| 76 | 4727 | jcw | void rightToLeft();
|
| 77 | 4727 | jcw | void autoscroll();
|
| 78 | 4727 | jcw | void noAutoscroll();
|
| 79 | 4727 | jcw | |
| 80 | 4727 | jcw | void createChar(byte, byte[]);
|
| 81 | 4727 | jcw | void setCursor(byte, byte);
|
| 82 | 4727 | jcw | virtual void write(byte);
|
| 83 | 4727 | jcw | void command(byte);
|
| 84 | 4727 | jcw | protected:
|
| 85 | 4727 | jcw | virtual void config() =0; |
| 86 | 4727 | jcw | virtual void send(byte, byte) =0; |
| 87 | 4727 | jcw | virtual void write4bits(byte) =0; |
| 88 | 4727 | jcw | |
| 89 | 4727 | jcw | byte _displayfunction; |
| 90 | 4727 | jcw | byte _displaycontrol; |
| 91 | 4727 | jcw | byte _displaymode; |
| 92 | 4727 | jcw | byte _initialized; |
| 93 | 4727 | jcw | byte _numlines,_currline; |
| 94 | 4727 | jcw | }; |
| 95 | 4727 | jcw | |
| 96 | 4727 | jcw | // This class can be used to create an object with drives an LCD through many
|
| 97 | 4727 | jcw | // different I/O pins, connected to the display in parallel - it is equivalent
|
| 98 | 4727 | jcw | // to the LiquidCrystal class defined in the Arduino, but has be adjusted to
|
| 99 | 4727 | jcw | // work with the above LiquidCrystalBase instead.
|
| 100 | 4727 | jcw | |
| 101 | 4727 | jcw | class LiquidCrystal : public LiquidCrystalBase {
|
| 102 | 4727 | jcw | public:
|
| 103 | 4727 | jcw | LiquidCrystal(byte rs, byte enable, |
| 104 | 4727 | jcw | byte d0, byte d1, byte d2, byte d3, byte d4, byte d5, byte d6, byte d7); |
| 105 | 4727 | jcw | LiquidCrystal(byte rs, byte rw, byte enable, |
| 106 | 4727 | jcw | byte d0, byte d1, byte d2, byte d3, byte d4, byte d5, byte d6, byte d7); |
| 107 | 4727 | jcw | LiquidCrystal(byte rs, byte rw, byte enable, |
| 108 | 4727 | jcw | byte d0, byte d1, byte d2, byte d3); |
| 109 | 4727 | jcw | LiquidCrystal(byte rs, byte enable, |
| 110 | 4727 | jcw | byte d0, byte d1, byte d2, byte d3); |
| 111 | 4727 | jcw | |
| 112 | 4727 | jcw | void init(byte fourbitmode, byte rs, byte rw, byte enable,
|
| 113 | 4727 | jcw | byte d0, byte d1, byte d2, byte d3, byte d4, byte d5, byte d6, byte d7); |
| 114 | 4727 | jcw | |
| 115 | 4727 | jcw | virtual void config();
|
| 116 | 4727 | jcw | virtual void send(byte, byte);
|
| 117 | 4727 | jcw | virtual void write4bits(byte);
|
| 118 | 4727 | jcw | |
| 119 | 4727 | jcw | void write8bits(byte);
|
| 120 | 4727 | jcw | void pulseEnable();
|
| 121 | 4727 | jcw | |
| 122 | 4727 | jcw | byte _rs_pin; // LOW: command. HIGH: character.
|
| 123 | 4727 | jcw | byte _rw_pin; // LOW: write to LCD. HIGH: read from LCD.
|
| 124 | 4727 | jcw | byte _enable_pin; // activated by a HIGH pulse.
|
| 125 | 4727 | jcw | byte _data_pins[8];
|
| 126 | 4727 | jcw | }; |
| 127 | 4727 | jcw | |
| 128 | 4727 | jcw | // This class allows driving an LCD connected via I2C using an LCD Plug, which
|
| 129 | 4727 | jcw | // is in turn based on an MCP23008 I2C I/O expander chip and some other parts.
|
| 130 | 4769 | jcw | // The available functions include all those of the LiquidCrystal class.
|
| 131 | 4727 | jcw | |
| 132 | 4727 | jcw | class LiquidCrystalI2C : public LiquidCrystalBase {
|
| 133 | 4727 | jcw | DeviceI2C device; |
| 134 | 4727 | jcw | public:
|
| 135 | 4727 | jcw | LiquidCrystalI2C (const PortI2C& p, byte addr =0x24); |
| 136 | 4769 | jcw | |
| 137 | 4769 | jcw | // this display can also turn the back-light on or off
|
| 138 | 4769 | jcw | void backlight();
|
| 139 | 4769 | jcw | void noBacklight();
|
| 140 | 4727 | jcw | protected:
|
| 141 | 4727 | jcw | virtual void config();
|
| 142 | 4727 | jcw | virtual void send(byte, byte);
|
| 143 | 4727 | jcw | virtual void write4bits(byte);
|
| 144 | 4727 | jcw | }; |
| 145 | 4727 | jcw | |
| 146 | 4727 | jcw | #endif |