LCD Library 1.1.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 LiquidCrystal.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.
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 //
00030 // This library is only compatible with Arduino's SDK version 1.0
00031 //
00032 // @version API 1.0.0
00033 //
00034 //
00035 // @author F. Malpartida - fmalpartida@gmail.com
00036 // ---------------------------------------------------------------------------
00037 #ifndef _LCD_H_
00038 #define _LCD_H_
00039 #include <inttypes.h>
00040 #include <Print.h>
00041 
00050 #define FAST_MODE
00051 
00059 // LCD Commands
00060 // ---------------------------------------------------------------------------
00061 #define LCD_CLEARDISPLAY        0x01
00062 #define LCD_RETURNHOME          0x02
00063 #define LCD_ENTRYMODESET        0x04
00064 #define LCD_DISPLAYCONTROL      0x08
00065 #define LCD_CURSORSHIFT         0x10
00066 #define LCD_FUNCTIONSET         0x20
00067 #define LCD_SETCGRAMADDR        0x40
00068 #define LCD_SETDDRAMADDR        0x80
00069 
00070 // flags for display entry mode
00071 // ---------------------------------------------------------------------------
00072 #define LCD_ENTRYRIGHT          0x00
00073 #define LCD_ENTRYLEFT           0x02
00074 #define LCD_ENTRYSHIFTINCREMENT 0x01
00075 #define LCD_ENTRYSHIFTDECREMENT 0x00
00076 
00077 // flags for display on/off and cursor control
00078 // ---------------------------------------------------------------------------
00079 #define LCD_DISPLAYON           0x04
00080 #define LCD_DISPLAYOFF          0x00
00081 #define LCD_CURSORON            0x02
00082 #define LCD_CURSOROFF           0x00
00083 #define LCD_BLINKON             0x01
00084 #define LCD_BLINKOFF            0x00
00085 
00086 // flags for display/cursor shift
00087 // ---------------------------------------------------------------------------
00088 #define LCD_DISPLAYMOVE         0x08
00089 #define LCD_CURSORMOVE          0x00
00090 #define LCD_MOVERIGHT           0x04
00091 #define LCD_MOVELEFT            0x00
00092 
00093 // flags for function set
00094 // ---------------------------------------------------------------------------
00095 #define LCD_8BITMODE            0x10
00096 #define LCD_4BITMODE            0x00
00097 #define LCD_2LINE               0x08
00098 #define LCD_1LINE               0x00
00099 #define LCD_5x10DOTS            0x04
00100 #define LCD_5x8DOTS             0x00
00101 
00102 #define LCD_4BIT                1
00103 #define LCD_8BIT                0
00104 
00105 // Define COMMAND and DATA LCD Rs
00106 // ---------------------------------------------------------------------------
00107 #define COMMAND                 0
00108 #define DATA                    1
00109 
00116 #define HOME_CLEAR_EXEC      2000
00117 
00118 class LCD : public Print 
00119 {
00120 public:
00121    
00128    LCD ( );
00129    
00144 #if (ARDUINO <  100)
00145    virtual void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS) { };
00146 #else
00147    virtual void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS) = 0;
00148 #endif
00149    
00160    void clear();
00161    
00173    void home();
00174    
00183    void noDisplay();
00184    
00194    void display();
00195    
00202    void noBlink();
00203    
00212    void blink();
00213    
00220    void noCursor();
00221    
00230    void cursor();
00231    
00239    void scrollDisplayLeft();
00240    
00248    void scrollDisplayRight();
00249    
00261    void leftToRight();
00262    
00274    void rightToLeft();
00275    
00289    void autoscroll();
00290    
00299    void noAutoscroll();
00300    
00317    void createChar(uint8_t location, uint8_t charmap[]);
00318    
00328    void setCursor(uint8_t col, uint8_t row);
00329    
00330    
00342    void command(uint8_t value);
00343    
00355 #if (ARDUINO <  100)
00356    virtual void write(uint8_t value);
00357 #else
00358    virtual size_t write(uint8_t value);
00359 #endif
00360    
00361    
00375 #if (ARDUINO <  100)
00376    virtual void send(uint8_t value, uint8_t mode) { };
00377 #else
00378    virtual void send(uint8_t value, uint8_t mode) = 0;
00379 #endif
00380    
00381 #if (ARDUINO <  100)
00382    using Print::write;
00383 #else
00384    using Print::write;
00385 #endif   
00386    
00387 protected:
00388    // Internal LCD variables to control the LCD shared between all derived
00389    // classes.
00390    uint8_t _displayfunction;  // LCD_5x10DOTS or LCD_5x8DOTS, LCD_4BITMODE or 
00391    // LCD_8BITMODE, LCD_1LINE or LCD_2LINE
00392    uint8_t _displaycontrol;   // LCD base control command LCD on/off, blink, cursor
00393    // all commands are "ored" to its contents.
00394    uint8_t _displaymode;      // Text entry mode to the LCD
00395    uint8_t _numlines;         // Number of lines of the LCD, initialized with begin()
00396    uint8_t _cols;             // Number of columns in the LCD
00397    
00398 private:
00399    
00400 };
00401 
00402 #endif
 All Classes Files Functions Variables Defines