![]() | LCD Library 1.2.1 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-SA00005 //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: No00010 // Extendable: Yes00011 //00012 // @file LCD.h00013 // This file implements a basic liquid crystal library that comes as standard00014 // in the Arduino SDK.00015 // 00016 // @brief 00017 // This is a basic implementation of the LiquidCrystal library of the00018 // Arduino SDK. This library is a refactored version of the one supplied00019 // in the Arduino SDK in such a way that it simplifies its extension00020 // 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 be00022 // the base class implementing all generic methods to command an LCD based00023 // 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 extension00027 // 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 identical00030 // to the original functionality of the Arduino LiquidCrystal library.00031 //00032 // @version API 1.1.000033 //00034 //00035 // @author F. Malpartida - fmalpartida@gmail.com00036 // ---------------------------------------------------------------------------00037 #ifndef _LCD_H_00038 #define _LCD_H_00039 00040 #if (ARDUINO < 100)00041 #include <WProgram.h>00042 #else00043 #include <Arduino.h>00044 #endif00045 00046 #include <inttypes.h>00047 #include <Print.h>00048 00049 00058 #ifdef __AVR__00059 #define FAST_MODE00060 #endif00061 00071inlinestaticvoidwaitUsec ( uint16_t uSec ) 00072 { 00073 #ifndef FAST_MODE00074 delayMicroseconds ( uSec ); 00075 #endif // FAST_MODE00076 } 00077 00078 00086 // LCD Commands00087 // ---------------------------------------------------------------------------00088#define LCD_CLEARDISPLAY 0x0100089#define LCD_RETURNHOME 0x0200090#define LCD_ENTRYMODESET 0x0400091#define LCD_DISPLAYCONTROL 0x0800092#define LCD_CURSORSHIFT 0x1000093#define LCD_FUNCTIONSET 0x2000094#define LCD_SETCGRAMADDR 0x4000095#define LCD_SETDDRAMADDR 0x8000096 00097 // flags for display entry mode00098 // ---------------------------------------------------------------------------00099#define LCD_ENTRYRIGHT 0x0000100#define LCD_ENTRYLEFT 0x0200101#define LCD_ENTRYSHIFTINCREMENT 0x0100102#define LCD_ENTRYSHIFTDECREMENT 0x0000103 00104 // flags for display on/off and cursor control00105 // ---------------------------------------------------------------------------00106#define LCD_DISPLAYON 0x0400107#define LCD_DISPLAYOFF 0x0000108#define LCD_CURSORON 0x0200109#define LCD_CURSOROFF 0x0000110#define LCD_BLINKON 0x0100111#define LCD_BLINKOFF 0x0000112 00113 // flags for display/cursor shift00114 // ---------------------------------------------------------------------------00115#define LCD_DISPLAYMOVE 0x0800116#define LCD_CURSORMOVE 0x0000117#define LCD_MOVERIGHT 0x0400118#define LCD_MOVELEFT 0x0000119 00120 // flags for function set00121 // ---------------------------------------------------------------------------00122#define LCD_8BITMODE 0x1000123#define LCD_4BITMODE 0x0000124#define LCD_2LINE 0x0800125#define LCD_1LINE 0x0000126#define LCD_5x10DOTS 0x0400127#define LCD_5x8DOTS 0x0000128 00129 00130 // Define COMMAND and DATA LCD Rs (used by send method).00131 // ---------------------------------------------------------------------------00132#define COMMAND 000133#define DATA 100134#define FOUR_BITS 200135 00136 00143#define HOME_CLEAR_EXEC 200000144 00151#define BACKLIGHT_OFF 000152 00159#define BACKLIGHT_ON 25500160 00161 00167typedefenum { POSITIVE, NEGATIVE } t_backlighPol; 00168 00169class LCD : public Print 00170 { 00171 public: 00172 00179 LCD ( ); 00180 00196 virtualvoidbegin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS); 00197 00208 voidclear(); 00209 00221 voidhome(); 00222 00231 voidnoDisplay(); 00232 00242 voiddisplay(); 00243 00250 voidnoBlink(); 00251 00260 voidblink(); 00261 00268 voidnoCursor(); 00269 00278 voidcursor(); 00279 00287 voidscrollDisplayLeft(); 00288 00296 voidscrollDisplayRight(); 00297 00309 voidleftToRight(); 00310 00322 voidrightToLeft(); 00323 00330 voidmoveCursorLeft(); 00331 00332 00339 voidmoveCursorRight(); 00340 00354 voidautoscroll(); 00355 00364 voidnoAutoscroll(); 00365 00382 voidcreateChar(uint8_t location, uint8_t charmap[]); 00383 00393 voidsetCursor(uint8_t col, uint8_t row); 00394 00402 voidbacklight ( void ); 00403 00411 voidnoBacklight ( void ); 00412 00420 voidon ( void ); 00421 00429 voidoff ( void ); 00430 00431 //00432 // virtual class methods00433 // --------------------------------------------------------------------------00444virtualvoidsetBacklightPin ( uint8_t value, t_backlighPol pol ) { }; 00445 00463virtualvoidsetBacklight ( uint8_t value ) { }; 00464 00476 #if (ARDUINO < 100)00477 virtualvoidwrite(uint8_t value); 00478 #else00479 virtualsize_twrite(uint8_t value); 00480 #endif00481 00482 #if (ARDUINO < 100)00483 usingPrint::write; 00484 #else00485 usingPrint::write; 00486 #endif 00487 00488 protected: 00489 // Internal LCD variables to control the LCD shared between all derived00490 // classes.00491 uint8_t _displayfunction; // LCD_5x10DOTS or LCD_5x8DOTS, LCD_4BITMODE or 00492 // LCD_8BITMODE, LCD_1LINE or LCD_2LINE00493 uint8_t _displaycontrol; // LCD base control command LCD on/off, blink, cursor00494 // all commands are "ored" to its contents.00495 uint8_t _displaymode; // Text entry mode to the LCD00496 uint8_t _numlines; // Number of lines of the LCD, initialized with begin()00497 uint8_t _cols; // Number of columns in the LCD00498t_backlighPol_polarity; // Backlight polarity00499 00500 private: 00513 void command(uint8_t value); 00514 00528 #if (ARDUINO < 100)00529 virtualvoid send(uint8_t value, uint8_t mode) { }; 00530 #else00531 virtualvoid send(uint8_t value, uint8_t mode) = 0; 00532 #endif00533 00534 }; 00535 00536 #endif