JeeLib
An easy interface to the port headers, the RF12 driver library, timers, low-power code, and more.
 All Classes Files Functions Variables Enumerations Macros Pages
PortsLCD.h
Go to the documentation of this file.
1 // 2009-09-23 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
2 
3 #ifndef LiquidCrystal_h
4 #define LiquidCrystal_h
5 
6 /// @file
7 /// LiquidCrystal library, extended for use over I2C with the LCD Plug.
8 /// See https://jeelabs.org/2009/09/26/generalized-liquidcrystal-library/
9 
10 #include <inttypes.h>
11 #include <Print.h>
12 #include <Ports.h>
13 
14 // commands
15 #define LCD_CLEARDISPLAY 0x01
16 #define LCD_RETURNHOME 0x02
17 #define LCD_ENTRYMODESET 0x04
18 #define LCD_DISPLAYCONTROL 0x08
19 #define LCD_CURSORSHIFT 0x10
20 #define LCD_FUNCTIONSET 0x20
21 #define LCD_SETCGRAMADDR 0x40
22 #define LCD_SETDDRAMADDR 0x80
23 
24 // flags for display entry mode
25 #define LCD_ENTRYRIGHT 0x00
26 #define LCD_ENTRYLEFT 0x02
27 #define LCD_ENTRYSHIFTINCREMENT 0x01
28 #define LCD_ENTRYSHIFTDECREMENT 0x00
29 
30 // flags for display on/off control
31 #define LCD_DISPLAYON 0x04
32 #define LCD_DISPLAYOFF 0x00
33 #define LCD_CURSORON 0x02
34 #define LCD_CURSOROFF 0x00
35 #define LCD_BLINKON 0x01
36 #define LCD_BLINKOFF 0x00
37 
38 // flags for display/cursor shift
39 #define LCD_DISPLAYMOVE 0x08
40 #define LCD_CURSORMOVE 0x00
41 #define LCD_MOVERIGHT 0x04
42 #define LCD_MOVELEFT 0x00
43 
44 // flags for function set
45 #define LCD_8BITMODE 0x10
46 #define LCD_4BITMODE 0x00
47 #define LCD_2LINE 0x08
48 #define LCD_1LINE 0x00
49 #define LCD_5x10DOTS 0x04
50 #define LCD_5x8DOTS 0x00
51 
52 /// Base class for different types of interfaces to character LCD's.
53 /// This class defines the basic functionality needed to drive an LCD display.
54 /// It is an incomplete (abstract) base class, which needs to be extended.
55 /// See the LiquidCrystal and LiquidCrystalI2C classes for two usable versions.
56 
57 class LiquidCrystalBase : public Print {
58 public:
59  LiquidCrystalBase () {}
60 
61  void begin(byte cols, byte rows, byte charsize = LCD_5x8DOTS);
62 
63  void clear();
64  void home();
65 
66  void noDisplay();
67  void display();
68  void noBlink();
69  void blink();
70  void noCursor();
71  void cursor();
72  void scrollDisplayLeft();
73  void scrollDisplayRight();
74  void leftToRight();
75  void rightToLeft();
76  void autoscroll();
77  void noAutoscroll();
78 
79  void createChar(byte, byte[]);
80  void setCursor(byte, byte);
81  virtual WRITE_RESULT write(byte);
82  void command(byte);
83 protected:
84  virtual void config() =0;
85  virtual void send(byte, byte) =0;
86  virtual void write4bits(byte) =0;
87 
88  byte _displayfunction;
89  byte _displaycontrol;
90  byte _displaymode;
91  byte _initialized;
92  byte _numlines,_currline;
93 };
94 
95 /// Interface to character LCD's connected via 4 to 8 I/O pins.
96 /// This class can be used to create an object with drives an LCD through many
97 /// different I/O pins, connected to the display in parallel - it is equivalent
98 /// to the LiquidCrystal class defined in the Arduino, but has be adjusted to
99 /// work with the above LiquidCrystalBase instead.
100 
102 public:
103  LiquidCrystal(byte rs, byte enable,
104  byte d0, byte d1, byte d2, byte d3, byte d4, byte d5, byte d6, byte d7);
105  LiquidCrystal(byte rs, byte rw, byte enable,
106  byte d0, byte d1, byte d2, byte d3, byte d4, byte d5, byte d6, byte d7);
107  LiquidCrystal(byte rs, byte rw, byte enable,
108  byte d0, byte d1, byte d2, byte d3);
109  LiquidCrystal(byte rs, byte enable,
110  byte d0, byte d1, byte d2, byte d3);
111 
112  void init(byte fourbitmode, byte rs, byte rw, byte enable,
113  byte d0, byte d1, byte d2, byte d3, byte d4, byte d5, byte d6, byte d7);
114 
115  virtual void config();
116  virtual void send(byte, byte);
117  virtual void write4bits(byte);
118 
119  void write8bits(byte);
120  void pulseEnable();
121 
122  byte _rs_pin; // LOW: command. HIGH: character.
123  byte _rw_pin; // LOW: write to LCD. HIGH: read from LCD.
124  byte _enable_pin; // activated by a HIGH pulse.
125  byte _data_pins[8];
126 };
127 
128 /// Interface to character LCD's connected via 2 I/O pins using software I2C.
129 /// This class allows driving an LCD connected via I2C using an LCD Plug, which
130 /// is in turn based on an MCP23008 I2C I/O expander chip and some other parts.
131 /// The available functions include all those of the LiquidCrystal class.
132 
134  DeviceI2C device;
135 public:
136  LiquidCrystalI2C (const PortI2C& p, byte addr =0x24);
137 
138  // this display can also turn the back-light on or off
139  void backlight();
140  void noBacklight();
141 protected:
142  virtual void config();
143  virtual void send(byte, byte);
144  virtual void write4bits(byte);
145 };
146 
147 #endif
Base class for different types of interfaces to character LCD's.
Definition: PortsLCD.h:57
void noBlink()
Turn on and off the blinking cursor.
Definition: PortsLCD.cpp:127
Can be used to drive a software (bit-banged) I2C bus via a Port interface.
Definition: Ports.h:213
void autoscroll()
This will 'right justify' text from the cursor.
Definition: PortsLCD.cpp:157
void rightToLeft()
This is for text that flows Right to Left.
Definition: PortsLCD.cpp:151
void noCursor()
Turns the underline cursor on/off.
Definition: PortsLCD.cpp:117
void createChar(byte, byte[])
Allows us to fill the first 8 CGRAM locations with custom characters.
Definition: PortsLCD.cpp:170
Each device on the I2C bus needs to be defined using a DeviceI2C instance.
Definition: Ports.h:266
void leftToRight()
This is for text that flows Left to Right.
Definition: PortsLCD.cpp:145
virtual void send(byte, byte)
write either command or data, with automatic 4/8-bit selection
Definition: PortsLCD.cpp:367
Interface to character LCD's connected via 2 I/O pins using software I2C.
Definition: PortsLCD.h:133
Ports library definitions.
void scrollDisplayLeft()
These commands scroll the display without changing the RAM.
Definition: PortsLCD.cpp:137
void noAutoscroll()
This will 'left justify' text from the cursor.
Definition: PortsLCD.cpp:163
Interface to character LCD's connected via 4 to 8 I/O pins.
Definition: PortsLCD.h:101
virtual void send(byte, byte)
write either command or data, with automatic 4/8-bit selection
Definition: PortsLCD.cpp:281
void noDisplay()
Turn the display on/off (quickly)
Definition: PortsLCD.cpp:107