![]() |
LCD Library 1.2.0
LCD Library - LCD control class hierarchy library. Drop in replacement for the LiquidCrystal Library.
|
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 // @version API 1.1.0 00030 // 00031 // 00032 // @author F. Malpartida - fmalpartida@gmail.com 00033 // --------------------------------------------------------------------------- 00034 #ifndef _LCD_H_ 00035 #define _LCD_H_ 00036 00037 #if (ARDUINO < 100) 00038 #include <WProgram.h> 00039 #else 00040 #include <Arduino.h> 00041 #endif 00042 00043 #include <inttypes.h> 00044 #include <Print.h> 00045 00046 00055 #define FAST_MODE 00056 00066 inline static void waitUsec ( uint16_t uSec ) 00067 { 00068 #ifndef FAST_MODE 00069 delayMicroseconds ( uSec ); 00070 #endif // FAST_MODE 00071 } 00072 00073 00081 // LCD Commands 00082 // --------------------------------------------------------------------------- 00083 #define LCD_CLEARDISPLAY 0x01 00084 #define LCD_RETURNHOME 0x02 00085 #define LCD_ENTRYMODESET 0x04 00086 #define LCD_DISPLAYCONTROL 0x08 00087 #define LCD_CURSORSHIFT 0x10 00088 #define LCD_FUNCTIONSET 0x20 00089 #define LCD_SETCGRAMADDR 0x40 00090 #define LCD_SETDDRAMADDR 0x80 00091 00092 // flags for display entry mode 00093 // --------------------------------------------------------------------------- 00094 #define LCD_ENTRYRIGHT 0x00 00095 #define LCD_ENTRYLEFT 0x02 00096 #define LCD_ENTRYSHIFTINCREMENT 0x01 00097 #define LCD_ENTRYSHIFTDECREMENT 0x00 00098 00099 // flags for display on/off and cursor control 00100 // --------------------------------------------------------------------------- 00101 #define LCD_DISPLAYON 0x04 00102 #define LCD_DISPLAYOFF 0x00 00103 #define LCD_CURSORON 0x02 00104 #define LCD_CURSOROFF 0x00 00105 #define LCD_BLINKON 0x01 00106 #define LCD_BLINKOFF 0x00 00107 00108 // flags for display/cursor shift 00109 // --------------------------------------------------------------------------- 00110 #define LCD_DISPLAYMOVE 0x08 00111 #define LCD_CURSORMOVE 0x00 00112 #define LCD_MOVERIGHT 0x04 00113 #define LCD_MOVELEFT 0x00 00114 00115 // flags for function set 00116 // --------------------------------------------------------------------------- 00117 #define LCD_8BITMODE 0x10 00118 #define LCD_4BITMODE 0x00 00119 #define LCD_2LINE 0x08 00120 #define LCD_1LINE 0x00 00121 #define LCD_5x10DOTS 0x04 00122 #define LCD_5x8DOTS 0x00 00123 00124 #define LCD_4BIT 1 00125 #define LCD_8BIT 0 00126 00127 // Define COMMAND and DATA LCD Rs 00128 // --------------------------------------------------------------------------- 00129 #define COMMAND 0 00130 #define DATA 1 00131 00138 #define HOME_CLEAR_EXEC 2000 00139 00140 class LCD : public Print 00141 { 00142 public: 00143 00150 LCD ( ); 00151 00166 virtual void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS); 00167 00178 void clear(); 00179 00191 void home(); 00192 00201 void noDisplay(); 00202 00212 void display(); 00213 00220 void noBlink(); 00221 00230 void blink(); 00231 00238 void noCursor(); 00239 00248 void cursor(); 00249 00257 void scrollDisplayLeft(); 00258 00266 void scrollDisplayRight(); 00267 00279 void leftToRight(); 00280 00292 void rightToLeft(); 00293 00307 void autoscroll(); 00308 00317 void noAutoscroll(); 00318 00335 void createChar(uint8_t location, uint8_t charmap[]); 00336 00346 void setCursor(uint8_t col, uint8_t row); 00347 00348 00360 void command(uint8_t value); 00361 00362 // 00363 // virtual class methods 00364 // -------------------------------------------------------------------------- 00376 virtual void setBacklight ( uint8_t mode ) { }; 00377 00387 virtual void setBacklightPin ( uint8_t pin ) { }; 00388 00400 #if (ARDUINO < 100) 00401 virtual void write(uint8_t value); 00402 #else 00403 virtual size_t write(uint8_t value); 00404 #endif 00405 00406 00420 #if (ARDUINO < 100) 00421 virtual void send(uint8_t value, uint8_t mode) { }; 00422 #else 00423 virtual void send(uint8_t value, uint8_t mode) = 0; 00424 #endif 00425 00426 #if (ARDUINO < 100) 00427 using Print::write; 00428 #else 00429 using Print::write; 00430 #endif 00431 00432 protected: 00433 // Internal LCD variables to control the LCD shared between all derived 00434 // classes. 00435 uint8_t _displayfunction; // LCD_5x10DOTS or LCD_5x8DOTS, LCD_4BITMODE or 00436 // LCD_8BITMODE, LCD_1LINE or LCD_2LINE 00437 uint8_t _displaycontrol; // LCD base control command LCD on/off, blink, cursor 00438 // all commands are "ored" to its contents. 00439 uint8_t _displaymode; // Text entry mode to the LCD 00440 uint8_t _numlines; // Number of lines of the LCD, initialized with begin() 00441 uint8_t _cols; // Number of columns in the LCD 00442 00443 private: 00444 00445 }; 00446 00447 #endif
1.7.4