New LiquidCrystal library  1.5.0
Generic LCD control library
/Users/fmalpartida/Documents/development/mercurial repos/SW/NewLiquidCrystal_lib/LiquidCrystal_SR2W.h
1 // ---------------------------------------------------------------------------
2 // Created/Adapted by Bill Perry 2012-03-16
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 // @file LiquidCrystal_SR2W.h
22 // Connects a hd44780 LCD using 2 pins from the Arduino, via an 8-bit
23 // ShiftRegister (SR2W from now on).
24 //
25 // @brief
26 // This is the 2 wire shift register interface class for the LCD library
27 //
28 // The functionality provided by this class and its base class is a superset of
29 // the original functionality of the Arduino LiquidCrystal library and can
30 // be used as such.
31 // See the LCD class for a full description of the API functions available.
32 //
33 // It works with a 8-bit unlatched, no-tristate, unidirectional SIPO (Serial-In-Parallel-Out)
34 // shift register (IE a very simple SR), and an hd44780 LCD in 4-bit mode.
35 // Any such shift register should do (pref. 74LS family IC's for 2-wire).
36 // 74LS164 and 74HC595 have been exstensively tested.
37 //
38 //
39 // 2 Pins required from the Arduino:
40 // - Data/Enable
41 // - Clock
42 // The Data pin is also used to control the enable signal
43 // LCD RW-pin hardwired to LOW (only writing to LCD).
44 // Busy Flag (BF, data bit D7) is not read.
45 //
46 // Original project homepage: http://code.google.com/p/arduinoshiftreglcd/
47 //
48 // Shift register bits
49 // Bit #0 - (cannot be used on 74HC595)
50 // Bit #1 - optional backlight control
51 // Bit #2 - connects to RS (Register Select) on the LCD
52 // Bit #3 - connects to LCD data inputs D4
53 // Bit #4 - connects to LCD data inputs D5
54 // Bit #5 - connects to LCD data inputs D6
55 // Bit #6 - connects to LCD data inputs D7
56 // Bit #7 - enables the LCD enable-puls (via the diode-resistor AND "gate")
57 //
58 // Wiring for a 74LS164
59 // ---------------------
60 // 1k/4.7k
61 // +--------[ Resistor ]--------+---(LCD Enable)
62 // | |
63 // | 74LS164 (VCC) |
64 // | +----u----+ | _V_ diode
65 // (data pin)---+---+--1-|A VCC|-14-+ |
66 // | | | |
67 // +--2-|B Q7|-13------+
68 // 3-|Q0 Q6|-12--(LCD D7)
69 // (BL Circuit)--------4-|Q1 Q5|-11--(LCD D6)
70 // (LCD RS)------------5-|Q2 Q4|-10--(LCD D5)
71 // (LCD D4)------------6-|Q3 /MR|--9--(VCC)
72 // +-7-|GND CP|--8--(clock pin)
73 // | +---------+
74 // | 0.1uf
75 // (gnd)-----||----(vcc)
76 //
77 // Wiring for a 74HC595
78 // --------------------
79 // NOTE: the 74HC595 is a latching shift register. In order to get it to operate
80 // in a "non latching" mode, RCLK and SCLK are tied together. The side effect of this
81 // is that the latched output is one clock behind behind the internal shift register bits.
82 // To compensate for this the wiring is offset by one bit position lower.
83 // For example, while the backlight is hooked to Q0 it is still using bit 1 of
84 // of the shift register because the outputs are 1 clock behind the real internal shift
85 // register.
86 //
87 // 74HC595 (VCC)
88 // +----u----+ | +-----------------------(BL circuit)
89 // (LCD RS)------------1-|Q1 VCC|-16-+ | +--------------------(data pin)
90 // (LCD D4)------------2-|Q2 Q0|-15----+ | 1k/4.7k
91 // (LCD D5)------------3-|Q3 SER|-14-------+---[ Resistor ]--+--(LCD Enable)
92 // (LCD D6)------------4-|Q4 /OE|-13--(gnd) |
93 // (LCD D7)------------5-|Q5 RCLK|-12-------+ |
94 // | | | |
95 // +------6-|Q6 SCLK|-11-------+--(clock pin) |
96 // | 7-|Q7 /MR|-10--(VCC) |
97 // | +-8-|GND Q6'|--9 |
98 // | | +---------+ diode _V_
99 // | | 0.1uf |
100 // | (gnd)-----||----(vcc) |
101 // +-----------------------------------------------+
102 //
103 //
104 // Backlight Control circuit
105 // -------------------------
106 // Because the shift resiter is not latching the outputs, the backlight circuitry
107 // will "see" the output bits as they are shifted into the shift register which
108 // can cause the backlight to flicker rather than remain constantly on/off.
109 // The circuit below slows down the transitions to the transistor to remove
110 // the visible flicker. When the BL input is HIGH the LCD backlight will turn on.
111 //
112 // (value depends on LCD, 100ohm is usually safe)
113 // (LCD BL anode)---[ resistor ]---(vcc)
114 //
115 // (LCD BL cathode)-------------------------------+
116 // |
117 // D
118 // |
119 // (BL input)----[ 4.7k Resistor ]----+-------G-|-< (2N7000 FET)
120 // | |
121 // (0.1uf) = S
122 // | |
123 // (gnd) (gnd)
124 //
125 //
126 //
127 //
128 // History
129 // 2012.03.16 bperrybap - creation/adaption from SR header to create SR2W header.
130 // Fixed typo in SR2W mask define names
131 // @author B. Perry - bperrybap@opensource.billsworld.billandterrie.com
132 // --------------------------------------------------------------------------------
133 #ifndef _LIQUIDCRYSTAL_SR2W_
134 #define _LIQUIDCRYSTAL_SR2W_
135 
136 #include <inttypes.h>
137 #include "LCD.h"
138 #include "FastIO.h"
139 
140 
141 // two-wire SR output bit constants
142 // ---------------------------------------------------------------------------
143 
144 #define SR2W_BL_MASK 0x02
145 #define SR2W_RS_MASK 0x04
146 #define SR2W_DATA_MASK 0x78 // data bits are hard coded to be SR bits 6,5,4,3
147 #define SR2W_EN_MASK 0x80 // cannot ever be changed
148 
149 class LiquidCrystal_SR2W : public LCD
150 {
151 public:
163  LiquidCrystal_SR2W (uint8_t srdata, uint8_t srclock, t_backlightPol blpol = POSITIVE);
164 
177  virtual void send(uint8_t value, uint8_t mode);
178 
179 
189  void setBacklight ( uint8_t mode );
190 
191 private:
192 
198  void init ( uint8_t srdata, uint8_t srclock, t_backlightPol blpol, uint8_t lines, uint8_t font );
199 
204  void loadSR (uint8_t val);
205 
206  fio_register _srDataRegister; // Serial Data pin
207  fio_bit _srDataMask;
208  fio_register _srClockRegister; // Clock Pin
209  fio_bit _srClockMask;
210 
211  uint8_t _blPolarity;
212  uint8_t _blMask;
213 };
214 #endif
void setBacklight(uint8_t mode)
Definition: LiquidCrystal_SR2W.cpp:129
Definition: LiquidCrystal_SR2W.h:149
LiquidCrystal_SR2W(uint8_t srdata, uint8_t srclock, t_backlightPol blpol=POSITIVE)
Definition: LiquidCrystal_SR2W.cpp:49
Definition: LCD.h:199
virtual void send(uint8_t value, uint8_t mode)
Definition: LiquidCrystal_SR2W.cpp:102