LCD Library 1.2.1
LCD Library - LCD control class hierarchy library. Drop in replacement for the LiquidCrystal Library.
/Users/fmalpartida/development/ardWorkspace/LiquidCrystal_I2C/LiquiCrystal_I2C/LCD.h
Go to the documentation of this file.
00001 // ---------------------------------------------------------------------------
00002 // Created by Francisco Malpartida on 20/08/11.
00003 // Copyright 2011 - Under creative commons license 3.0:
00004 //        Attribution-ShareAlike CC BY-SA
00005 //
00006 // This software is furnished "as is", without technical support, and with no 
00007 // warranty, express or implied, as to its usefulness for any purpose.
00008 //
00009 // Thread Safe: No
00010 // Extendable: Yes
00011 //
00012 // @file LCD.h
00013 // This file implements a basic liquid crystal library that comes as standard
00014 // in the Arduino SDK.
00015 // 
00016 // @brief 
00017 // This is a basic implementation of the LiquidCrystal library of the
00018 // Arduino SDK. This library is a refactored version of the one supplied
00019 // in the Arduino SDK in such a way that it simplifies its extension
00020 // to support other mechanism to communicate to LCDs such as I2C, Serial, SR, 
00021 // The original library has been reworked in such a way that this will be
00022 // the base class implementing all generic methods to command an LCD based
00023 // on the Hitachi HD44780 and compatible chipsets.
00024 //
00025 // This base class is a pure abstract class and needs to be extended. As reference,
00026 // it has been extended to drive 4 and 8 bit mode control, LCDs and I2C extension
00027 // backpacks such as the I2CLCDextraIO using the PCF8574* I2C IO Expander ASIC.
00028 //
00029 // The functionality provided by this class and its base class is identical
00030 // to the original functionality of the Arduino LiquidCrystal library.
00031 //
00032 // @version API 1.1.0
00033 //
00034 //
00035 // @author F. Malpartida - fmalpartida@gmail.com
00036 // ---------------------------------------------------------------------------
00037 #ifndef _LCD_H_
00038 #define _LCD_H_
00039 
00040 #if (ARDUINO <  100)
00041 #include <WProgram.h>
00042 #else
00043 #include <Arduino.h>
00044 #endif
00045 
00046 #include <inttypes.h>
00047 #include <Print.h>
00048 
00049 
00058 #define FAST_MODE
00059 
00069 inline static void waitUsec ( uint16_t uSec )
00070 {
00071 #ifndef FAST_MODE
00072    delayMicroseconds ( uSec );
00073 #endif // FAST_MODE
00074 }
00075 
00076 
00084 // LCD Commands
00085 // ---------------------------------------------------------------------------
00086 #define LCD_CLEARDISPLAY        0x01
00087 #define LCD_RETURNHOME          0x02
00088 #define LCD_ENTRYMODESET        0x04
00089 #define LCD_DISPLAYCONTROL      0x08
00090 #define LCD_CURSORSHIFT         0x10
00091 #define LCD_FUNCTIONSET         0x20
00092 #define LCD_SETCGRAMADDR        0x40
00093 #define LCD_SETDDRAMADDR        0x80
00094 
00095 // flags for display entry mode
00096 // ---------------------------------------------------------------------------
00097 #define LCD_ENTRYRIGHT          0x00
00098 #define LCD_ENTRYLEFT           0x02
00099 #define LCD_ENTRYSHIFTINCREMENT 0x01
00100 #define LCD_ENTRYSHIFTDECREMENT 0x00
00101 
00102 // flags for display on/off and cursor control
00103 // ---------------------------------------------------------------------------
00104 #define LCD_DISPLAYON           0x04
00105 #define LCD_DISPLAYOFF          0x00
00106 #define LCD_CURSORON            0x02
00107 #define LCD_CURSOROFF           0x00
00108 #define LCD_BLINKON             0x01
00109 #define LCD_BLINKOFF            0x00
00110 
00111 // flags for display/cursor shift
00112 // ---------------------------------------------------------------------------
00113 #define LCD_DISPLAYMOVE         0x08
00114 #define LCD_CURSORMOVE          0x00
00115 #define LCD_MOVERIGHT           0x04
00116 #define LCD_MOVELEFT            0x00
00117 
00118 // flags for function set
00119 // ---------------------------------------------------------------------------
00120 #define LCD_8BITMODE            0x10
00121 #define LCD_4BITMODE            0x00
00122 #define LCD_2LINE               0x08
00123 #define LCD_1LINE               0x00
00124 #define LCD_5x10DOTS            0x04
00125 #define LCD_5x8DOTS             0x00
00126 
00127 #define LCD_4BIT                1
00128 #define LCD_8BIT                0
00129 
00130 // Define COMMAND and DATA LCD Rs
00131 // ---------------------------------------------------------------------------
00132 #define COMMAND                 0
00133 #define DATA                    1
00134 
00141 #define HOME_CLEAR_EXEC      2000
00142 
00143 class LCD : public Print 
00144 {
00145 public:
00146    
00153    LCD ( );
00154    
00169    virtual void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
00170    
00181    void clear();
00182    
00194    void home();
00195    
00204    void noDisplay();
00205    
00215    void display();
00216    
00223    void noBlink();
00224    
00233    void blink();
00234    
00241    void noCursor();
00242    
00251    void cursor();
00252    
00260    void scrollDisplayLeft();
00261    
00269    void scrollDisplayRight();
00270    
00282    void leftToRight();
00283    
00295    void rightToLeft();
00296    
00303    void moveCursorLeft();
00304 
00305    
00312    void moveCursorRight();
00313    
00327    void autoscroll();
00328    
00337    void noAutoscroll();
00338    
00355    void createChar(uint8_t location, uint8_t charmap[]);
00356    
00366    void setCursor(uint8_t col, uint8_t row);
00367 
00368    
00380    void command(uint8_t value);
00381    
00382    //
00383    // virtual class methods
00384    // --------------------------------------------------------------------------
00394    virtual void setBacklightPin ( uint8_t value ) { };
00395    
00411    virtual void setBacklight ( uint8_t value ) { };
00412    
00420    void backlight ( void );
00421 
00429    void noBacklight ( void );
00430    
00442 #if (ARDUINO <  100)
00443    virtual void write(uint8_t value);
00444 #else
00445    virtual size_t write(uint8_t value);
00446 #endif
00447    
00448    
00462 #if (ARDUINO <  100)
00463    virtual void send(uint8_t value, uint8_t mode) { };
00464 #else
00465    virtual void send(uint8_t value, uint8_t mode) = 0;
00466 #endif
00467    
00468 #if (ARDUINO <  100)
00469    using Print::write;
00470 #else
00471    using Print::write;
00472 #endif   
00473    
00474 protected:
00475    // Internal LCD variables to control the LCD shared between all derived
00476    // classes.
00477    uint8_t _displayfunction;  // LCD_5x10DOTS or LCD_5x8DOTS, LCD_4BITMODE or 
00478                               // LCD_8BITMODE, LCD_1LINE or LCD_2LINE
00479    uint8_t _displaycontrol;   // LCD base control command LCD on/off, blink, cursor
00480                               // all commands are "ored" to its contents.
00481    uint8_t _displaymode;      // Text entry mode to the LCD
00482    uint8_t _numlines;         // Number of lines of the LCD, initialized with begin()
00483    uint8_t _cols;             // Number of columns in the LCD
00484    
00485 private:
00486    
00487 };
00488 
00489 #endif
 All Classes Files Functions Variables Typedefs Defines