New LiquidCrystal library  1.5.0
Generic LCD control library
/Users/fmalpartida/Documents/development/mercurial repos/SW/NewLiquidCrystal_lib/LiquidCrystal_SR.h
1 // ---------------------------------------------------------------------------
2 // Created by Francisco Malpartida on 20/08/11.
3 // Copyright (C) - 2018
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License v3.0
16 // along with this program.
17 // If not, see <https://www.gnu.org/licenses/gpl-3.0.en.html>.
18 //
19 // ---------------------------------------------------------------------------
20 //
21 // Thread Safe: No
22 // Extendable: Yes
23 //
24 // @file LiquidCrystal_SR.h
25 // Connects an LCD using 2 or 3 pins from the Arduino, via an 8-bit
26 // ShiftRegister (SR from now on).
27 //
28 // @brief
29 // This is a port of the ShiftRegLCD library from raron and ported to the
30 // LCD library.
31 //
32 // The functionality provided by this class and its base class is identical
33 // to the original functionality of the Arduino LiquidCrystal library and can
34 // be used as such.
35 //
36 // Modified to work serially with the shiftOut() function, an 8-bit
37 // unlatched, no-tristate, unidirectional SIPO (Serial-In-Parallel-Out)
38 // shift register (IE a very simple SR), and an LCD in 4-bit mode.
39 // Any such shift register should do (pref. 74LS family IC's for 2-wire).
40 // I used 74LS164, for the reason that's what I had at hand.
41 //
42 // Connection description:
43 //
44 // SR output:
45 // Bit #0 - N/C - not connected, used to hold a zero
46 // Bit #1 - N/C
47 // Bit #2 - connects to RS (Register Select) on the LCD
48 // Bits #3-6 - connects to LCD data inputs D4 - D7.
49 // Bit #7 - enables the LCD enable-puls (via the diode-resistor AND "gate")
50 //
51 // 2 or 3 Pins required from the Arduino for Data, Clock and (optional) Enable
52 // If not using Enable, the Data pin will be used for the enable signal.
53 // 2 wire mode can be indicated by:
54 // - ommitting the enable pin in constructor
55 // - defining the same pin for Enable as for Data in constructor
56 // - by using the token TWO_WIRE for the enable pin.
57 //
58 // Data and Clock outputs/pins goes to the shiftregister.
59 // LCD RW-pin hardwired to LOW (only writing to LCD).
60 // Busy Flag (BF, data bit D7) is not read.
61 //
62 // Original project homepage: http://code.google.com/p/arduinoshiftreglcd/
63 //
64 //
65 // History
66 // 2012.03.29 bperrybap - can now eliminate enable pin in constructor for two wire mode.
67 // 2011.10.29 fmalpartida - adaption of the library to the LCD class hierarchy.
68 // 2011.07.02 Fixed a minor flaw in setCursor function. No functional change,
69 // just a bit more memory efficient.
70 // Thanks to CapnBry (from google code and github) who noticed it.
71 // URL to his version of shiftregLCD:
72 // https://github.com/CapnBry/HeaterMeter/commit/c6beba1b46b092ab0b33bcbd0a30a201fd1f28c1
73 // 2009.07.30 raron - minor corrections to the comments.
74 // Fixed timing to datasheet safe. Fixed keyword highlights.
75 // 2009.07.28 Mircho / raron - a new modification to the schematics, and a
76 // more streamlined interface
77 // 2009.07.27 Thanks to an excellent suggestion from mircho at the Arduiono
78 // playgrond forum, the number of wires now required is only two!
79 // 2009.07.25 raron - Fixed comments. I really messed up the comments before
80 // posting this, so I had to fix it.
81 // Renamed a function, but no improvements or functional changes.
82 // 2009.07.23 Incorporated some proper initialization routines
83 // inspired (lets say copy-paste-tweaked) from LiquidCrystal
84 // library improvements from LadyAda.
85 // 2009.05.23 raron - first version, but based mostly (as in almost verbatim)
86 // on the "official" LiquidCrystal library.
87 //
88 //
89 //
90 // @author F. Malpartida - fmalpartida@gmail.com
91 // ---------------------------------------------------------------------------
92 #ifndef _LIQUIDCRYSTAL_SR_
93 #define _LIQUIDCRYSTAL_SR_
94 
95 #include <inttypes.h>
96 #include "LCD.h"
97 #include "FastIO.h"
98 
99 
100 // two-wire indicator constant
101 // ---------------------------------------------------------------------------
102 #define TWO_WIRE 204
103 #define SR_RS_BIT 0x04
104 #define SR_EN_BIT 0x80
105 
106 class LiquidCrystal_SR : public LCD
107 {
108 public:
120  LiquidCrystal_SR ( uint8_t srdata, uint8_t srclock, uint8_t enable=TWO_WIRE );
121 
134  virtual void send(uint8_t value, uint8_t mode);
135 
136 
146  void setBacklightPin ( uint8_t pin, t_backlightPol pol );
147 
157  void setBacklight ( uint8_t mode );
158 
159 private:
160 
166  void init ( uint8_t srdata, uint8_t srclock, uint8_t enable, uint8_t lines,
167  uint8_t font );
168 
173  void shiftIt (uint8_t val);
174 
175  uint8_t _enable_pin; // Enable Pin
176  uint8_t _two_wire; // two wire mode
177 
178  fio_register _srDataRegister; // Serial Data pin
179  fio_bit _srDataBit;
180  fio_register _srClockRegister; // Clock Pin
181  fio_bit _srClockBit;
182  fio_register _srEnableRegister; // Enable Pin
183  fio_bit _srEnableBit;
184 
185 };
186 
187 #endif
188 
Definition: LCD.h:199
LiquidCrystal_SR(uint8_t srdata, uint8_t srclock, uint8_t enable=TWO_WIRE)
Definition: LiquidCrystal_SR.cpp:110
void setBacklightPin(uint8_t pin, t_backlightPol pol)
Definition: LiquidCrystal_SR.cpp:214
void setBacklight(uint8_t mode)
Definition: LiquidCrystal_SR.cpp:219
virtual void send(uint8_t value, uint8_t mode)
Definition: LiquidCrystal_SR.cpp:184
Definition: LiquidCrystal_SR.h:106