New LiquidCrystal library: /Users/fmalpartida/Documents/development/mercurial repos/SW/NewliquidCrystal/LCD.h Source File

New LiquidCrystal library 1.3.2 Generic LCD control library

- Main Page
- Related Pages
- Classes
- Files

- File List

/Users/fmalpartida/Documents/development/mercurial repos/SW/NewliquidCrystal/LCD.h
1 // ---------------------------------------------------------------------------
2 // Created by Francisco Malpartida on 20/08/11.
3 // Copyright 2011 - Under creative commons license 3.0:
4 // Attribution-ShareAlike CC BY-SA
5 //
6 // This software is furnished "as is", without technical support, and with no
7 // warranty, express or implied, as to its usefulness for any purpose.
8 //
9 // Thread Safe: No
10 // Extendable: Yes
11 //
12 // @file LCD.h
13 // This file implements a basic liquid crystal library that comes as standard
14 // in the Arduino SDK.
15 //
16 // @brief
17 // This is a basic implementation of the LiquidCrystal library of the
18 // Arduino SDK. This library is a refactored version of the one supplied
19 // in the Arduino SDK in such a way that it simplifies its extension
20 // to support other mechanism to communicate to LCDs such as I2C, Serial, SR,
21 // The original library has been reworked in such a way that this will be
22 // the base class implementing all generic methods to command an LCD based
23 // on the Hitachi HD44780 and compatible chipsets.
24 //
25 // This base class is a pure abstract class and needs to be extended. As reference,
26 // it has been extended to drive 4 and 8 bit mode control, LCDs and I2C extension
27 // backpacks such as the I2CLCDextraIO using the PCF8574* I2C IO Expander ASIC.
28 //
29 // The functionality provided by this class and its base class is identical
30 // to the original functionality of the Arduino LiquidCrystal library.
31 //
32 // @version API 1.1.0
33 //
34 //
35 // @author F. Malpartida - fmalpartida@gmail.com
36 // ---------------------------------------------------------------------------
37 #ifndef _LCD_H_
38 #define _LCD_H_
39
40 #if (ARDUINO < 100)
41 #include <WProgram.h>
42 #else
43 #include <Arduino.h>
44 #endif
45
46 #ifdef __AVR__
47 #include <avr/pgmspace.h>
48 #endif
49
50 #include <inttypes.h>
51 #include <Print.h>
52
53
64 #ifndef _BV
65 #define _BV(bit) (1 << (bit))
66 #endif
67
76 #ifdef __AVR__
77 #define FAST_MODE
78 #endif
79
89 inline static void waitUsec ( uint16_t uSec )
90 {
91 #ifndef FAST_MODE
92 delayMicroseconds ( uSec );
93 #endif // FAST_MODE
94 }
95
96
104 // LCD Commands
105 // ---------------------------------------------------------------------------
106 #define LCD_CLEARDISPLAY 0x01
107 #define LCD_RETURNHOME 0x02
108 #define LCD_ENTRYMODESET 0x04
109 #define LCD_DISPLAYCONTROL 0x08
110 #define LCD_CURSORSHIFT 0x10
111 #define LCD_FUNCTIONSET 0x20
112 #define LCD_SETCGRAMADDR 0x40
113 #define LCD_SETDDRAMADDR 0x80
114
115 // flags for display entry mode
116 // ---------------------------------------------------------------------------
117 #define LCD_ENTRYRIGHT 0x00
118 #define LCD_ENTRYLEFT 0x02
119 #define LCD_ENTRYSHIFTINCREMENT 0x01
120 #define LCD_ENTRYSHIFTDECREMENT 0x00
121
122 // flags for display on/off and cursor control
123 // ---------------------------------------------------------------------------
124 #define LCD_DISPLAYON 0x04
125 #define LCD_DISPLAYOFF 0x00
126 #define LCD_CURSORON 0x02
127 #define LCD_CURSOROFF 0x00
128 #define LCD_BLINKON 0x01
129 #define LCD_BLINKOFF 0x00
130
131 // flags for display/cursor shift
132 // ---------------------------------------------------------------------------
133 #define LCD_DISPLAYMOVE 0x08
134 #define LCD_CURSORMOVE 0x00
135 #define LCD_MOVERIGHT 0x04
136 #define LCD_MOVELEFT 0x00
137
138 // flags for function set
139 // ---------------------------------------------------------------------------
140 #define LCD_8BITMODE 0x10
141 #define LCD_4BITMODE 0x00
142 #define LCD_2LINE 0x08
143 #define LCD_1LINE 0x00
144 #define LCD_5x10DOTS 0x04
145 #define LCD_5x8DOTS 0x00
146
147
148 // Define COMMAND and DATA LCD Rs (used by send method).
149 // ---------------------------------------------------------------------------
150 #define COMMAND 0
151 #define DATA 1
152 #define FOUR_BITS 2
153
154
161 #define HOME_CLEAR_EXEC 2000
162
169 #define BACKLIGHT_OFF 0
170
177 #define BACKLIGHT_ON 255
178
179
185 typedef enum { POSITIVE, NEGATIVE } t_backlighPol;
186
187 class LCD : public Print
188 {
189 public:
190
197 LCD ( );
198
214 virtual void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
215
226 void clear();
227
239 void home();
240
249 void noDisplay();
250
260 void display();
261
268 void noBlink();
269
278 void blink();
279
286 void noCursor();
287
296 void cursor();
297
305 void scrollDisplayLeft();
306
314 void scrollDisplayRight();
315
327 void leftToRight();
328
340 void rightToLeft();
341
348 void moveCursorLeft();
349
350
357 void moveCursorRight();
358
372 void autoscroll();
373
382 void noAutoscroll();
383
400 void createChar(uint8_t location, uint8_t charmap[]);
401
402 #ifdef __AVR__
403
423 void createChar(uint8_t location, const char *charmap);
424 #endif // __AVR__
425
435 void setCursor(uint8_t col, uint8_t row);
436
444 void backlight ( void );
445
453 void noBacklight ( void );
454
462 void on ( void );
463
471 void off ( void );
472
473 //
474 // virtual class methods
475 // --------------------------------------------------------------------------
486 virtual void setBacklightPin ( uint8_t value, t_backlighPol pol ) { };
487
505 virtual void setBacklight ( uint8_t value ) { };
506
518 #if (ARDUINO < 100)
519 virtual void write(uint8_t value);
520 #else
521 virtual size_t write(uint8_t value);
522 #endif
523
524 #if (ARDUINO < 100)
525 using Print::write;
526 #else
527 using Print::write;
528 #endif
529
530 protected:
531 // Internal LCD variables to control the LCD shared between all derived
532 // classes.
533 uint8_t _displayfunction; // LCD_5x10DOTS or LCD_5x8DOTS, LCD_4BITMODE or
534 // LCD_8BITMODE, LCD_1LINE or LCD_2LINE
535 uint8_t _displaycontrol; // LCD base control command LCD on/off, blink, cursor
536 // all commands are "ored" to its contents.
537 uint8_t _displaymode; // Text entry mode to the LCD
538 uint8_t _numlines; // Number of lines of the LCD, initialized with begin()
539 uint8_t _cols; // Number of columns in the LCD
540 t_backlighPol _polarity; // Backlight polarity
541
542 private:
555 void command(uint8_t value);
556
570 #if (ARDUINO < 100)
571 virtual void send(uint8_t value, uint8_t mode) { };
572 #else
573 virtual void send(uint8_t value, uint8_t mode) = 0;
574 #endif
575
576 };
577
578 #endif
LCD
Definition: LCD.h:187
LCD::createChar
void createChar(uint8_t location, uint8_t charmap[])
Definition: LCD.cpp:294
LCD::autoscroll
void autoscroll()
Definition: LCD.cpp:280
LCD::leftToRight
void leftToRight()
Definition: LCD.cpp:253
LCD::backlight
void backlight(void)
Definition: LCD.cpp:326
LCD::clear
void clear()
Definition: LCD.cpp:168
LCD::on
void on(void)
Definition: LCD.cpp:340
LCD::off
void off(void)
Definition: LCD.cpp:348
LCD::noBlink
void noBlink()
Definition: LCD.cpp:229
LCD::scrollDisplayRight
void scrollDisplayRight()
Definition: LCD.cpp:247
LCD::display
void display()
Definition: LCD.cpp:210
LCD::setCursor
void setCursor(uint8_t col, uint8_t row)
Definition: LCD.cpp:180
LCD::rightToLeft
void rightToLeft()
Definition: LCD.cpp:260
LCD::noAutoscroll
void noAutoscroll()
Definition: LCD.cpp:287
LCD::home
void home()
Definition: LCD.cpp:174
LCD::blink
void blink()
Definition: LCD.cpp:235
LCD::setBacklight
virtual void setBacklight(uint8_t value)
Definition: LCD.h:505
LCD::moveCursorRight
void moveCursorRight()
Definition: LCD.cpp:267
LCD::LCD
LCD()
Definition: LCD.cpp:52
LCD::scrollDisplayLeft
void scrollDisplayLeft()
Definition: LCD.cpp:242
LCD::begin
virtual void begin(uint8_t cols, uint8_t rows, uint8_t charsize=LCD_5x8DOTS)
Definition: LCD.cpp:79
LCD::noDisplay
void noDisplay()
Definition: LCD.cpp:204
LCD::noBacklight
void noBacklight(void)
Definition: LCD.cpp:333
LCD::noCursor
void noCursor()
Definition: LCD.cpp:217
LCD::setBacklightPin
virtual void setBacklightPin(uint8_t value, t_backlighPol pol)
Definition: LCD.h:486
LCD::moveCursorLeft
void moveCursorLeft()
Definition: LCD.cpp:273
LCD::write
virtual void write(uint8_t value)
Definition: LCD.cpp:362
LCD::cursor
void cursor()
Definition: LCD.cpp:222